tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

numparse_impl.h (3662B)


      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_IMPL_H__
      8 #define __NUMPARSE_IMPL_H__
      9 
     10 #include "numparse_types.h"
     11 #include "numparse_decimal.h"
     12 #include "numparse_symbols.h"
     13 #include "numparse_scientific.h"
     14 #include "unicode/uniset.h"
     15 #include "numparse_currency.h"
     16 #include "numparse_affixes.h"
     17 #include "number_decimfmtprops.h"
     18 #include "unicode/localpointer.h"
     19 #include "numparse_validators.h"
     20 #include "number_multiplier.h"
     21 #include "string_segment.h"
     22 
     23 U_NAMESPACE_BEGIN
     24 
     25 namespace numparse::impl {
     26 
     27 // Exported as U_I18N_API_CLASS for tests
     28 class U_I18N_API_CLASS NumberParserImpl : public MutableMatcherCollection, public UMemory {
     29  public:
     30    virtual ~NumberParserImpl();
     31 
     32    U_I18N_API static NumberParserImpl *createSimpleParser(const Locale& locale,
     33                                                           const UnicodeString& patternString,
     34                                                           parse_flags_t parseFlags,
     35                                                           UErrorCode& status);
     36 
     37    static NumberParserImpl* createParserFromProperties(
     38            const number::impl::DecimalFormatProperties& properties, const DecimalFormatSymbols& symbols,
     39            bool parseCurrency, UErrorCode& status);
     40 
     41    /**
     42     * Does NOT take ownership of the matcher. The matcher MUST remain valid for the lifespan of the
     43     * NumberParserImpl.
     44     * @param matcher The matcher to reference.
     45     */
     46    void addMatcher(NumberParseMatcher& matcher) override;
     47 
     48    void freeze();
     49 
     50    parse_flags_t getParseFlags() const;
     51 
     52    U_I18N_API void parse(const UnicodeString& input, bool greedy, ParsedNumber& result,
     53                          UErrorCode& status) const;
     54 
     55    void parse(const UnicodeString& input, int32_t start, bool greedy, ParsedNumber& result,
     56               UErrorCode& status) const;
     57 
     58    U_I18N_API UnicodeString toString() const;
     59 
     60  private:
     61    parse_flags_t fParseFlags;
     62    int32_t fNumMatchers = 0;
     63    // NOTE: The stack capacity for fMatchers and fLeads should be the same
     64    MaybeStackArray<const NumberParseMatcher*, 10> fMatchers;
     65    bool fFrozen = false;
     66 
     67    // WARNING: All of these matchers start in an undefined state (default-constructed).
     68    // You must use an assignment operator on them before using.
     69    struct {
     70        IgnorablesMatcher ignorables;
     71        InfinityMatcher infinity;
     72        MinusSignMatcher minusSign;
     73        NanMatcher nan;
     74        PaddingMatcher padding;
     75        PercentMatcher percent;
     76        PermilleMatcher permille;
     77        PlusSignMatcher plusSign;
     78        ApproximatelySignMatcher approximatelySign;
     79        DecimalMatcher decimal;
     80        ScientificMatcher scientific;
     81        CombinedCurrencyMatcher currency;
     82        AffixMatcherWarehouse affixMatcherWarehouse;
     83        AffixTokenMatcherWarehouse affixTokenMatcherWarehouse;
     84    } fLocalMatchers;
     85    struct {
     86        RequireAffixValidator affix;
     87        RequireCurrencyValidator currency;
     88        RequireDecimalSeparatorValidator decimalSeparator;
     89        RequireNumberValidator number;
     90        MultiplierParseHandler multiplier;
     91    } fLocalValidators;
     92 
     93    explicit NumberParserImpl(parse_flags_t parseFlags);
     94 
     95    void parseGreedy(StringSegment& segment, ParsedNumber& result, UErrorCode& status) const;
     96 
     97    void parseLongestRecursive(
     98        StringSegment& segment, ParsedNumber& result, int32_t recursionLevels, UErrorCode& status) const;
     99 };
    100 
    101 } // namespace numparse::impl
    102 
    103 U_NAMESPACE_END
    104 
    105 #endif //__NUMPARSE_IMPL_H__
    106 #endif /* #if !UCONFIG_NO_FORMATTING */