| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef COMPONENTS_PAYMENTS_CURRENCY_FORMATTER_H_ | 5 #ifndef COMPONENTS_PAYMENTS_CORE_CURRENCY_FORMATTER_H_ |
| 6 #define COMPONENTS_PAYMENTS_CURRENCY_FORMATTER_H_ | 6 #define COMPONENTS_PAYMENTS_CORE_CURRENCY_FORMATTER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/optional.h" | |
| 13 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 14 #include "third_party/icu/source/common/unicode/locid.h" | 13 #include "third_party/icu/source/common/unicode/locid.h" |
| 14 #include "third_party/icu/source/common/unicode/unistr.h" |
| 15 #include "third_party/icu/source/i18n/unicode/numfmt.h" | 15 #include "third_party/icu/source/i18n/unicode/numfmt.h" |
| 16 | 16 |
| 17 namespace payments { | 17 namespace payments { |
| 18 | 18 |
| 19 // URI specifying the ISO4217 currency code specification. See for details: | 19 // URI specifying the ISO4217 currency code specification. See for details: |
| 20 // https://w3c.github.io/browser-payment-api/#paymentcurrencyamount-dictionary | 20 // https://w3c.github.io/browser-payment-api/#paymentcurrencyamount-dictionary |
| 21 extern const char kIso4217CurrencySystem[]; | 21 extern const char kIso4217CurrencySystem[]; |
| 22 | 22 |
| 23 // Currency formatter for amounts, according to a currency code, which typically | 23 // Currency formatter for amounts, according to a currency code, which typically |
| 24 // adheres to [ISO4217] (for example, "USD" for US Dollars). | 24 // adheres to [ISO4217] (for example, "USD" for US Dollars). |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 // Formats the |amount| according to the currency code that was set. The | 36 // Formats the |amount| according to the currency code that was set. The |
| 37 // result will NOT contain the currency code, nor a subset of it. Rather, the | 37 // result will NOT contain the currency code, nor a subset of it. Rather, the |
| 38 // caller of this function should display the currency code separately. The | 38 // caller of this function should display the currency code separately. The |
| 39 // return value may contain non-breaking space and is ready for display. In | 39 // return value may contain non-breaking space and is ready for display. In |
| 40 // the case of a failure in initialization of the formatter or during | 40 // the case of a failure in initialization of the formatter or during |
| 41 // formatter, this method will return |amount|. | 41 // formatter, this method will return |amount|. |
| 42 base::string16 Format(const std::string& amount); | 42 base::string16 Format(const std::string& amount); |
| 43 | 43 |
| 44 // Returns the formatted currency code (<= 6 characters including ellipsis if | 44 // Returns the formatted currency code (<= 6 characters including ellipsis if |
| 45 // applicable). | 45 // applicable). |
| 46 std::string formatted_currency_code() { return formatted_currency_code_; } | 46 const std::string& formatted_currency_code() const { |
| 47 return formatted_currency_code_; |
| 48 } |
| 47 | 49 |
| 48 private: | 50 private: |
| 49 const icu::Locale locale_; | 51 const icu::Locale locale_; |
| 50 std::unique_ptr<icu::UnicodeString> currency_code_; | 52 std::unique_ptr<icu::UnicodeString> currency_code_; |
| 51 std::string formatted_currency_code_; | 53 std::string formatted_currency_code_; |
| 52 std::unique_ptr<icu::NumberFormat> icu_formatter_; | 54 std::unique_ptr<icu::NumberFormat> icu_formatter_; |
| 53 | 55 |
| 54 DISALLOW_COPY_AND_ASSIGN(CurrencyFormatter); | 56 DISALLOW_COPY_AND_ASSIGN(CurrencyFormatter); |
| 55 }; | 57 }; |
| 56 | 58 |
| 57 } // namespace payments | 59 } // namespace payments |
| 58 | 60 |
| 59 #endif // COMPONENTS_PAYMENTS_CURRENCY_FORMATTER_H_ | 61 #endif // COMPONENTS_PAYMENTS_CORE_CURRENCY_FORMATTER_H_ |
| OLD | NEW |