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"
12 namespace state_names
{
16 // TODO(jhawkins): Add more states/provinces. See http://crbug.com/45039.
19 const char* const name
;
20 const char abbreviation
[3];
23 StateData kStateData
[] = {
28 { "california", "ca" },
30 { "connecticut", "ct" },
32 { "district of columbia", "dc" },
42 { "louisiana", "la" },
45 { "massachusetts", "ma" },
47 { "minnesota", "mn" },
48 { "mississippi", "ms" },
53 { "new hampshire", "nh" },
54 { "new jersey", "nj" },
55 { "new mexico", "nm" },
57 { "north carolina", "nc" },
58 { "north dakota", "nd" },
62 { "pennsylvania", "pa" },
63 { "puerto rico", "pr" },
64 { "rhode island", "ri" },
65 { "south carolina", "sc" },
66 { "south dakota", "sd" },
67 { "tennessee", "tn" },
72 { "washington", "wa" },
73 { "west virginia", "wv" },
74 { "wisconsin", "wi" },
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
,
100 base::string16
* abbreviation
) {
101 base::string16 full
= GetNameForAbbreviation(value
);
102 base::string16 abbr
= value
;
104 abbr
= GetAbbreviationForName(value
);
111 abbreviation
->swap(abbr
);
114 } // namespace state_names
115 } // namespace autofill