pluralranges.h 1.9 KB

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