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

Unified Diff: app/l10n_util.cc

Issue 5816001: Minor changes to simplify IsValidLocaleSyntax logic. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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: app/l10n_util.cc
===================================================================
--- app/l10n_util.cc (revision 69048)
+++ app/l10n_util.cc (working copy)
@@ -507,10 +507,11 @@
// 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 @@
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 @@
// 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 @@
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;
« 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