Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: components/payments/currency_formatter.h

Issue 2621033003: [Payments] Currency formatter for order amounts. (Closed)
Patch Set: currency formatter takes locale_name as string Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/optional.h"
12 #include "base/strings/string16.h"
13 #include "third_party/icu/source/common/unicode/locid.h"
14 #include "third_party/icu/source/i18n/unicode/numfmt.h"
15
16 namespace payments {
17
18 // URI specifying the ISO4217 currency code specification. See for details:
19 // https://w3c.github.io/browser-payment-api/#paymentcurrencyamount-dictionary
20 extern const char kIso4217CurrencySystem[];
21
22 // Currency formatter for amounts, according to a currency code, which typically
23 // adheres to [ISO4217] (for example, "USD" for US Dollars).
24 class CurrencyFormatter {
25 public:
26 // Initializes the CurrencyFormatter for a given |currency_code|,
27 // |currency_system| and |locale_name|. Note that |currency_code| and
28 // |currency_system| should have been validated (as part of
29 // payment_details_validation.h) before this is created.
30 CurrencyFormatter(const std::string& currency_code,
31 const base::Optional<std::string> currency_system,
32 const std::string& locale_name);
33 ~CurrencyFormatter();
34
35 // Formats the |amount| according to the currency code that was set. The
36 // result will NOT contain the currency code, nor a subset of it. Rather, the
37 // caller of this function should display the currency code separately. The
38 // return value may contain non-breaking space and is ready for display. In
39 // the case of a failure in initialization of the formatter or during
40 // formatter, this method will return |amount|.
41 base::string16 Format(const std::string& amount);
42
43 private:
44 const icu::Locale locale_;
45 std::unique_ptr<icu::UnicodeString> currency_code_;
46 std::unique_ptr<icu::NumberFormat> icu_formatter_;
47 };
please use gerrit instead 2017/01/12 19:23:24 DISALLOW_COPY_AND_ASSIGN for good measure.
Mathieu 2017/01/12 20:29:57 Done.
48
49 } // namespace payments
50
51 #endif // COMPONENTS_PAYMENTS_CURRENCY_FORMATTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698