Locale.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/Vector.h>
  10. #include <LibJS/Runtime/Object.h>
  11. #include <LibJS/Runtime/Value.h>
  12. #include <LibUnicode/Forward.h>
  13. namespace JS::Intl {
  14. class Locale final : public Object {
  15. JS_OBJECT(Locale, Object);
  16. public:
  17. static Locale* create(GlobalObject&, Unicode::LocaleID const&);
  18. static Vector<StringView> const& relevant_extension_keys(); // [[RelevantExtensionKeys]]
  19. Locale(Object& prototype);
  20. Locale(Unicode::LocaleID const&, Object& prototype);
  21. virtual ~Locale() override = default;
  22. String const& locale() const { return m_locale; }
  23. void set_locale(String locale) { m_locale = move(locale); }
  24. bool has_calendar() const { return m_calendar.has_value(); }
  25. String const& calendar() const { return m_calendar.value(); }
  26. void set_calendar(String calendar) { m_calendar = move(calendar); }
  27. bool has_case_first() const { return m_case_first.has_value(); }
  28. String const& case_first() const { return m_case_first.value(); }
  29. void set_case_first(String case_first) { m_case_first = move(case_first); }
  30. bool has_collation() const { return m_collation.has_value(); }
  31. String const& collation() const { return m_collation.value(); }
  32. void set_collation(String collation) { m_collation = move(collation); }
  33. bool has_hour_cycle() const { return m_hour_cycle.has_value(); }
  34. String const& hour_cycle() const { return m_hour_cycle.value(); }
  35. void set_hour_cycle(String hour_cycle) { m_hour_cycle = move(hour_cycle); }
  36. bool has_numbering_system() const { return m_numbering_system.has_value(); }
  37. String const& numbering_system() const { return m_numbering_system.value(); }
  38. void set_numbering_system(String numbering_system) { m_numbering_system = move(numbering_system); }
  39. bool numeric() const { return m_numeric; }
  40. void set_numeric(bool numeric) { m_numeric = numeric; }
  41. private:
  42. String m_locale; // [[Locale]]
  43. Optional<String> m_calendar; // [[Calendar]]
  44. Optional<String> m_case_first; // [[CaseFirst]]
  45. Optional<String> m_collation; // [[Collation]]
  46. Optional<String> m_hour_cycle; // [[HourCycle]]
  47. Optional<String> m_numbering_system; // [[NumberingSystem]]
  48. bool m_numeric { false }; // [[Numeric]]
  49. };
  50. }