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

Unified Diff: chrome/browser/search_engines/template_url_prepopulate_data.cc

Issue 203079: Implement GetCurrentCountryID() for Linux.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/search_engines/template_url_prepopulate_data.cc
===================================================================
--- chrome/browser/search_engines/template_url_prepopulate_data.cc (revision 26311)
+++ chrome/browser/search_engines/template_url_prepopulate_data.cc (working copy)
@@ -4,6 +4,10 @@
#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
+#if defined(OS_LINUX)
+#include <locale.h>
+#endif
+
#include "base/command_line.h"
#include "base/string_util.h"
#include "chrome/browser/search_engines/template_url.h"
@@ -2785,7 +2789,30 @@
#elif defined(OS_LINUX)
int GetCurrentCountryID() {
- NOTIMPLEMENTED();
+ const char* locale = setlocale(LC_MESSAGES, NULL);
+
+ if (!locale)
+ return kCountryIDUnknown;
+
+ // The format of a locale name is:
+ // language[_territory][.codeset][@modifier], where territory is an ISO 3166
+ // country code, which is what we want.
+ std::string locale_str(locale);
+ std::string::size_type begin = locale_str.find('_');
Peter Kasting 2009/09/16 23:35:10 Nit: After some discussion a while back, we agreed
+ if (begin == std::string::npos || locale_str.size() - begin < 3)
+ return kCountryIDUnknown;
+
+ begin++;
Peter Kasting 2009/09/16 23:35:10 Nit: I'd prefer preincrement to post except where
+ std::string::size_type end = locale_str.find_first_of(".@", begin);
+ if (end == std::string::npos)
+ end = locale_str.size();
+
+ // The territory part must contain exactly two characters.
+ if (end - begin == 2) {
+ return CountryCharsToCountryIDWithUpdate(
+ ToUpperASCII(locale_str[begin]), ToUpperASCII(locale_str[begin + 1]));
+ }
+
return kCountryIDUnknown;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698