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

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

Issue 2417783004: Replace for loops with |arraysize| with for each loops (Closed)
Patch Set: Adressed Comments 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 (size_t i = 0; i < arraysize(kStateData); ++i) { 83 for (const StateData& state : kStateData) {
84 const StateData& state = kStateData[i];
85 if (base::LowerCaseEqualsASCII(name, state.name)) 84 if (base::LowerCaseEqualsASCII(name, state.name))
86 return base::ASCIIToUTF16(state.abbreviation); 85 return base::ASCIIToUTF16(state.abbreviation);
87 } 86 }
88 return base::string16(); 87 return base::string16();
89 } 88 }
90 89
91 base::string16 GetNameForAbbreviation(const base::string16& abbreviation) { 90 base::string16 GetNameForAbbreviation(const base::string16& abbreviation) {
92 for (size_t i = 0; i < arraysize(kStateData); ++i) { 91 for (const StateData& state : kStateData) {
93 const StateData& state = kStateData[i];
94 if (base::LowerCaseEqualsASCII(abbreviation, state.abbreviation)) 92 if (base::LowerCaseEqualsASCII(abbreviation, state.abbreviation))
95 return base::ASCIIToUTF16(state.name); 93 return base::ASCIIToUTF16(state.name);
96 } 94 }
97 return base::string16(); 95 return base::string16();
98 } 96 }
99 97
100 void GetNameAndAbbreviation(const base::string16& value, 98 void GetNameAndAbbreviation(const base::string16& value,
101 base::string16* name, 99 base::string16* name,
102 base::string16* abbreviation) { 100 base::string16* abbreviation) {
103 base::string16 full = GetNameForAbbreviation(value); 101 base::string16 full = GetNameForAbbreviation(value);
104 base::string16 abbr = value; 102 base::string16 abbr = value;
105 if (full.empty()) { 103 if (full.empty()) {
106 abbr = GetAbbreviationForName(value); 104 abbr = GetAbbreviationForName(value);
107 full = value; 105 full = value;
108 } 106 }
109 107
110 if (name) 108 if (name)
111 name->swap(full); 109 name->swap(full);
112 if (abbreviation) 110 if (abbreviation)
113 abbreviation->swap(abbr); 111 abbreviation->swap(abbr);
114 } 112 }
115 113
116 } // namespace state_names 114 } // namespace state_names
117 } // namespace autofill 115 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698