NumberFormat.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Error.h>
  8. #include <AK/Optional.h>
  9. #include <AK/String.h>
  10. #include <AK/StringView.h>
  11. #include <AK/Vector.h>
  12. #include <LibLocale/Forward.h>
  13. #include <LibLocale/PluralRules.h>
  14. namespace Locale {
  15. struct NumberGroupings {
  16. u8 minimum_grouping_digits { 0 };
  17. u8 primary_grouping_size { 0 };
  18. u8 secondary_grouping_size { 0 };
  19. };
  20. enum class StandardNumberFormatType : u8 {
  21. Decimal,
  22. Currency,
  23. Accounting,
  24. Percent,
  25. Scientific,
  26. };
  27. enum class CompactNumberFormatType : u8 {
  28. DecimalLong,
  29. DecimalShort,
  30. CurrencyUnit,
  31. CurrencyShort,
  32. };
  33. struct NumberFormat {
  34. u8 magnitude { 0 };
  35. u8 exponent { 0 };
  36. PluralCategory plurality { PluralCategory::Other };
  37. StringView zero_format {};
  38. StringView positive_format {};
  39. StringView negative_format {};
  40. Vector<StringView> identifiers {};
  41. };
  42. enum class NumericSymbol : u8 {
  43. ApproximatelySign,
  44. Decimal,
  45. Exponential,
  46. Group,
  47. Infinity,
  48. MinusSign,
  49. NaN,
  50. PercentSign,
  51. PlusSign,
  52. RangeSeparator,
  53. TimeSeparator,
  54. };
  55. ErrorOr<Optional<StringView>> get_number_system_symbol(StringView locale, StringView system, NumericSymbol symbol);
  56. ErrorOr<Optional<NumberGroupings>> get_number_system_groupings(StringView locale, StringView system);
  57. Optional<ReadonlySpan<u32>> get_digits_for_number_system(StringView system);
  58. ErrorOr<String> replace_digits_for_number_system(StringView system, StringView number);
  59. ErrorOr<Optional<NumberFormat>> get_standard_number_system_format(StringView locale, StringView system, StandardNumberFormatType type);
  60. ErrorOr<Vector<NumberFormat>> get_compact_number_system_formats(StringView locale, StringView system, CompactNumberFormatType type);
  61. ErrorOr<Vector<NumberFormat>> get_unit_formats(StringView locale, StringView unit, Style style);
  62. ErrorOr<Optional<String>> augment_currency_format_pattern(StringView currency_display, StringView base_pattern);
  63. ErrorOr<Optional<String>> augment_range_pattern(StringView range_separator, StringView lower, StringView upper);
  64. }