NumberFormat.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Optional.h>
  8. #include <AK/String.h>
  9. #include <AK/StringView.h>
  10. #include <AK/Vector.h>
  11. #include <LibUnicode/Forward.h>
  12. namespace Unicode {
  13. struct NumberGroupings {
  14. u8 primary_grouping_size { 0 };
  15. u8 secondary_grouping_size { 0 };
  16. };
  17. enum class StandardNumberFormatType : u8 {
  18. Decimal,
  19. Currency,
  20. Accounting,
  21. Percent,
  22. Scientific,
  23. };
  24. enum class CompactNumberFormatType : u8 {
  25. DecimalLong,
  26. DecimalShort,
  27. CurrencyUnit,
  28. CurrencyShort,
  29. };
  30. struct NumberFormat {
  31. enum class Plurality : u8 {
  32. Other,
  33. Zero,
  34. Single,
  35. One,
  36. Two,
  37. Few,
  38. Many,
  39. };
  40. u8 magnitude { 0 };
  41. u8 exponent { 0 };
  42. Plurality plurality { Plurality::Other };
  43. StringView zero_format {};
  44. StringView positive_format {};
  45. StringView negative_format {};
  46. Vector<StringView> identifiers {};
  47. };
  48. Optional<StringView> get_number_system_symbol(StringView locale, StringView system, StringView symbol);
  49. Optional<NumberGroupings> get_number_system_groupings(StringView locale, StringView system);
  50. Optional<NumberFormat> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type);
  51. Vector<NumberFormat> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type);
  52. Vector<NumberFormat> get_unit_formats(StringView locale, StringView unit, Style style);
  53. Optional<NumberFormat> select_pattern_with_plurality(Vector<NumberFormat> const& formats, double number);
  54. Optional<String> augment_currency_format_pattern(StringView currency_display, StringView base_pattern);
  55. }