blob: eba59c70ed7f02f302a568fc4961628050a434c1 [file] [log] [blame]
Victor Changce4bf3c2021-01-19 16:34:24 +00001// © 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
17U_NAMESPACE_BEGIN
18
19// Forward declarations
20namespace number {
21namespace impl {
22class UFormattedNumberRangeData;
23}
24}
25
26class 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
64U_NAMESPACE_END
65
66#endif /* #if !UCONFIG_NO_FORMATTING */
67#endif //__PLURALRANGES_H__