summaryrefslogtreecommitdiffstats
path: root/app/l10n_util.cc
diff options
context:
space:
mode:
authordmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-14 14:47:53 +0000
committerdmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-14 14:47:53 +0000
commit75106d77a5af0db5ffaf0cb9f59723449420a1e7 (patch)
treeb80d97e7b950428c1b545d218a6f253863602185 /app/l10n_util.cc
parent650c908b1828a8ad8ff1c925106f18f65922fb06 (diff)
downloadchromium_src-75106d77a5af0db5ffaf0cb9f59723449420a1e7.zip
chromium_src-75106d77a5af0db5ffaf0cb9f59723449420a1e7.tar.gz
chromium_src-75106d77a5af0db5ffaf0cb9f59723449420a1e7.tar.bz2
Minor changes to simplify IsValidLocaleSyntax logic.
BUG=none TEST=none Review URL: http://codereview.chromium.org/5816001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69130 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/l10n_util.cc')
-rw-r--r--app/l10n_util.cc33
1 files changed, 17 insertions, 16 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc
index 4d6b8b9..28b16b2 100644
--- a/app/l10n_util.cc
+++ b/app/l10n_util.cc
@@ -507,10 +507,11 @@ bool IsValidLocaleSyntax(const std::string& locale) {
// Strip off the part after an '@' sign, which might contain keywords,
// as in en_IE@currency=IEP or fr@collation=phonebook;calendar=islamic-civil.
// We don't validate that part much, just check that there's at least one
- // equals sign in a plausible place.
- std::string prefix = locale;
- if (locale.find("@") != std::string::npos) {
- size_t split_point = locale.find("@");
+ // equals sign in a plausible place. Normalize the prefix so that hyphens
+ // are changed to underscores.
+ std::string prefix = NormalizeLocale(locale);
+ size_t split_point = locale.find("@");
+ if (split_point != std::string::npos) {
std::string keywords = locale.substr(split_point + 1);
prefix = locale.substr(0, split_point);
@@ -520,11 +521,11 @@ bool IsValidLocaleSyntax(const std::string& locale) {
return false;
}
- // Check that all characters before the at-sign are alphanumeric, hyphen,
- // or underscore.
+ // Check that all characters before the at-sign are alphanumeric or
+ // underscore.
for (size_t i = 0; i < prefix.size(); i++) {
char ch = prefix[i];
- if (!IsAsciiAlpha(ch) && !IsAsciiDigit(ch) && ch != '-' && ch != '_')
+ if (!IsAsciiAlpha(ch) && !IsAsciiDigit(ch) && ch != '_')
return false;
}
@@ -532,7 +533,7 @@ bool IsValidLocaleSyntax(const std::string& locale) {
// is 1 - 3 alphabetical characters (a language tag).
for (size_t i = 0; i < prefix.size(); i++) {
char ch = prefix[i];
- if (ch == '-' || ch == '_') {
+ if (ch == '_') {
if (i < 1 || i > 3)
return false;
break;
@@ -547,16 +548,16 @@ bool IsValidLocaleSyntax(const std::string& locale) {
int token_len = 0;
int token_index = 0;
for (size_t i = 0; i < prefix.size(); i++) {
- char ch = prefix[i];
- if (ch == '-' || ch == '_') {
- if (token_index > 0 && (token_len < 1 || token_len > 8)) {
- return false;
- }
- token_index++;
- token_len = 0;
- } else {
+ if (prefix[i] != '_') {
token_len++;
+ continue;
+ }
+
+ if (token_index > 0 && (token_len < 1 || token_len > 8)) {
+ return false;
}
+ token_index++;
+ token_len = 0;
}
if (token_index == 0 && (token_len < 1 || token_len > 3)) {
return false;