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

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

Issue 448853002: Move StringToLowerASCII to base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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/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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 base::TrimWhitespaceASCII(*code, base::TRIM_ALL, code); 284 base::TrimWhitespaceASCII(*code, base::TRIM_ALL, code);
285 285
286 // An underscore instead of a dash is a frequent mistake. 286 // An underscore instead of a dash is a frequent mistake.
287 size_t underscore_index = code->find('_'); 287 size_t underscore_index = code->find('_');
288 if (underscore_index != std::string::npos) 288 if (underscore_index != std::string::npos)
289 (*code)[underscore_index] = '-'; 289 (*code)[underscore_index] = '-';
290 290
291 // Change everything up to a dash to lower-case and everything after to upper. 291 // Change everything up to a dash to lower-case and everything after to upper.
292 size_t dash_index = code->find('-'); 292 size_t dash_index = code->find('-');
293 if (dash_index != std::string::npos) { 293 if (dash_index != std::string::npos) {
294 *code = StringToLowerASCII(code->substr(0, dash_index)) + 294 *code = base::StringToLowerASCII(code->substr(0, dash_index)) +
295 StringToUpperASCII(code->substr(dash_index)); 295 StringToUpperASCII(code->substr(dash_index));
296 } else { 296 } else {
297 *code = StringToLowerASCII(*code); 297 *code = base::StringToLowerASCII(*code);
298 } 298 }
299 } 299 }
300 300
301 bool IsValidLanguageCode(const std::string& code) { 301 bool IsValidLanguageCode(const std::string& code) {
302 // Roughly check if the language code follows /[a-zA-Z]{2,3}(-[a-zA-Z]{2})?/. 302 // Roughly check if the language code follows /[a-zA-Z]{2,3}(-[a-zA-Z]{2})?/.
303 // TODO(hajimehoshi): How about es-419, which is used as an Accept language? 303 // TODO(hajimehoshi): How about es-419, which is used as an Accept language?
304 std::vector<std::string> chunks; 304 std::vector<std::string> chunks;
305 base::SplitString(code, '-', &chunks); 305 base::SplitString(code, '-', &chunks);
306 306
307 if (chunks.size() < 1 || 2 < chunks.size()) 307 if (chunks.size() < 1 || 2 < chunks.size())
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // distinguish from English, and the language is one of well-known languages 380 // distinguish from English, and the language is one of well-known languages
381 // which often provide "en-*" meta information mistakenly. 381 // which often provide "en-*" meta information mistakenly.
382 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) { 382 for (size_t i = 0; i < arraysize(kWellKnownCodesOnWrongConfiguration); ++i) {
383 if (cld_language == kWellKnownCodesOnWrongConfiguration[i]) 383 if (cld_language == kWellKnownCodesOnWrongConfiguration[i])
384 return true; 384 return true;
385 } 385 }
386 return false; 386 return false;
387 } 387 }
388 388
389 } // namespace translate 389 } // namespace translate
OLDNEW
« no previous file with comments | « components/storage_monitor/portable_device_watcher_win.cc ('k') | components/url_matcher/regex_set_matcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698