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

Side by Side Diff: components/autofill/core/browser/state_names.cc

Issue 2424793002: Revert of Replace for loops with |arraysize| with for each loops (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/state_names.h" 5 #include "components/autofill/core/browser/state_names.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 { "virginia", "va" }, 73 { "virginia", "va" },
74 { "washington", "wa" }, 74 { "washington", "wa" },
75 { "west virginia", "wv" }, 75 { "west virginia", "wv" },
76 { "wisconsin", "wi" }, 76 { "wisconsin", "wi" },
77 { "wyoming", "wy" }, 77 { "wyoming", "wy" },
78 }; 78 };
79 79
80 } // namespace 80 } // namespace
81 81
82 base::string16 GetAbbreviationForName(const base::string16& name) { 82 base::string16 GetAbbreviationForName(const base::string16& name) {
83 for (const StateData& state : kStateData) { 83 for (size_t i = 0; i < arraysize(kStateData); ++i) {
84 const StateData& state = kStateData[i];
84 if (base::LowerCaseEqualsASCII(name, state.name)) 85 if (base::LowerCaseEqualsASCII(name, state.name))
85 return base::ASCIIToUTF16(state.abbreviation); 86 return base::ASCIIToUTF16(state.abbreviation);
86 } 87 }
87 return base::string16(); 88 return base::string16();
88 } 89 }
89 90
90 base::string16 GetNameForAbbreviation(const base::string16& abbreviation) { 91 base::string16 GetNameForAbbreviation(const base::string16& abbreviation) {
91 for (const StateData& state : kStateData) { 92 for (size_t i = 0; i < arraysize(kStateData); ++i) {
93 const StateData& state = kStateData[i];
92 if (base::LowerCaseEqualsASCII(abbreviation, state.abbreviation)) 94 if (base::LowerCaseEqualsASCII(abbreviation, state.abbreviation))
93 return base::ASCIIToUTF16(state.name); 95 return base::ASCIIToUTF16(state.name);
94 } 96 }
95 return base::string16(); 97 return base::string16();
96 } 98 }
97 99
98 void GetNameAndAbbreviation(const base::string16& value, 100 void GetNameAndAbbreviation(const base::string16& value,
99 base::string16* name, 101 base::string16* name,
100 base::string16* abbreviation) { 102 base::string16* abbreviation) {
101 base::string16 full = GetNameForAbbreviation(value); 103 base::string16 full = GetNameForAbbreviation(value);
102 base::string16 abbr = value; 104 base::string16 abbr = value;
103 if (full.empty()) { 105 if (full.empty()) {
104 abbr = GetAbbreviationForName(value); 106 abbr = GetAbbreviationForName(value);
105 full = value; 107 full = value;
106 } 108 }
107 109
108 if (name) 110 if (name)
109 name->swap(full); 111 name->swap(full);
110 if (abbreviation) 112 if (abbreviation)
111 abbreviation->swap(abbr); 113 abbreviation->swap(abbr);
112 } 114 }
113 115
114 } // namespace state_names 116 } // namespace state_names
115 } // namespace autofill 117 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698