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

Side by Side Diff: components/translate/core/browser/translate_accept_languages.cc

Issue 1234973004: Update SplitString calls in components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 5 years, 5 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/browser/translate_accept_languages.h" 5 #include "components/translate/core/browser/translate_accept_languages.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 bool TranslateAcceptLanguages::IsAcceptLanguage(const std::string& language) { 55 bool TranslateAcceptLanguages::IsAcceptLanguage(const std::string& language) {
56 std::string accept_language = language; 56 std::string accept_language = language;
57 translate::ToChromeLanguageSynonym(&accept_language); 57 translate::ToChromeLanguageSynonym(&accept_language);
58 return accept_languages_.find(accept_language) != accept_languages_.end(); 58 return accept_languages_.find(accept_language) != accept_languages_.end();
59 } 59 }
60 60
61 void TranslateAcceptLanguages::InitAcceptLanguages(PrefService* prefs) { 61 void TranslateAcceptLanguages::InitAcceptLanguages(PrefService* prefs) {
62 DCHECK(prefs); 62 DCHECK(prefs);
63 // Build the languages. 63 // Build the languages.
64 accept_languages_.clear(); 64 accept_languages_.clear();
65 std::string accept_langs_str = prefs->GetString( 65 for (const base::StringPiece& lang : base::SplitStringPiece(
66 accept_languages_pref_.c_str()); 66 prefs->GetString(accept_languages_pref_), ",",
67 std::vector<std::string> accept_langs_list; 67 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
68 base::SplitString(accept_langs_str, ',', &accept_langs_list);
69 std::vector<std::string>::const_iterator iter;
70
71 for (iter = accept_langs_list.begin();
72 iter != accept_langs_list.end(); ++iter) {
73 // Get rid of the locale extension if any (ex: en-US -> en), but for Chinese 68 // Get rid of the locale extension if any (ex: en-US -> en), but for Chinese
74 // for which the CLD reports zh-CN and zh-TW. 69 // for which the CLD reports zh-CN and zh-TW.
75 std::string accept_lang(*iter); 70 size_t index = lang.find('-');
76 size_t index = iter->find("-"); 71 if (index != base::StringPiece::npos && lang != "zh-CN" && lang != "zh-TW")
77 if (index != std::string::npos && *iter != "zh-CN" && *iter != "zh-TW") 72 accept_languages_.insert(lang.substr(0, index).as_string());
78 accept_lang = iter->substr(0, index); 73 else
79 74 accept_languages_.insert(lang.as_string());
80 accept_languages_.insert(accept_lang);
81 } 75 }
82 } 76 }
83 77
84 } // namespace translate 78 } // namespace translate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698