| 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_CURRENCY_FORMATTER_H_ |
| 6 #define COMPONENTS_PAYMENTS_CURRENCY_FORMATTER_H_ | 6 #define COMPONENTS_PAYMENTS_CURRENCY_FORMATTER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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). |
| 25 class CurrencyFormatter { | 25 class CurrencyFormatter { |
| 26 public: | 26 public: |
| 27 // Initializes the CurrencyFormatter for a given |currency_code|, | 27 // Initializes the CurrencyFormatter for a given |currency_code|, |
| 28 // |currency_system| and |locale_name|. Note that |currency_code| and | 28 // |currency_system| and |locale_name|. Note that |currency_code| and |
| 29 // |currency_system| should have been validated (as part of | 29 // |currency_system| should have been validated (as part of |
| 30 // payment_details_validation.h) before this is created. | 30 // payment_details_validation.h) before this is created. |
| 31 CurrencyFormatter(const std::string& currency_code, | 31 CurrencyFormatter(const std::string& currency_code, |
| 32 const base::Optional<std::string> currency_system, | 32 const std::string& currency_system, |
| 33 const std::string& locale_name); | 33 const std::string& locale_name); |
| 34 ~CurrencyFormatter(); | 34 ~CurrencyFormatter(); |
| 35 | 35 |
| 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 std::string formatted_currency_code() { return formatted_currency_code_; } |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 const icu::Locale locale_; | 49 const icu::Locale locale_; |
| 50 std::unique_ptr<icu::UnicodeString> currency_code_; | 50 std::unique_ptr<icu::UnicodeString> currency_code_; |
| 51 std::string formatted_currency_code_; | 51 std::string formatted_currency_code_; |
| 52 std::unique_ptr<icu::NumberFormat> icu_formatter_; | 52 std::unique_ptr<icu::NumberFormat> icu_formatter_; |
| 53 | 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(CurrencyFormatter); | 54 DISALLOW_COPY_AND_ASSIGN(CurrencyFormatter); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 } // namespace payments | 57 } // namespace payments |
| 58 | 58 |
| 59 #endif // COMPONENTS_PAYMENTS_CURRENCY_FORMATTER_H_ | 59 #endif // COMPONENTS_PAYMENTS_CURRENCY_FORMATTER_H_ |
| OLD | NEW |