2018-02-10 02:59:49 +00:00
|
|
|
// © 2018 and later: Unicode, Inc. and others.
|
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING && !UPRV_INCOMPLETE_CPP11_SUPPORT
|
|
|
|
#ifndef __NUMPARSE_CURRENCY_H__
|
|
|
|
#define __NUMPARSE_CURRENCY_H__
|
|
|
|
|
|
|
|
#include "numparse_types.h"
|
2018-02-10 06:36:07 +00:00
|
|
|
#include "numparse_compositions.h"
|
2018-02-10 02:59:49 +00:00
|
|
|
#include "charstr.h"
|
2018-03-21 05:17:28 +00:00
|
|
|
#include "number_currencysymbols.h"
|
2018-02-10 02:59:49 +00:00
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN namespace numparse {
|
|
|
|
namespace impl {
|
|
|
|
|
2018-03-21 05:17:28 +00:00
|
|
|
using ::icu::number::impl::CurrencySymbols;
|
2018-02-10 02:59:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Matches currencies according to all available strings in locale data.
|
|
|
|
*
|
|
|
|
* The implementation of this class is different between J and C. See #13584 for a follow-up.
|
|
|
|
*
|
|
|
|
* @author sffc
|
|
|
|
*/
|
|
|
|
class CurrencyNamesMatcher : public NumberParseMatcher, public UMemory {
|
|
|
|
public:
|
|
|
|
CurrencyNamesMatcher() = default; // WARNING: Leaves the object in an unusable state
|
|
|
|
|
|
|
|
CurrencyNamesMatcher(const Locale& locale, UErrorCode& status);
|
|
|
|
|
|
|
|
bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
|
|
|
|
|
2018-02-10 06:36:07 +00:00
|
|
|
const UnicodeSet& getLeadCodePoints() override;
|
2018-02-10 02:59:49 +00:00
|
|
|
|
2018-02-13 02:23:52 +00:00
|
|
|
UnicodeString toString() const override;
|
|
|
|
|
2018-02-10 02:59:49 +00:00
|
|
|
private:
|
|
|
|
// We could use Locale instead of CharString here, but
|
|
|
|
// Locale has a non-trivial default constructor.
|
|
|
|
CharString fLocaleName;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-10 06:36:07 +00:00
|
|
|
class CurrencyCustomMatcher : public NumberParseMatcher, public UMemory {
|
|
|
|
public:
|
2018-02-10 10:01:46 +00:00
|
|
|
CurrencyCustomMatcher() = default; // WARNING: Leaves the object in an unusable state
|
|
|
|
|
2018-03-21 05:17:28 +00:00
|
|
|
CurrencyCustomMatcher(const CurrencySymbols& currencySymbols, UErrorCode& status);
|
2018-02-10 06:36:07 +00:00
|
|
|
|
|
|
|
bool match(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const override;
|
|
|
|
|
|
|
|
const UnicodeSet& getLeadCodePoints() override;
|
|
|
|
|
2018-02-13 02:23:52 +00:00
|
|
|
UnicodeString toString() const override;
|
|
|
|
|
2018-02-10 06:36:07 +00:00
|
|
|
private:
|
|
|
|
UChar fCurrencyCode[4];
|
|
|
|
UnicodeString fCurrency1;
|
|
|
|
UnicodeString fCurrency2;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An implementation of AnyMatcher, allowing for either currency data or locale currency matches.
|
|
|
|
*/
|
|
|
|
class CurrencyAnyMatcher : public AnyMatcher, public UMemory {
|
|
|
|
public:
|
2018-02-10 10:01:46 +00:00
|
|
|
CurrencyAnyMatcher(); // WARNING: Leaves the object in an unusable state
|
|
|
|
|
2018-02-10 06:36:07 +00:00
|
|
|
CurrencyAnyMatcher(CurrencyNamesMatcher namesMatcher, CurrencyCustomMatcher customMatcher);
|
|
|
|
|
2018-02-10 11:32:18 +00:00
|
|
|
// Needs custom move constructor/operator since constructor is nontrivial
|
|
|
|
|
|
|
|
CurrencyAnyMatcher(CurrencyAnyMatcher&& src) U_NOEXCEPT;
|
|
|
|
|
|
|
|
CurrencyAnyMatcher& operator=(CurrencyAnyMatcher&& src) U_NOEXCEPT;
|
|
|
|
|
2018-02-10 06:36:07 +00:00
|
|
|
const UnicodeSet& getLeadCodePoints() override;
|
|
|
|
|
2018-02-13 02:23:52 +00:00
|
|
|
UnicodeString toString() const override;
|
|
|
|
|
2018-02-10 06:36:07 +00:00
|
|
|
protected:
|
|
|
|
const NumberParseMatcher* const* begin() const override;
|
|
|
|
|
|
|
|
const NumberParseMatcher* const* end() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CurrencyNamesMatcher fNamesMatcher;
|
|
|
|
CurrencyCustomMatcher fCustomMatcher;
|
|
|
|
|
|
|
|
const NumberParseMatcher* fMatcherArray[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-10 02:59:49 +00:00
|
|
|
} // namespace impl
|
|
|
|
} // namespace numparse
|
|
|
|
U_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif //__NUMPARSE_CURRENCY_H__
|
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|