1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/autofill/core/browser/state_names.h"
#include <stddef.h>
#include "base/macros.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
namespace autofill {
namespace state_names {
namespace {
// TODO(jhawkins): Add more states/provinces. See http://crbug.com/45039.
struct StateData {
const char* const name;
const char abbreviation[3];
};
StateData kStateData[] = {
{ "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", "mn" },
{ "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" },
};
} // namespace
base::string16 GetAbbreviationForName(const base::string16& name) {
for (const StateData& state : kStateData) {
if (base::LowerCaseEqualsASCII(name, state.name))
return base::ASCIIToUTF16(state.abbreviation);
}
return base::string16();
}
base::string16 GetNameForAbbreviation(const base::string16& abbreviation) {
for (const StateData& state : kStateData) {
if (base::LowerCaseEqualsASCII(abbreviation, state.abbreviation))
return base::ASCIIToUTF16(state.name);
}
return base::string16();
}
void GetNameAndAbbreviation(const base::string16& value,
base::string16* name,
base::string16* abbreviation) {
base::string16 full = GetNameForAbbreviation(value);
base::string16 abbr = value;
if (full.empty()) {
abbr = GetAbbreviationForName(value);
full = value;
}
if (name)
name->swap(full);
if (abbreviation)
abbreviation->swap(abbr);
}
} // namespace state_names
} // namespace autofill
|