numparse_currency.h 2.3 KB

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