Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: components/translate/core/language_detection/language_detection_util.cc

Issue 1280473002: Update ToLower/UpperASCII API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 base::TrimWhitespaceASCII(*code, base::TRIM_ALL, code); 263 base::TrimWhitespaceASCII(*code, base::TRIM_ALL, code);
264 264
265 // An underscore instead of a dash is a frequent mistake. 265 // An underscore instead of a dash is a frequent mistake.
266 size_t underscore_index = code->find('_'); 266 size_t underscore_index = code->find('_');
267 if (underscore_index != std::string::npos) 267 if (underscore_index != std::string::npos)
268 (*code)[underscore_index] = '-'; 268 (*code)[underscore_index] = '-';
269 269
270 // Change everything up to a dash to lower-case and everything after to upper. 270 // Change everything up to a dash to lower-case and everything after to upper.
271 size_t dash_index = code->find('-'); 271 size_t dash_index = code->find('-');
272 if (dash_index != std::string::npos) { 272 if (dash_index != std::string::npos) {
273 *code = base::StringToLowerASCII(code->substr(0, dash_index)) + 273 *code = base::ToLowerASCII(code->substr(0, dash_index)) +
274 base::StringToUpperASCII(code->substr(dash_index)); 274 base::ToUpperASCII(code->substr(dash_index));
275 } else { 275 } else {
276 *code = base::StringToLowerASCII(*code); 276 *code = base::ToLowerASCII(*code);
277 } 277 }
278 } 278 }
279 279
280 bool IsValidLanguageCode(const std::string& code) { 280 bool IsValidLanguageCode(const std::string& code) {
281 // Roughly check if the language code follows /[a-zA-Z]{2,3}(-[a-zA-Z]{2})?/. 281 // Roughly check if the language code follows /[a-zA-Z]{2,3}(-[a-zA-Z]{2})?/.
282 // TODO(hajimehoshi): How about es-419, which is used as an Accept language? 282 // TODO(hajimehoshi): How about es-419, which is used as an Accept language?
283 std::vector<base::StringPiece> chunks = base::SplitStringPiece( 283 std::vector<base::StringPiece> chunks = base::SplitStringPiece(
284 code, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 284 code, "-", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
285 285
286 if (chunks.size() < 1 || 2 < chunks.size()) 286 if (chunks.size() < 1 || 2 < chunks.size())
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 // distinguish from English, and the language is one of well-known languages 358 // distinguish from English, and the language is one of well-known languages
359 // which often provide "en-*" meta information mistakenly. 359 // which often provide "en-*" meta information mistakenly.
360 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { 360 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) {
361 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) 361 if (cld_language == kWellKnownCodesOnWrongConfiguration[i])
362 return true; 362 return true;
363 } 363 }
364 return false; 364 return false;
365 } 365 }
366 366
367 } // namespace translate 367 } // namespace translate
OLDNEW
« no previous file with comments | « components/test_runner/event_sender.cc ('k') | content/browser/renderer_host/input/web_input_event_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698