DisplayNames.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/String.h>
  8. #include <AK/StringView.h>
  9. #include <LibJS/Runtime/Object.h>
  10. namespace JS::Intl {
  11. class DisplayNames final : public Object {
  12. JS_OBJECT(DisplayNames, Object);
  13. enum class Style {
  14. Invalid,
  15. Narrow,
  16. Short,
  17. Long,
  18. };
  19. enum class Type {
  20. Invalid,
  21. Language,
  22. Region,
  23. Script,
  24. Currency,
  25. };
  26. enum class Fallback {
  27. Invalid,
  28. None,
  29. Code,
  30. };
  31. public:
  32. DisplayNames(Object& prototype);
  33. virtual ~DisplayNames() override = default;
  34. String const& locale() const { return m_locale; }
  35. void set_locale(String locale) { m_locale = move(locale); }
  36. Style style() const { return m_style; }
  37. void set_style(StringView style);
  38. StringView style_string() const;
  39. Type type() const { return m_type; }
  40. void set_type(StringView type);
  41. StringView type_string() const;
  42. Fallback fallback() const { return m_fallback; }
  43. void set_fallback(StringView fallback);
  44. StringView fallback_string() const;
  45. private:
  46. String m_locale; // [[Locale]]
  47. Style m_style { Style::Invalid }; // [[Style]]
  48. Type m_type { Type::Invalid }; // [[Type]]
  49. Fallback m_fallback { Fallback::Invalid }; // [[Fallback]]
  50. };
  51. ThrowCompletionOr<Value> canonical_code_for_display_names(GlobalObject& global_object, DisplayNames::Type type, StringView code);
  52. }