Index: components/autofill/core/browser/address_i18n.cc |
diff --git a/components/autofill/core/browser/address_i18n.cc b/components/autofill/core/browser/address_i18n.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7e23a33269bfadec2f81b602181146724a7fc255 |
--- /dev/null |
+++ b/components/autofill/core/browser/address_i18n.cc |
@@ -0,0 +1,43 @@ |
+// Copyright 2014 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/address_i18n.h" |
+ |
+#include "base/logging.h" |
+#include "base/strings/string_split.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "components/autofill/core/browser/autofill_type.h" |
+#include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_data.h" |
+ |
+namespace autofill { |
+namespace i18n { |
+ |
+using ::i18n::addressinput::AddressData; |
+ |
+scoped_ptr<AddressData> CreateAddressData( |
+ const base::Callback<base::string16(const AutofillType&)>& get_info) { |
+ scoped_ptr<AddressData> address_data(new AddressData()); |
+ address_data->recipient = UTF16ToUTF8(get_info.Run(AutofillType(NAME_FULL))); |
+ address_data->country_code = UTF16ToUTF8( |
+ get_info.Run(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_SHIPPING))); |
Ilya Sherman
2014/05/07 01:19:19
nit: Why SHIPPING as opposed to NONE?
Evan Stade
2014/05/09 22:14:59
Done.
|
+ DCHECK_EQ(2U, address_data->country_code.size()); |
Ilya Sherman
2014/05/07 01:19:19
What if the country code is unspecified?
Evan Stade
2014/05/09 22:14:59
added a testcase
|
+ address_data->administrative_area = UTF16ToUTF8( |
+ get_info.Run(AutofillType(ADDRESS_HOME_STATE))); |
+ address_data->locality = UTF16ToUTF8( |
+ get_info.Run(AutofillType(ADDRESS_HOME_CITY))); |
+ address_data->dependent_locality = UTF16ToUTF8( |
+ get_info.Run(AutofillType(ADDRESS_HOME_DEPENDENT_LOCALITY))); |
+ address_data->sorting_code = UTF16ToUTF8( |
+ get_info.Run(AutofillType(ADDRESS_HOME_SORTING_CODE))); |
+ address_data->postal_code = UTF16ToUTF8( |
+ get_info.Run(AutofillType(ADDRESS_HOME_ZIP))); |
+ base::SplitString( |
+ UTF16ToUTF8(get_info.Run(AutofillType(ADDRESS_HOME_STREET_ADDRESS))), |
+ '\n', |
Ilya Sherman
2014/05/07 01:19:19
Not all addresses are joined with newlines, right?
Evan Stade
2014/05/09 22:14:59
Yes, all addresses are joined with newlines in the
|
+ &address_data->address_lines); |
+ return address_data.Pass(); |
+} |
+ |
+} // namespace i18n |
+} // namespace autofill |