OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/language_detection/language_detection_util.h" | 5 #include "components/translate/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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 271 } |
272 | 272 |
273 void CorrectLanguageCodeTypo(std::string* code) { | 273 void CorrectLanguageCodeTypo(std::string* code) { |
274 DCHECK(code); | 274 DCHECK(code); |
275 | 275 |
276 size_t coma_index = code->find(','); | 276 size_t coma_index = code->find(','); |
277 if (coma_index != std::string::npos) { | 277 if (coma_index != std::string::npos) { |
278 // There are more than 1 language specified, just keep the first one. | 278 // There are more than 1 language specified, just keep the first one. |
279 *code = code->substr(0, coma_index); | 279 *code = code->substr(0, coma_index); |
280 } | 280 } |
281 TrimWhitespaceASCII(*code, TRIM_ALL, code); | 281 base::TrimWhitespaceASCII(*code, base::TRIM_ALL, code); |
282 | 282 |
283 // An underscore instead of a dash is a frequent mistake. | 283 // An underscore instead of a dash is a frequent mistake. |
284 size_t underscore_index = code->find('_'); | 284 size_t underscore_index = code->find('_'); |
285 if (underscore_index != std::string::npos) | 285 if (underscore_index != std::string::npos) |
286 (*code)[underscore_index] = '-'; | 286 (*code)[underscore_index] = '-'; |
287 | 287 |
288 // Change everything up to a dash to lower-case and everything after to upper. | 288 // Change everything up to a dash to lower-case and everything after to upper. |
289 size_t dash_index = code->find('-'); | 289 size_t dash_index = code->find('-'); |
290 if (dash_index != std::string::npos) { | 290 if (dash_index != std::string::npos) { |
291 *code = StringToLowerASCII(code->substr(0, dash_index)) + | 291 *code = StringToLowerASCII(code->substr(0, dash_index)) + |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // distinguish from English, and the language is one of well-known languages | 377 // distinguish from English, and the language is one of well-known languages |
378 // which often provide "en-*" meta information mistakenly. | 378 // which often provide "en-*" meta information mistakenly. |
379 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { | 379 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { |
380 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) | 380 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) |
381 return true; | 381 return true; |
382 } | 382 } |
383 return false; | 383 return false; |
384 } | 384 } |
385 | 385 |
386 } // namespace translate | 386 } // namespace translate |
OLD | NEW |