OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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. | |
4 | |
5 #include "components/autofill/browser/autofill_country.h" | |
6 | |
7 #include <stddef.h> | |
8 #include <stdint.h> | |
9 #include <map> | |
10 #include <utility> | |
11 | |
12 #include "base/logging.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/memory/singleton.h" | |
15 #include "base/stl_util.h" | |
16 #include "base/strings/string_util.h" | |
17 #include "base/strings/utf_string_conversions.h" | |
18 #include "grit/component_strings.h" | |
19 #include "third_party/icu/public/common/unicode/locid.h" | |
20 #include "third_party/icu/public/common/unicode/uloc.h" | |
21 #include "third_party/icu/public/common/unicode/unistr.h" | |
22 #include "third_party/icu/public/common/unicode/urename.h" | |
23 #include "third_party/icu/public/common/unicode/utypes.h" | |
24 #include "third_party/icu/public/i18n/unicode/coll.h" | |
25 #include "third_party/icu/public/i18n/unicode/ucol.h" | |
26 #include "ui/base/l10n/l10n_util.h" | |
27 | |
28 namespace autofill { | |
29 namespace { | |
30 | |
31 // The maximum capacity needed to store a locale up to the country code. | |
32 const size_t kLocaleCapacity = | |
33 ULOC_LANG_CAPACITY + ULOC_SCRIPT_CAPACITY + ULOC_COUNTRY_CAPACITY + 1; | |
34 | |
35 struct CountryData { | |
36 int postal_code_label_id; | |
37 int state_label_id; | |
38 AddressRequiredFields address_required_fields; | |
39 }; | |
40 | |
41 struct StaticCountryData { | |
42 char country_code[3]; | |
43 CountryData country_data; | |
44 }; | |
45 | |
46 // Maps country codes to localized label string identifiers. | |
47 const StaticCountryData kCountryData[] = { | |
48 { "AD", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
49 IDS_AUTOFILL_FIELD_LABEL_PARISH, | |
50 ADDRESS_REQUIRES_STATE } }, | |
51 { "AE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
52 IDS_AUTOFILL_FIELD_LABEL_EMIRATE, | |
53 ADDRESS_REQUIRES_STATE } }, | |
54 { "AF", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
55 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
56 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
57 { "AG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
58 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
59 ADDRESS_REQUIRES_ADDRESS_LINE_1_ONLY } }, | |
60 { "AI", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
61 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
62 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
63 { "AL", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
64 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
65 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
66 { "AM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
67 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
68 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
69 { "AN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
70 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
71 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
72 { "AO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
73 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
74 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
75 { "AQ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
76 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
77 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
78 { "AR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
79 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
80 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
81 { "AS", { IDS_AUTOFILL_FIELD_LABEL_ZIP_CODE, | |
82 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
83 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
84 { "AT", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
85 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
86 ADDRESS_REQUIRES_CITY_ZIP } }, | |
87 { "AU", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
88 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
89 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
90 { "AW", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
91 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
92 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
93 { "AX", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
94 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
95 ADDRESS_REQUIRES_CITY_ZIP } }, | |
96 { "AZ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
97 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
98 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
99 { "BA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
100 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
101 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
102 { "BB", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
103 IDS_AUTOFILL_FIELD_LABEL_PARISH, | |
104 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
105 { "BD", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
106 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
107 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
108 { "BE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
109 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
110 ADDRESS_REQUIRES_CITY_ZIP } }, | |
111 { "BF", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
112 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
113 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
114 { "BG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
115 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
116 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
117 { "BH", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
118 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
119 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
120 { "BI", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
121 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
122 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
123 { "BJ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
124 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
125 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
126 { "BL", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
127 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
128 ADDRESS_REQUIRES_CITY_ZIP } }, | |
129 { "BM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
130 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
131 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
132 { "BN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
133 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
134 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
135 { "BO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
136 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
137 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
138 { "BR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
139 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
140 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
141 { "BS", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
142 IDS_AUTOFILL_FIELD_LABEL_ISLAND, | |
143 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
144 { "BT", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
145 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
146 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
147 { "BV", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
148 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
149 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
150 { "BW", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
151 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
152 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
153 { "BY", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
154 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
155 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
156 { "BZ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
157 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
158 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
159 { "CA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
160 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
161 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
162 { "CC", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
163 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
164 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
165 { "CD", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
166 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
167 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
168 { "CF", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
169 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
170 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
171 { "CG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
172 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
173 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
174 { "CH", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
175 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
176 ADDRESS_REQUIRES_CITY_ZIP } }, | |
177 { "CI", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
178 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
179 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
180 { "CK", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
181 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
182 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
183 { "CL", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
184 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
185 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
186 { "CM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
187 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
188 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
189 { "CN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
190 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
191 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
192 { "CO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
193 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
194 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
195 { "CR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
196 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
197 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
198 { "CS", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
199 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
200 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
201 { "CV", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
202 IDS_AUTOFILL_FIELD_LABEL_ISLAND, | |
203 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
204 { "CX", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
205 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
206 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
207 { "CY", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
208 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
209 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
210 { "CZ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
211 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
212 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
213 { "DE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
214 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
215 ADDRESS_REQUIRES_CITY_ZIP } }, | |
216 { "DJ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
217 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
218 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
219 { "DK", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
220 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
221 ADDRESS_REQUIRES_CITY_ZIP } }, | |
222 { "DM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
223 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
224 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
225 { "DO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
226 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
227 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
228 { "DZ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
229 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
230 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
231 { "EC", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
232 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
233 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
234 { "EE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
235 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
236 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
237 { "EG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
238 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
239 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
240 { "EH", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
241 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
242 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
243 { "ER", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
244 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
245 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
246 { "ES", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
247 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
248 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
249 { "ET", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
250 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
251 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
252 { "FI", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
253 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
254 ADDRESS_REQUIRES_CITY_ZIP } }, | |
255 { "FJ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
256 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
257 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
258 { "FK", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
259 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
260 ADDRESS_REQUIRES_CITY_ZIP } }, | |
261 { "FM", { IDS_AUTOFILL_FIELD_LABEL_ZIP_CODE, | |
262 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
263 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
264 { "FO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
265 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
266 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
267 { "FR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
268 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
269 ADDRESS_REQUIRES_CITY_ZIP } }, | |
270 { "GA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
271 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
272 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
273 { "GB", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
274 IDS_AUTOFILL_FIELD_LABEL_COUNTY, | |
275 ADDRESS_REQUIRES_CITY_ZIP } }, | |
276 { "GD", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
277 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
278 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
279 { "GE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
280 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
281 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
282 { "GF", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
283 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
284 ADDRESS_REQUIRES_CITY_ZIP } }, | |
285 { "GG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
286 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
287 ADDRESS_REQUIRES_CITY_ZIP } }, | |
288 { "GH", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
289 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
290 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
291 { "GI", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
292 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
293 ADDRESS_REQUIRES_ADDRESS_LINE_1_ONLY } }, | |
294 { "GL", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
295 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
296 ADDRESS_REQUIRES_CITY_ZIP } }, | |
297 { "GM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
298 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
299 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
300 { "GN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
301 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
302 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
303 { "GP", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
304 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
305 ADDRESS_REQUIRES_CITY_ZIP } }, | |
306 { "GQ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
307 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
308 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
309 { "GR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
310 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
311 ADDRESS_REQUIRES_CITY_ZIP } }, | |
312 { "GS", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
313 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
314 ADDRESS_REQUIRES_CITY_ZIP } }, | |
315 { "GT", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
316 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
317 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
318 { "GU", { IDS_AUTOFILL_FIELD_LABEL_ZIP_CODE, | |
319 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
320 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
321 { "GW", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
322 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
323 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
324 { "GY", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
325 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
326 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
327 { "HK", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
328 IDS_AUTOFILL_FIELD_LABEL_AREA, | |
329 ADDRESS_REQUIRES_STATE } }, | |
330 { "HM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
331 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
332 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
333 { "HN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
334 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
335 ADDRESS_REQUIRES_CITY_STATE } }, | |
336 { "HR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
337 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
338 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
339 { "HT", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
340 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
341 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
342 { "HU", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
343 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
344 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
345 { "ID", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
346 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
347 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
348 { "IE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
349 IDS_AUTOFILL_FIELD_LABEL_COUNTY, | |
350 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
351 { "IL", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
352 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
353 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
354 { "IM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
355 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
356 ADDRESS_REQUIRES_CITY_ZIP } }, | |
357 { "IN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
358 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
359 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
360 { "IO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
361 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
362 ADDRESS_REQUIRES_CITY_ZIP } }, | |
363 { "IQ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
364 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
365 ADDRESS_REQUIRES_CITY_STATE } }, | |
366 { "IS", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
367 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
368 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
369 { "IT", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
370 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
371 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
372 { "JE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
373 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
374 ADDRESS_REQUIRES_CITY_ZIP } }, | |
375 { "JM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
376 IDS_AUTOFILL_FIELD_LABEL_PARISH, | |
377 ADDRESS_REQUIRES_CITY_STATE } }, | |
378 { "JO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
379 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
380 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
381 { "JP", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
382 IDS_AUTOFILL_FIELD_LABEL_PREFECTURE, | |
383 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
384 { "KE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
385 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
386 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
387 { "KG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
388 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
389 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
390 { "KH", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
391 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
392 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
393 { "KI", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
394 IDS_AUTOFILL_FIELD_LABEL_ISLAND, | |
395 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
396 { "KM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
397 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
398 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
399 { "KN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
400 IDS_AUTOFILL_FIELD_LABEL_ISLAND, | |
401 ADDRESS_REQUIRES_CITY_STATE } }, | |
402 { "KP", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
403 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
404 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
405 { "KR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
406 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
407 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
408 { "KW", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
409 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
410 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
411 { "KY", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
412 IDS_AUTOFILL_FIELD_LABEL_ISLAND, | |
413 ADDRESS_REQUIRES_STATE } }, | |
414 { "KZ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
415 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
416 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
417 { "LA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
418 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
419 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
420 { "LB", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
421 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
422 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
423 { "LC", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
424 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
425 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
426 { "LI", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
427 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
428 ADDRESS_REQUIRES_CITY_ZIP } }, | |
429 { "LK", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
430 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
431 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
432 { "LR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
433 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
434 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
435 { "LS", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
436 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
437 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
438 { "LT", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
439 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
440 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
441 { "LU", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
442 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
443 ADDRESS_REQUIRES_CITY_ZIP } }, | |
444 { "LV", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
445 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
446 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
447 { "LY", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
448 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
449 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
450 { "MA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
451 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
452 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
453 { "MC", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
454 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
455 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
456 { "MD", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
457 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
458 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
459 { "ME", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
460 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
461 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
462 { "MF", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
463 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
464 ADDRESS_REQUIRES_CITY_ZIP } }, | |
465 { "MG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
466 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
467 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
468 { "MH", { IDS_AUTOFILL_FIELD_LABEL_ZIP_CODE, | |
469 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
470 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
471 { "MK", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
472 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
473 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
474 { "ML", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
475 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
476 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
477 { "MN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
478 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
479 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
480 { "MO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
481 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
482 ADDRESS_REQUIRES_ADDRESS_LINE_1_ONLY } }, | |
483 { "MP", { IDS_AUTOFILL_FIELD_LABEL_ZIP_CODE, | |
484 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
485 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
486 { "MQ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
487 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
488 ADDRESS_REQUIRES_CITY_ZIP } }, | |
489 { "MR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
490 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
491 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
492 { "MS", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
493 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
494 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
495 { "MT", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
496 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
497 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
498 { "MU", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
499 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
500 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
501 { "MV", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
502 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
503 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
504 { "MW", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
505 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
506 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
507 { "MX", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
508 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
509 ADDRESS_REQUIRES_CITY_ZIP } }, | |
510 { "MY", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
511 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
512 ADDRESS_REQUIRES_CITY_ZIP } }, | |
513 { "MZ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
514 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
515 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
516 { "NA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
517 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
518 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
519 { "NC", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
520 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
521 ADDRESS_REQUIRES_CITY_ZIP } }, | |
522 { "NE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
523 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
524 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
525 { "NF", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
526 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
527 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
528 { "NG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
529 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
530 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
531 { "NI", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
532 IDS_AUTOFILL_FIELD_LABEL_DEPARTMENT, | |
533 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
534 { "NL", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
535 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
536 ADDRESS_REQUIRES_CITY_ZIP } }, | |
537 { "NO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
538 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
539 ADDRESS_REQUIRES_CITY_ZIP } }, | |
540 { "NP", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
541 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
542 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
543 { "NR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
544 IDS_AUTOFILL_FIELD_LABEL_DISTRICT, | |
545 ADDRESS_REQUIRES_STATE } }, | |
546 { "NU", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
547 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
548 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
549 { "NZ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
550 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
551 ADDRESS_REQUIRES_CITY_ZIP } }, | |
552 { "OM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
553 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
554 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
555 { "PA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
556 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
557 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
558 { "PE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
559 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
560 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
561 { "PF", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
562 IDS_AUTOFILL_FIELD_LABEL_ISLAND, | |
563 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
564 { "PG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
565 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
566 ADDRESS_REQUIRES_CITY_STATE } }, | |
567 { "PH", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
568 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
569 ADDRESS_REQUIRES_CITY } }, | |
570 { "PK", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
571 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
572 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
573 { "PL", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
574 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
575 ADDRESS_REQUIRES_CITY_ZIP } }, | |
576 { "PM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
577 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
578 ADDRESS_REQUIRES_CITY_ZIP } }, | |
579 { "PN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
580 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
581 ADDRESS_REQUIRES_CITY_ZIP } }, | |
582 { "PR", { IDS_AUTOFILL_FIELD_LABEL_ZIP_CODE, | |
583 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
584 ADDRESS_REQUIRES_CITY_ZIP } }, | |
585 { "PS", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
586 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
587 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
588 { "PT", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
589 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
590 ADDRESS_REQUIRES_CITY_ZIP } }, | |
591 { "PW", { IDS_AUTOFILL_FIELD_LABEL_ZIP_CODE, | |
592 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
593 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
594 { "PY", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
595 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
596 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
597 { "QA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
598 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
599 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
600 { "RE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
601 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
602 ADDRESS_REQUIRES_CITY_ZIP } }, | |
603 { "RO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
604 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
605 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
606 { "RS", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
607 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
608 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
609 { "RU", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
610 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
611 ADDRESS_REQUIRES_CITY_ZIP } }, | |
612 { "RW", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
613 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
614 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
615 { "SA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
616 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
617 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
618 { "SB", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
619 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
620 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
621 { "SC", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
622 IDS_AUTOFILL_FIELD_LABEL_ISLAND, | |
623 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
624 { "SE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
625 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
626 ADDRESS_REQUIRES_CITY_ZIP } }, | |
627 { "SG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
628 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
629 ADDRESS_REQUIRES_ZIP } }, | |
630 { "SH", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
631 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
632 ADDRESS_REQUIRES_CITY_ZIP } }, | |
633 { "SI", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
634 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
635 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
636 { "SJ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
637 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
638 ADDRESS_REQUIRES_CITY_ZIP } }, | |
639 { "SK", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
640 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
641 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
642 { "SL", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
643 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
644 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
645 { "SM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
646 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
647 ADDRESS_REQUIRES_ZIP } }, | |
648 { "SN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
649 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
650 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
651 { "SO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
652 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
653 ADDRESS_REQUIRES_CITY_STATE } }, | |
654 { "SR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
655 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
656 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
657 { "ST", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
658 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
659 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
660 { "SV", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
661 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
662 ADDRESS_REQUIRES_CITY_STATE } }, | |
663 { "SZ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
664 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
665 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
666 { "TC", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
667 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
668 ADDRESS_REQUIRES_CITY_ZIP } }, | |
669 { "TD", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
670 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
671 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
672 { "TF", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
673 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
674 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
675 { "TG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
676 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
677 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
678 { "TH", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
679 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
680 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
681 { "TJ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
682 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
683 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
684 { "TK", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
685 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
686 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
687 { "TL", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
688 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
689 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
690 { "TM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
691 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
692 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
693 { "TN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
694 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
695 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
696 { "TO", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
697 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
698 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
699 { "TR", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
700 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
701 ADDRESS_REQUIRES_CITY_ZIP } }, | |
702 { "TT", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
703 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
704 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
705 { "TV", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
706 IDS_AUTOFILL_FIELD_LABEL_ISLAND, | |
707 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
708 { "TW", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
709 IDS_AUTOFILL_FIELD_LABEL_COUNTY, | |
710 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
711 { "TZ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
712 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
713 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
714 { "UA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
715 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
716 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
717 { "UG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
718 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
719 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
720 { "UM", { IDS_AUTOFILL_FIELD_LABEL_ZIP_CODE, | |
721 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
722 ADDRESS_REQUIRES_CITY_STATE } }, | |
723 { "US", { IDS_AUTOFILL_FIELD_LABEL_ZIP_CODE, | |
724 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
725 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
726 { "UY", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
727 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
728 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
729 { "UZ", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
730 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
731 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
732 { "VA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
733 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
734 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
735 { "VC", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
736 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
737 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
738 { "VE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
739 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
740 ADDRESS_REQUIRES_CITY_STATE } }, | |
741 { "VG", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
742 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
743 ADDRESS_REQUIRES_ADDRESS_LINE_1_ONLY } }, | |
744 { "VI", { IDS_AUTOFILL_FIELD_LABEL_ZIP_CODE, | |
745 IDS_AUTOFILL_FIELD_LABEL_STATE, | |
746 ADDRESS_REQUIRES_CITY_STATE_ZIP } }, | |
747 { "VN", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
748 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
749 ADDRESS_REQUIRES_CITY } }, | |
750 { "VU", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
751 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
752 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
753 { "WF", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
754 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
755 ADDRESS_REQUIRES_CITY_ZIP } }, | |
756 { "WS", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
757 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
758 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
759 { "YE", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
760 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
761 ADDRESS_REQUIRES_CITY } }, | |
762 { "YT", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
763 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
764 ADDRESS_REQUIRES_CITY_ZIP } }, | |
765 { "ZA", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
766 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
767 ADDRESS_REQUIRES_CITY_ZIP } }, | |
768 { "ZM", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
769 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
770 ADDRESS_REQUIRES_CITY } }, | |
771 { "ZW", { IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
772 IDS_AUTOFILL_FIELD_LABEL_PROVINCE, | |
773 ADDRESS_REQUIREMENTS_UNKNOWN } }, | |
774 }; | |
775 | |
776 // A singleton class that encapsulates a map from country codes to country data. | |
777 class CountryDataMap { | |
778 public: | |
779 // A const iterator over the wrapped map data. | |
780 typedef std::map<std::string, CountryData>::const_iterator Iterator; | |
781 | |
782 static CountryDataMap* GetInstance(); | |
783 static const Iterator Begin(); | |
784 static const Iterator End(); | |
785 static const Iterator Find(const std::string& country_code); | |
786 | |
787 private: | |
788 CountryDataMap(); | |
789 friend struct DefaultSingletonTraits<CountryDataMap>; | |
790 | |
791 std::map<std::string, CountryData> country_data_; | |
792 | |
793 DISALLOW_COPY_AND_ASSIGN(CountryDataMap); | |
794 }; | |
795 | |
796 // static | |
797 CountryDataMap* CountryDataMap::GetInstance() { | |
798 return Singleton<CountryDataMap>::get(); | |
799 } | |
800 | |
801 CountryDataMap::CountryDataMap() { | |
802 // Add all the countries we have explicit data for. | |
803 for (size_t i = 0; i < arraysize(kCountryData); ++i) { | |
804 const StaticCountryData& static_data = kCountryData[i]; | |
805 country_data_.insert(std::make_pair(static_data.country_code, | |
806 static_data.country_data)); | |
807 } | |
808 | |
809 // Add any other countries that ICU knows about, falling back to default data | |
810 // values. | |
811 for (const char* const* country_pointer = icu::Locale::getISOCountries(); | |
812 *country_pointer; | |
813 ++country_pointer) { | |
814 std::string country_code = *country_pointer; | |
815 if (!country_data_.count(country_code)) { | |
816 CountryData data = { | |
817 IDS_AUTOFILL_FIELD_LABEL_POSTAL_CODE, | |
818 IDS_AUTOFILL_FIELD_LABEL_PROVINCE | |
819 }; | |
820 country_data_.insert(std::make_pair(country_code, data)); | |
821 } | |
822 } | |
823 } | |
824 | |
825 const CountryDataMap::Iterator CountryDataMap::Begin() { | |
826 return GetInstance()->country_data_.begin(); | |
827 } | |
828 | |
829 const CountryDataMap::Iterator CountryDataMap::End() { | |
830 return GetInstance()->country_data_.end(); | |
831 } | |
832 | |
833 const CountryDataMap::Iterator CountryDataMap::Find( | |
834 const std::string& country_code) { | |
835 return GetInstance()->country_data_.find(country_code); | |
836 } | |
837 | |
838 // A singleton class that encapsulates mappings from country names to their | |
839 // corresponding country codes. | |
840 class CountryNames { | |
841 public: | |
842 static CountryNames* GetInstance(); | |
843 | |
844 // Returns the country code corresponding to |country|, which should be a | |
845 // country code or country name localized to |locale|. | |
846 const std::string GetCountryCode(const base::string16& country, | |
847 const std::string& locale); | |
848 | |
849 private: | |
850 CountryNames(); | |
851 ~CountryNames(); | |
852 friend struct DefaultSingletonTraits<CountryNames>; | |
853 | |
854 // Populates |locales_to_localized_names_| with the mapping of country names | |
855 // localized to |locale| to their corresponding country codes. | |
856 void AddLocalizedNamesForLocale(const std::string& locale); | |
857 | |
858 // Interprets |country_name| as a full country name localized to the given | |
859 // |locale| and returns the corresponding country code stored in | |
860 // |locales_to_localized_names_|, or an empty string if there is none. | |
861 const std::string GetCountryCodeForLocalizedName( | |
862 const base::string16& country_name, | |
863 const std::string& locale); | |
864 | |
865 // Returns an ICU collator -- i.e. string comparator -- appropriate for the | |
866 // given |locale|. | |
867 icu::Collator* GetCollatorForLocale(const std::string& locale); | |
868 | |
869 // Returns the ICU sort key corresponding to |str| for the given |collator|. | |
870 // Uses |buffer| as temporary storage, and might resize |buffer| as a side- | |
871 // effect. |buffer_size| should specify the |buffer|'s size, and is updated if | |
872 // the |buffer| is resized. | |
873 const std::string GetSortKey(const icu::Collator& collator, | |
874 const base::string16& str, | |
875 scoped_ptr<uint8_t[]>* buffer, | |
876 int32_t* buffer_size) const; | |
877 | |
878 // Maps from common country names, including 2- and 3-letter country codes, | |
879 // to the corresponding 2-letter country codes. The keys are uppercase ASCII | |
880 // strings. | |
881 std::map<std::string, std::string> common_names_; | |
882 | |
883 // The outer map keys are ICU locale identifiers. | |
884 // The inner maps map from localized country names to their corresponding | |
885 // country codes. The inner map keys are ICU collation sort keys corresponding | |
886 // to the target localized country name. | |
887 std::map<std::string, std::map<std::string, std::string> > | |
888 locales_to_localized_names_; | |
889 | |
890 // Maps ICU locale names to their corresponding collators. | |
891 std::map<std::string, icu::Collator*> collators_; | |
892 | |
893 DISALLOW_COPY_AND_ASSIGN(CountryNames); | |
894 }; | |
895 | |
896 // static | |
897 CountryNames* CountryNames::GetInstance() { | |
898 return Singleton<CountryNames>::get(); | |
899 } | |
900 | |
901 CountryNames::CountryNames() { | |
902 // Add 2- and 3-letter ISO country codes. | |
903 for (CountryDataMap::Iterator it = CountryDataMap::Begin(); | |
904 it != CountryDataMap::End(); | |
905 ++it) { | |
906 const std::string& country_code = it->first; | |
907 std::string iso3_country_code = | |
908 icu::Locale(NULL, country_code.c_str()).getISO3Country(); | |
909 | |
910 common_names_.insert(std::make_pair(country_code, country_code)); | |
911 common_names_.insert(std::make_pair(iso3_country_code, country_code)); | |
912 } | |
913 | |
914 // Add a few other common synonyms. | |
915 common_names_.insert(std::make_pair("UNITED STATES OF AMERICA", "US")); | |
916 common_names_.insert(std::make_pair("U.S.A.", "US")); | |
917 common_names_.insert(std::make_pair("GREAT BRITAIN", "GB")); | |
918 common_names_.insert(std::make_pair("UK", "GB")); | |
919 common_names_.insert(std::make_pair("BRASIL", "BR")); | |
920 common_names_.insert(std::make_pair("DEUTSCHLAND", "DE")); | |
921 } | |
922 | |
923 CountryNames::~CountryNames() { | |
924 STLDeleteContainerPairSecondPointers(collators_.begin(), | |
925 collators_.end()); | |
926 } | |
927 | |
928 const std::string CountryNames::GetCountryCode(const base::string16& country, | |
929 const std::string& locale) { | |
930 // First, check common country names, including 2- and 3-letter country codes. | |
931 std::string country_utf8 = UTF16ToUTF8(StringToUpperASCII(country)); | |
932 std::map<std::string, std::string>::const_iterator result = | |
933 common_names_.find(country_utf8); | |
934 if (result != common_names_.end()) | |
935 return result->second; | |
936 | |
937 // Next, check country names localized to |locale|. | |
938 std::string country_code = GetCountryCodeForLocalizedName(country, locale); | |
939 if (!country_code.empty()) | |
940 return country_code; | |
941 | |
942 // Finally, check country names localized to US English. | |
943 return GetCountryCodeForLocalizedName(country, "en_US"); | |
944 } | |
945 | |
946 void CountryNames::AddLocalizedNamesForLocale(const std::string& locale) { | |
947 // Nothing to do if we've previously added the localized names for the given | |
948 // |locale|. | |
949 if (locales_to_localized_names_.count(locale)) | |
950 return; | |
951 | |
952 std::map<std::string, std::string> localized_names; | |
953 const icu::Collator* collator = GetCollatorForLocale(locale); | |
954 int32_t buffer_size = 1000; | |
955 scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); | |
956 | |
957 for (CountryDataMap::Iterator it = CountryDataMap::Begin(); | |
958 it != CountryDataMap::End(); | |
959 ++it) { | |
960 const std::string& country_code = it->first; | |
961 base::string16 country_name = l10n_util::GetDisplayNameForCountry( | |
962 country_code, locale); | |
963 std::string sort_key = GetSortKey(*collator, | |
964 country_name, | |
965 &buffer, | |
966 &buffer_size); | |
967 | |
968 localized_names.insert(std::make_pair(sort_key, country_code)); | |
969 } | |
970 | |
971 locales_to_localized_names_.insert(std::make_pair(locale, localized_names)); | |
972 } | |
973 | |
974 const std::string CountryNames::GetCountryCodeForLocalizedName( | |
975 const base::string16& country_name, | |
976 const std::string& locale) { | |
977 AddLocalizedNamesForLocale(locale); | |
978 | |
979 icu::Collator* collator = GetCollatorForLocale(locale); | |
980 | |
981 // As recommended[1] by ICU, initialize the buffer size to four times the | |
982 // source string length. | |
983 // [1] http://userguide.icu-project.org/collation/api#TOC-Examples | |
984 int32_t buffer_size = country_name.size() * 4; | |
985 scoped_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); | |
986 std::string sort_key = GetSortKey(*collator, | |
987 country_name, | |
988 &buffer, | |
989 &buffer_size); | |
990 | |
991 const std::map<std::string, std::string>& localized_names = | |
992 locales_to_localized_names_[locale]; | |
993 std::map<std::string, std::string>::const_iterator result = | |
994 localized_names.find(sort_key); | |
995 | |
996 if (result != localized_names.end()) | |
997 return result->second; | |
998 | |
999 return std::string(); | |
1000 } | |
1001 | |
1002 icu::Collator* CountryNames::GetCollatorForLocale(const std::string& locale) { | |
1003 if (!collators_.count(locale)) { | |
1004 icu::Locale icu_locale(locale.c_str()); | |
1005 UErrorCode ignored = U_ZERO_ERROR; | |
1006 icu::Collator* collator(icu::Collator::createInstance(icu_locale, ignored)); | |
1007 | |
1008 // Compare case-insensitively and ignoring punctuation. | |
1009 ignored = U_ZERO_ERROR; | |
1010 collator->setAttribute(UCOL_STRENGTH, UCOL_SECONDARY, ignored); | |
1011 ignored = U_ZERO_ERROR; | |
1012 collator->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, ignored); | |
1013 | |
1014 collators_.insert(std::make_pair(locale, collator)); | |
1015 } | |
1016 | |
1017 return collators_[locale]; | |
1018 } | |
1019 | |
1020 const std::string CountryNames::GetSortKey(const icu::Collator& collator, | |
1021 const base::string16& str, | |
1022 scoped_ptr<uint8_t[]>* buffer, | |
1023 int32_t* buffer_size) const { | |
1024 DCHECK(buffer); | |
1025 DCHECK(buffer_size); | |
1026 | |
1027 icu::UnicodeString icu_str(str.c_str(), str.length()); | |
1028 int32_t expected_size = collator.getSortKey(icu_str, buffer->get(), | |
1029 *buffer_size); | |
1030 if (expected_size > *buffer_size) { | |
1031 // If there wasn't enough space, grow the buffer and try again. | |
1032 *buffer_size = expected_size; | |
1033 buffer->reset(new uint8_t[*buffer_size]); | |
1034 DCHECK(buffer->get()); | |
1035 | |
1036 expected_size = collator.getSortKey(icu_str, buffer->get(), *buffer_size); | |
1037 DCHECK_EQ(*buffer_size, expected_size); | |
1038 } | |
1039 | |
1040 return std::string(reinterpret_cast<const char*>(buffer->get())); | |
1041 } | |
1042 | |
1043 } // namespace | |
1044 | |
1045 AutofillCountry::AutofillCountry(const std::string& country_code, | |
1046 const std::string& locale) { | |
1047 const CountryDataMap::Iterator result = CountryDataMap::Find(country_code); | |
1048 DCHECK(result != CountryDataMap::End()); | |
1049 const CountryData& data = result->second; | |
1050 | |
1051 country_code_ = country_code; | |
1052 name_ = l10n_util::GetDisplayNameForCountry(country_code, locale); | |
1053 postal_code_label_ = l10n_util::GetStringUTF16(data.postal_code_label_id); | |
1054 state_label_ = l10n_util::GetStringUTF16(data.state_label_id); | |
1055 address_required_fields_ = data.address_required_fields; | |
1056 } | |
1057 | |
1058 AutofillCountry::~AutofillCountry() { | |
1059 } | |
1060 | |
1061 // static | |
1062 void AutofillCountry::GetAvailableCountries( | |
1063 std::vector<std::string>* country_codes) { | |
1064 DCHECK(country_codes); | |
1065 | |
1066 for (CountryDataMap::Iterator it = CountryDataMap::Begin(); | |
1067 it != CountryDataMap::End(); | |
1068 ++it) { | |
1069 country_codes->push_back(it->first); | |
1070 } | |
1071 } | |
1072 | |
1073 // static | |
1074 const std::string AutofillCountry::CountryCodeForLocale( | |
1075 const std::string& locale) { | |
1076 // Add likely subtags to the locale. In particular, add any likely country | |
1077 // subtags -- e.g. for locales like "ru" that only include the language. | |
1078 std::string likely_locale; | |
1079 UErrorCode error_ignored = U_ZERO_ERROR; | |
1080 uloc_addLikelySubtags(locale.c_str(), | |
1081 WriteInto(&likely_locale, kLocaleCapacity), | |
1082 kLocaleCapacity, | |
1083 &error_ignored); | |
1084 | |
1085 // Extract the country code. | |
1086 std::string country_code = icu::Locale(likely_locale.c_str()).getCountry(); | |
1087 | |
1088 // Default to the United States if we have no better guess. | |
1089 if (CountryDataMap::Find(country_code) == CountryDataMap::End()) | |
1090 return "US"; | |
1091 | |
1092 return country_code; | |
1093 } | |
1094 | |
1095 // static | |
1096 const std::string AutofillCountry::GetCountryCode(const base::string16& country, | |
1097 const std::string& locale) { | |
1098 return CountryNames::GetInstance()->GetCountryCode(country, locale); | |
1099 } | |
1100 | |
1101 AutofillCountry::AutofillCountry(const std::string& country_code, | |
1102 const base::string16& name, | |
1103 const base::string16& postal_code_label, | |
1104 const base::string16& state_label) | |
1105 : country_code_(country_code), | |
1106 name_(name), | |
1107 postal_code_label_(postal_code_label), | |
1108 state_label_(state_label) { | |
1109 } | |
1110 | |
1111 } // namespace autofill | |
OLD | NEW |