• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2018 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 
4 #include "unicode/utypes.h"
5 
6 #if !UCONFIG_NO_FORMATTING
7 #ifndef __NUMPARSE_CURRENCY_H__
8 #define __NUMPARSE_CURRENCY_H__
9 
10 #include "numparse_types.h"
11 #include "numparse_compositions.h"
12 #include "charstr.h"
13 #include "number_currencysymbols.h"
14 #include "unicode/uniset.h"
15 
16 U_NAMESPACE_BEGIN namespace numparse {
17 namespace impl {
18 
19 using ::icu::number::impl::CurrencySymbols;
20 
21 /**
22  * Matches a currency, either a custom currency or one from the data bundle. The class is called
23  * "combined" to emphasize that the currency string may come from one of multiple sources.
24  *
25  * Will match currency spacing either before or after the number depending on whether we are currently in
26  * the prefix or suffix.
27  *
28  * The implementation of this class is slightly different between J and C. See #13584 for a follow-up.
29  *
30  * @author sffc
31  */
32 // Exported as U_I18N_API for tests
33 class U_I18N_API CombinedCurrencyMatcher : public NumberParseMatcher, public UMemory {
34   public:
35     CombinedCurrencyMatcher() = default;  // WARNING: Leaves the object in an unusable state
36 
37     CombinedCurrencyMatcher(const CurrencySymbols& currencySymbols, const DecimalFormatSymbols& dfs,
38                             parse_flags_t parseFlags, UErrorCode& status);
39 
40     bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
41 
42     bool smokeTest(const StringSegment& segment) const override;
43 
44     UnicodeString toString() const override;
45 
46   private:
47     UChar fCurrencyCode[4];
48     UnicodeString fCurrency1;
49     UnicodeString fCurrency2;
50 
51     bool fUseFullCurrencyData;
52     UnicodeString fLocalLongNames[StandardPlural::COUNT];
53 
54     UnicodeString afterPrefixInsert;
55     UnicodeString beforeSuffixInsert;
56 
57     // We could use Locale instead of CharString here, but
58     // Locale has a non-trivial default constructor.
59     CharString fLocaleName;
60 
61     // TODO: See comments in constructor in numparse_currency.cpp
62     // UnicodeSet fLeadCodePoints;
63 
64     /** Matches the currency string without concern for currency spacing. */
65     bool matchCurrency(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const;
66 };
67 
68 
69 } // namespace impl
70 } // namespace numparse
71 U_NAMESPACE_END
72 
73 #endif //__NUMPARSE_CURRENCY_H__
74 #endif /* #if !UCONFIG_NO_FORMATTING */
75