| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 const bool is_plain_text = true; | 79 const bool is_plain_text = true; |
| 80 | 80 |
| 81 // Language or CLD2::Language | 81 // Language or CLD2::Language |
| 82 int cld_language = 0; | 82 int cld_language = 0; |
| 83 bool is_valid_language = false; | 83 bool is_valid_language = false; |
| 84 | 84 |
| 85 const std::string utf8_text(base::UTF16ToUTF8(text)); | 85 const std::string utf8_text(base::UTF16ToUTF8(text)); |
| 86 const int num_utf8_bytes = static_cast<int>(utf8_text.size()); | 86 const int num_utf8_bytes = static_cast<int>(utf8_text.size()); |
| 87 const char* raw_utf8_bytes = utf8_text.c_str(); | 87 const char* raw_utf8_bytes = utf8_text.c_str(); |
| 88 | 88 |
| 89 CLD2::Language language3[3]; | 89 CLD2::Language language3[3] = { |
| 90 int percent3[3]; | 90 CLD2::UNKNOWN_LANGUAGE, CLD2::UNKNOWN_LANGUAGE, CLD2::UNKNOWN_LANGUAGE}; |
| 91 int percent3[3] = {0, 0, 0}; |
| 91 int flags = 0; // No flags, see compact_lang_det.h for details. | 92 int flags = 0; // No flags, see compact_lang_det.h for details. |
| 92 int text_bytes; // Amount of non-tag/letters-only text (assumed 0). | 93 int text_bytes; // Amount of non-tag/letters-only text (assumed 0). |
| 93 double normalized_score3[3]; | 94 double normalized_score3[3] = {0.0, 0.0, 0.0}; |
| 94 | 95 |
| 95 const char* tld_hint = ""; | 96 const char* tld_hint = ""; |
| 96 int encoding_hint = CLD2::UNKNOWN_ENCODING; | 97 int encoding_hint = CLD2::UNKNOWN_ENCODING; |
| 97 CLD2::Language language_hint = CLD2::GetLanguageFromName(html_lang.c_str()); | 98 CLD2::Language language_hint = CLD2::GetLanguageFromName(html_lang.c_str()); |
| 98 CLD2::CLDHints cldhints = {code.c_str(), tld_hint, encoding_hint, | 99 CLD2::CLDHints cldhints = {code.c_str(), tld_hint, encoding_hint, |
| 99 language_hint}; | 100 language_hint}; |
| 100 | 101 |
| 101 CLD2::ExtDetectLanguageSummaryCheckUTF8( | 102 CLD2::ExtDetectLanguageSummaryCheckUTF8( |
| 102 raw_utf8_bytes, num_utf8_bytes, is_plain_text, &cldhints, flags, | 103 raw_utf8_bytes, num_utf8_bytes, is_plain_text, &cldhints, flags, |
| 103 language3, percent3, normalized_score3, | 104 language3, percent3, normalized_score3, |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // distinguish from English, and the language is one of well-known languages | 367 // distinguish from English, and the language is one of well-known languages |
| 367 // which often provide "en-*" meta information mistakenly. | 368 // which often provide "en-*" meta information mistakenly. |
| 368 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { | 369 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { |
| 369 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) | 370 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) |
| 370 return true; | 371 return true; |
| 371 } | 372 } |
| 372 return false; | 373 return false; |
| 373 } | 374 } |
| 374 | 375 |
| 375 } // namespace translate | 376 } // namespace translate |
| OLD | NEW |