OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "modules/payments/ShippingAddress.h" |
| 6 |
| 7 namespace blink { |
| 8 namespace { |
| 9 |
| 10 bool isValidRegionCodeString(const String& code) |
| 11 { |
| 12 if (code.length() != 2) |
| 13 return false; |
| 14 |
| 15 for (size_t i = 0; i < code.length(); ++i) { |
| 16 if (code[i] < 'A' || code[i] > 'Z') |
| 17 return false; |
| 18 } |
| 19 |
| 20 return true; |
| 21 } |
| 22 |
| 23 bool isValidLanguageCodeString(const String& code) |
| 24 { |
| 25 if (code.isEmpty()) |
| 26 return true; |
| 27 |
| 28 if (code.length() != 2 && code.length() != 3) |
| 29 return false; |
| 30 |
| 31 for (size_t i = 0; i < code.length(); ++i) { |
| 32 if (code[i] < 'a' || code[i] > 'z') |
| 33 return false; |
| 34 } |
| 35 |
| 36 return true; |
| 37 } |
| 38 |
| 39 bool isValidScriptCodeString(const String& code) |
| 40 { |
| 41 if (code.isEmpty()) |
| 42 return true; |
| 43 |
| 44 if (code.length() != 4) |
| 45 return false; |
| 46 |
| 47 if (code[0] < 'A' || code[0] > 'A') |
| 48 return false; |
| 49 |
| 50 for (size_t i = 1; i < code.length(); ++i) { |
| 51 if (code[i] < 'a' || code[i] > 'z') |
| 52 return false; |
| 53 } |
| 54 |
| 55 return true; |
| 56 } |
| 57 |
| 58 } // namespace |
| 59 |
| 60 ShippingAddress::ShippingAddress(mojom::ShippingAddressPtr address) |
| 61 : m_regionCode(address->region_code) |
| 62 , m_addressLine(address->address_line.PassStorage()) |
| 63 , m_administrativeArea(address->administrative_area) |
| 64 , m_locality(address->locality) |
| 65 , m_dependentLocality(address->dependent_locality) |
| 66 , m_postalCode(address->postal_code) |
| 67 , m_sortingCode(address->sorting_code) |
| 68 , m_languageCode(address->language_code) |
| 69 , m_organization(address->organization) |
| 70 , m_recipient(address->recipient) |
| 71 , m_validRegionCode(isValidRegionCodeString(address->region_code)) |
| 72 , m_validLanguageCode(isValidLanguageCodeString(address->language_code)) |
| 73 , m_validScriptCode(isValidScriptCodeString(address->script_code)) |
| 74 { |
| 75 if (!m_languageCode.isEmpty() && !address->script_code.isEmpty()) { |
| 76 m_languageCode.append("-"); |
| 77 m_languageCode.append(address->script_code); |
| 78 } |
| 79 } |
| 80 |
| 81 ShippingAddress::~ShippingAddress() {} |
| 82 |
| 83 } // namespace blink |
OLD | NEW |