OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/translate/core/language_detection/language_detection_util.h
" | 5 #include "components/translate/core/language_detection/language_detection_util.h
" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 if (chunks.size() < 1 || 2 < chunks.size()) | 317 if (chunks.size() < 1 || 2 < chunks.size()) |
318 return false; | 318 return false; |
319 | 319 |
320 const std::string& main_code = chunks[0]; | 320 const std::string& main_code = chunks[0]; |
321 | 321 |
322 if (main_code.size() < 1 || 3 < main_code.size()) | 322 if (main_code.size() < 1 || 3 < main_code.size()) |
323 return false; | 323 return false; |
324 | 324 |
325 for (std::string::const_iterator it = main_code.begin(); | 325 for (std::string::const_iterator it = main_code.begin(); |
326 it != main_code.end(); ++it) { | 326 it != main_code.end(); ++it) { |
327 if (!IsAsciiAlpha(*it)) | 327 if (!base::IsAsciiAlpha(*it)) |
328 return false; | 328 return false; |
329 } | 329 } |
330 | 330 |
331 if (chunks.size() == 1) | 331 if (chunks.size() == 1) |
332 return true; | 332 return true; |
333 | 333 |
334 const std::string& sub_code = chunks[1]; | 334 const std::string& sub_code = chunks[1]; |
335 | 335 |
336 if (sub_code.size() != 2) | 336 if (sub_code.size() != 2) |
337 return false; | 337 return false; |
338 | 338 |
339 for (std::string::const_iterator it = sub_code.begin(); | 339 for (std::string::const_iterator it = sub_code.begin(); |
340 it != sub_code.end(); ++it) { | 340 it != sub_code.end(); ++it) { |
341 if (!IsAsciiAlpha(*it)) | 341 if (!base::IsAsciiAlpha(*it)) |
342 return false; | 342 return false; |
343 } | 343 } |
344 | 344 |
345 return true; | 345 return true; |
346 } | 346 } |
347 | 347 |
348 bool IsSameOrSimilarLanguages(const std::string& page_language, | 348 bool IsSameOrSimilarLanguages(const std::string& page_language, |
349 const std::string& cld_language) { | 349 const std::string& cld_language) { |
350 std::vector<std::string> chunks; | 350 std::vector<std::string> chunks; |
351 | 351 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 // distinguish from English, and the language is one of well-known languages | 390 // distinguish from English, and the language is one of well-known languages |
391 // which often provide "en-*" meta information mistakenly. | 391 // which often provide "en-*" meta information mistakenly. |
392 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { | 392 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { |
393 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) | 393 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) |
394 return true; | 394 return true; |
395 } | 395 } |
396 return false; | 396 return false; |
397 } | 397 } |
398 | 398 |
399 } // namespace translate | 399 } // namespace translate |
OLD | NEW |