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

Unified Diff: components/autofill/browser/form_group.cc

Issue 14148004: [Autofill] Move IsValidState() into validation.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | « components/autofill/browser/form_group.h ('k') | components/autofill/browser/personal_data_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/browser/form_group.cc
diff --git a/components/autofill/browser/form_group.cc b/components/autofill/browser/form_group.cc
index 82031f0afd3f19e931de5dd7b65d9b6b50902ef9..e81fd8424c90415139a2bbac1b2c59ef7abdeef5 100644
--- a/components/autofill/browser/form_group.cc
+++ b/components/autofill/browser/form_group.cc
@@ -12,6 +12,8 @@
#include "base/strings/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "components/autofill/browser/autofill_country.h"
+#include "components/autofill/browser/state_names.h"
+#include "components/autofill/browser/validation.h"
#include "components/autofill/common/form_field_data.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -19,91 +21,6 @@
namespace autofill {
namespace {
-// TODO(jhawkins): Add more states/provinces. See http://crbug.com/45039.
-
-class State {
- public:
- const char* name;
- const char* abbreviation;
-
- static const State all_states[];
-
- static base::string16 Abbreviation(const base::string16& name);
- static base::string16 FullName(const base::string16& abbreviation);
-};
-
-const State State::all_states[] = {
- { "alabama", "al" },
- { "alaska", "ak" },
- { "arizona", "az" },
- { "arkansas", "ar" },
- { "california", "ca" },
- { "colorado", "co" },
- { "connecticut", "ct" },
- { "delaware", "de" },
- { "district of columbia", "dc" },
- { "florida", "fl" },
- { "georgia", "ga" },
- { "hawaii", "hi" },
- { "idaho", "id" },
- { "illinois", "il" },
- { "indiana", "in" },
- { "iowa", "ia" },
- { "kansas", "ks" },
- { "kentucky", "ky" },
- { "louisiana", "la" },
- { "maine", "me" },
- { "maryland", "md" },
- { "massachusetts", "ma" },
- { "michigan", "mi" },
- { "minnesota", "mv" },
- { "mississippi", "ms" },
- { "missouri", "mo" },
- { "montana", "mt" },
- { "nebraska", "ne" },
- { "nevada", "nv" },
- { "new hampshire", "nh" },
- { "new jersey", "nj" },
- { "new mexico", "nm" },
- { "new york", "ny" },
- { "north carolina", "nc" },
- { "north dakota", "nd" },
- { "ohio", "oh" },
- { "oklahoma", "ok" },
- { "oregon", "or" },
- { "pennsylvania", "pa" },
- { "puerto rico", "pr" },
- { "rhode island", "ri" },
- { "south carolina", "sc" },
- { "south dakota", "sd" },
- { "tennessee", "tn" },
- { "texas", "tx" },
- { "utah", "ut" },
- { "vermont", "vt" },
- { "virginia", "va" },
- { "washington", "wa" },
- { "west virginia", "wv" },
- { "wisconsin", "wi" },
- { "wyoming", "wy" },
- { NULL, NULL }
-};
-
-base::string16 State::Abbreviation(const base::string16& name) {
- for (const State* state = all_states; state->name; ++state) {
- if (LowerCaseEqualsASCII(name, state->name))
- return ASCIIToUTF16(state->abbreviation);
- }
- return base::string16();
-}
-
-base::string16 State::FullName(const base::string16& abbreviation) {
- for (const State* state = all_states; state->name; ++state) {
- if (LowerCaseEqualsASCII(abbreviation, state->abbreviation))
- return ASCIIToUTF16(state->name);
- }
- return base::string16();
-}
-
const char* const kMonthsAbbreviated[] = {
NULL, // Padding so index 1 = month 1 = January.
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
@@ -141,23 +58,21 @@ bool SetSelectControlValue(const base::string16& value,
bool FillStateSelectControl(const base::string16& value,
FormFieldData* field) {
- base::string16 abbrev, full;
Evan Stade 2013/04/15 18:55:34 is there a rule against this type of declaration?
Ilya Sherman 2013/04/16 01:12:25 Not really, I just disprefer it. Anyway, it's no
+ base::string16 abbreviation;
+ base::string16 full;
if (value.size() < 4U) {
Evan Stade 2013/04/15 18:55:34 instead of this magic cutoff, why not just try Get
Ilya Sherman 2013/04/16 01:12:25 Done.
- abbrev = value;
- full = State::FullName(value);
+ abbreviation = value;
+ full = state_names::GetNameForAbbreviation(value);
} else {
- abbrev = State::Abbreviation(value);
+ abbreviation = state_names::GetAbbreviationForName(value);
full = value;
}
// Try the abbreviation name first.
- if (!abbrev.empty() && SetSelectControlValue(abbrev, field))
+ if (!abbreviation.empty() && SetSelectControlValue(abbreviation, field))
return true;
- if (full.empty())
- return false;
-
- return SetSelectControlValue(full, field);
+ return !full.empty() && SetSelectControlValue(full, field);
}
bool FillExpirationMonthSelectControl(const base::string16& value,
@@ -319,9 +234,4 @@ bool FormGroup::FillCountrySelectControl(const std::string& app_locale,
return false;
}
-// static
-bool FormGroup::IsValidState(const base::string16& value) {
- return !State::Abbreviation(value).empty() || !State::FullName(value).empty();
-}
-
} // namespace autofill
« no previous file with comments | « components/autofill/browser/form_group.h ('k') | components/autofill/browser/personal_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698