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

Side by Side Diff: components/language_usage_metrics/language_usage_metrics.cc

Issue 1279123004: Replace ToLower calls to the new format (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
« no previous file with comments | « components/history/core/browser/url_utils.cc ('k') | components/mime_util/mime_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/language_usage_metrics/language_usage_metrics.h" 5 #include "components/language_usage_metrics/language_usage_metrics.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/metrics/sparse_histogram.h" 9 #include "base/metrics/sparse_histogram.h"
10 #include "base/strings/string_tokenizer.h" 10 #include "base/strings/string_tokenizer.h"
(...skipping 24 matching lines...) Expand all
35 UMA_HISTOGRAM_SPARSE_SLOWLY("LanguageUsage.ApplicationLanguage", 35 UMA_HISTOGRAM_SPARSE_SLOWLY("LanguageUsage.ApplicationLanguage",
36 language_code); 36 language_code);
37 } 37 }
38 38
39 // static 39 // static
40 int LanguageUsageMetrics::ToLanguageCode(const std::string& locale) { 40 int LanguageUsageMetrics::ToLanguageCode(const std::string& locale) {
41 base::StringTokenizer parts(locale, "-_"); 41 base::StringTokenizer parts(locale, "-_");
42 if (!parts.GetNext()) 42 if (!parts.GetNext())
43 return 0; 43 return 0;
44 44
45 std::string language_part = parts.token(); 45 std::string language_part = base::ToLowerASCII(parts.token());
46 base::StringToLowerASCII(&language_part);
47 46
48 int language_code = 0; 47 int language_code = 0;
49 for (std::string::iterator it = language_part.begin(); 48 for (std::string::iterator it = language_part.begin();
50 it != language_part.end(); ++it) { 49 it != language_part.end(); ++it) {
51 char ch = *it; 50 char ch = *it;
52 if (ch < 'a' || 'z' < ch) 51 if (ch < 'a' || 'z' < ch)
53 return 0; 52 return 0;
54 53
55 language_code <<= 8; 54 language_code <<= 8;
56 language_code += ch; 55 language_code += ch;
57 } 56 }
58 57
59 return language_code; 58 return language_code;
60 } 59 }
61 60
62 // static 61 // static
63 void LanguageUsageMetrics::ParseAcceptLanguages( 62 void LanguageUsageMetrics::ParseAcceptLanguages(
64 const std::string& accept_languages, 63 const std::string& accept_languages,
65 std::set<int>* languages) { 64 std::set<int>* languages) {
66 languages->clear(); 65 languages->clear();
67 base::StringTokenizer locales(accept_languages, ","); 66 base::StringTokenizer locales(accept_languages, ",");
68 while (locales.GetNext()) { 67 while (locales.GetNext()) {
69 const int language_code = ToLanguageCode(locales.token()); 68 const int language_code = ToLanguageCode(locales.token());
70 if (language_code != 0) 69 if (language_code != 0)
71 languages->insert(language_code); 70 languages->insert(language_code);
72 } 71 }
73 } 72 }
74 73
75 } // namespace language_usage_metrics 74 } // namespace language_usage_metrics
OLDNEW
« no previous file with comments | « components/history/core/browser/url_utils.cc ('k') | components/mime_util/mime_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698