xref: /aosp_15_r20/external/icu/libicu/cts_headers/pluralranges.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
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::impl {
21 class UFormattedNumberRangeData;
22 }
23 
24 class StandardPluralRanges : public UMemory {
25   public:
26     /** Create a new StandardPluralRanges for the given locale */
27     static StandardPluralRanges forLocale(const Locale& locale, UErrorCode& status);
28 
29     /** Explicit copy constructor */
30     StandardPluralRanges copy(UErrorCode& status) const;
31 
32     /** Create an object (called on an rvalue) */
33     LocalPointer<StandardPluralRanges> toPointer(UErrorCode& status) && noexcept;
34 
35     /** Select rule based on the first and second forms */
36     StandardPlural::Form resolve(StandardPlural::Form first, StandardPlural::Form second) const;
37 
38     /** Used for data loading. */
39     void addPluralRange(
40         StandardPlural::Form first,
41         StandardPlural::Form second,
42         StandardPlural::Form result);
43 
44     /** Used for data loading. */
45     void setCapacity(int32_t length, UErrorCode& status);
46 
47   private:
48     struct StandardPluralRangeTriple {
49         StandardPlural::Form first;
50         StandardPlural::Form second;
51         StandardPlural::Form result;
52     };
53 
54     // TODO: An array is simple here, but it results in linear lookup time.
55     // Certain locales have 20-30 entries in this list.
56     // Consider changing to a smarter data structure.
57     typedef MaybeStackArray<StandardPluralRangeTriple, 3> PluralRangeTriples;
58     PluralRangeTriples fTriples;
59     int32_t fTriplesLen = 0;
60 };
61 
62 U_NAMESPACE_END
63 
64 #endif /* #if !UCONFIG_NO_FORMATTING */
65 #endif //__PLURALRANGES_H__
66