PluralRules.cpp 786 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2022, Tim Flynn <trflynn89@pm.me>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/Intl/PluralRules.h>
  7. namespace JS::Intl {
  8. // 16 PluralRules Objects, https://tc39.es/ecma402/#pluralrules-objects
  9. PluralRules::PluralRules(Object& prototype)
  10. : NumberFormatBase(prototype)
  11. {
  12. }
  13. void PluralRules::set_type(StringView type)
  14. {
  15. if (type == "cardinal"sv) {
  16. m_type = Type::Cardinal;
  17. } else if (type == "ordinal"sv) {
  18. m_type = Type::Ordinal;
  19. } else {
  20. VERIFY_NOT_REACHED();
  21. }
  22. }
  23. StringView PluralRules::type_string() const
  24. {
  25. switch (m_type) {
  26. case Type::Cardinal:
  27. return "cardinal"sv;
  28. case Type::Ordinal:
  29. return "ordinal"sv;
  30. default:
  31. VERIFY_NOT_REACHED();
  32. }
  33. }
  34. }