| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_PAYMENTS_CURRENCY_FORMATTER_H_ |
| 6 #define COMPONENTS_PAYMENTS_CURRENCY_FORMATTER_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/optional.h" |
| 13 #include "base/strings/string16.h" |
| 14 #include "third_party/icu/source/common/unicode/locid.h" |
| 15 #include "third_party/icu/source/i18n/unicode/numfmt.h" |
| 16 |
| 17 namespace payments { |
| 18 |
| 19 // URI specifying the ISO4217 currency code specification. See for details: |
| 20 // https://w3c.github.io/browser-payment-api/#paymentcurrencyamount-dictionary |
| 21 extern const char kIso4217CurrencySystem[]; |
| 22 |
| 23 // Currency formatter for amounts, according to a currency code, which typically |
| 24 // adheres to [ISO4217] (for example, "USD" for US Dollars). |
| 25 class CurrencyFormatter { |
| 26 public: |
| 27 // Initializes the CurrencyFormatter for a given |currency_code|, |
| 28 // |currency_system| and |locale_name|. Note that |currency_code| and |
| 29 // |currency_system| should have been validated (as part of |
| 30 // payment_details_validation.h) before this is created. |
| 31 CurrencyFormatter(const std::string& currency_code, |
| 32 const base::Optional<std::string> currency_system, |
| 33 const std::string& locale_name); |
| 34 ~CurrencyFormatter(); |
| 35 |
| 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 |
| 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 |
| 40 // the case of a failure in initialization of the formatter or during |
| 41 // formatter, this method will return |amount|. |
| 42 base::string16 Format(const std::string& amount); |
| 43 |
| 44 private: |
| 45 const icu::Locale locale_; |
| 46 std::unique_ptr<icu::UnicodeString> currency_code_; |
| 47 std::unique_ptr<icu::NumberFormat> icu_formatter_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(CurrencyFormatter); |
| 50 }; |
| 51 |
| 52 } // namespace payments |
| 53 |
| 54 #endif // COMPONENTS_PAYMENTS_CURRENCY_FORMATTER_H_ |
| OLD | NEW |