[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / components / autofill / core / browser / state_names.cc
blobde659243be76f8e962997a34ffb649cf4621d2d0
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/autofill/core/browser/state_names.h"
7 #include "base/basictypes.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h"
11 namespace autofill {
12 namespace state_names {
14 namespace {
16 // TODO(jhawkins): Add more states/provinces. See http://crbug.com/45039.
18 struct StateData {
19 const char* const name;
20 const char abbreviation[3];
23 StateData kStateData[] = {
24 { "alabama", "al" },
25 { "alaska", "ak" },
26 { "arizona", "az" },
27 { "arkansas", "ar" },
28 { "california", "ca" },
29 { "colorado", "co" },
30 { "connecticut", "ct" },
31 { "delaware", "de" },
32 { "district of columbia", "dc" },
33 { "florida", "fl" },
34 { "georgia", "ga" },
35 { "hawaii", "hi" },
36 { "idaho", "id" },
37 { "illinois", "il" },
38 { "indiana", "in" },
39 { "iowa", "ia" },
40 { "kansas", "ks" },
41 { "kentucky", "ky" },
42 { "louisiana", "la" },
43 { "maine", "me" },
44 { "maryland", "md" },
45 { "massachusetts", "ma" },
46 { "michigan", "mi" },
47 { "minnesota", "mn" },
48 { "mississippi", "ms" },
49 { "missouri", "mo" },
50 { "montana", "mt" },
51 { "nebraska", "ne" },
52 { "nevada", "nv" },
53 { "new hampshire", "nh" },
54 { "new jersey", "nj" },
55 { "new mexico", "nm" },
56 { "new york", "ny" },
57 { "north carolina", "nc" },
58 { "north dakota", "nd" },
59 { "ohio", "oh" },
60 { "oklahoma", "ok" },
61 { "oregon", "or" },
62 { "pennsylvania", "pa" },
63 { "puerto rico", "pr" },
64 { "rhode island", "ri" },
65 { "south carolina", "sc" },
66 { "south dakota", "sd" },
67 { "tennessee", "tn" },
68 { "texas", "tx" },
69 { "utah", "ut" },
70 { "vermont", "vt" },
71 { "virginia", "va" },
72 { "washington", "wa" },
73 { "west virginia", "wv" },
74 { "wisconsin", "wi" },
75 { "wyoming", "wy" },
78 } // namespace
80 base::string16 GetAbbreviationForName(const base::string16& name) {
81 for (size_t i = 0; i < arraysize(kStateData); ++i) {
82 const StateData& state = kStateData[i];
83 if (base::LowerCaseEqualsASCII(name, state.name))
84 return base::ASCIIToUTF16(state.abbreviation);
86 return base::string16();
89 base::string16 GetNameForAbbreviation(const base::string16& abbreviation) {
90 for (size_t i = 0; i < arraysize(kStateData); ++i) {
91 const StateData& state = kStateData[i];
92 if (base::LowerCaseEqualsASCII(abbreviation, state.abbreviation))
93 return base::ASCIIToUTF16(state.name);
95 return base::string16();
98 void GetNameAndAbbreviation(const base::string16& value,
99 base::string16* name,
100 base::string16* abbreviation) {
101 base::string16 full = GetNameForAbbreviation(value);
102 base::string16 abbr = value;
103 if (full.empty()) {
104 abbr = GetAbbreviationForName(value);
105 full = value;
108 if (name)
109 name->swap(full);
110 if (abbreviation)
111 abbreviation->swap(abbr);
114 } // namespace state_names
115 } // namespace autofill