1 // © 2018 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 4 #ifndef __PLURALRANGES_H__ 5 #define __PLURALRANGES_H__ 6 7 #include "unicode/utypes.h" 8 9 #if !UCONFIG_NO_FORMATTING 10 11 #include "unicode/uobject.h" 12 #include "unicode/locid.h" 13 #include "unicode/plurrule.h" 14 #include "standardplural.h" 15 #include "cmemory.h" 16 17 U_NAMESPACE_BEGIN 18 19 // Forward declarations 20 namespace number { 21 namespace impl { 22 class UFormattedNumberRangeData; 23 } 24 } 25 26 class StandardPluralRanges : public UMemory { 27 public: 28 /** Create a new StandardPluralRanges for the given locale */ 29 static StandardPluralRanges forLocale(const Locale& locale, UErrorCode& status); 30 31 /** Explicit copy constructor */ 32 StandardPluralRanges copy(UErrorCode& status) const; 33 34 /** Create an object (called on an rvalue) */ 35 LocalPointer<StandardPluralRanges> toPointer(UErrorCode& status) && noexcept; 36 37 /** Select rule based on the first and second forms */ 38 StandardPlural::Form resolve(StandardPlural::Form first, StandardPlural::Form second) const; 39 40 /** Used for data loading. */ 41 void addPluralRange( 42 StandardPlural::Form first, 43 StandardPlural::Form second, 44 StandardPlural::Form result); 45 46 /** Used for data loading. */ 47 void setCapacity(int32_t length, UErrorCode& status); 48 49 private: 50 struct StandardPluralRangeTriple { 51 StandardPlural::Form first; 52 StandardPlural::Form second; 53 StandardPlural::Form result; 54 }; 55 56 // TODO: An array is simple here, but it results in linear lookup time. 57 // Certain locales have 20-30 entries in this list. 58 // Consider changing to a smarter data structure. 59 typedef MaybeStackArray<StandardPluralRangeTriple, 3> PluralRangeTriples; 60 PluralRangeTriples fTriples; 61 int32_t fTriplesLen = 0; 62 }; 63 64 U_NAMESPACE_END 65 66 #endif /* #if !UCONFIG_NO_FORMATTING */ 67 #endif //__PLURALRANGES_H__ 68