ListFormat.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2021, Tim Flynn <trflynn89@pm.me>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/Intl/ListFormat.h>
  7. namespace JS::Intl {
  8. // 13 ListFomat Objects, https://tc39.es/ecma402/#listformat-objects
  9. ListFormat::ListFormat(Object& prototype)
  10. : Object(prototype)
  11. {
  12. }
  13. void ListFormat::set_type(StringView type)
  14. {
  15. if (type == "conjunction"sv) {
  16. m_type = Type::Conjunction;
  17. } else if (type == "disjunction"sv) {
  18. m_type = Type::Disjunction;
  19. } else if (type == "unit"sv) {
  20. m_type = Type::Unit;
  21. } else {
  22. VERIFY_NOT_REACHED();
  23. }
  24. }
  25. StringView ListFormat::type_string() const
  26. {
  27. switch (m_type) {
  28. case Type::Conjunction:
  29. return "conjunction"sv;
  30. case Type::Disjunction:
  31. return "disjunction"sv;
  32. case Type::Unit:
  33. return "unit"sv;
  34. default:
  35. VERIFY_NOT_REACHED();
  36. }
  37. }
  38. void ListFormat::set_style(StringView style)
  39. {
  40. if (style == "narrow"sv) {
  41. m_style = Style::Narrow;
  42. } else if (style == "short"sv) {
  43. m_style = Style::Short;
  44. } else if (style == "long"sv) {
  45. m_style = Style::Long;
  46. } else {
  47. VERIFY_NOT_REACHED();
  48. }
  49. }
  50. StringView ListFormat::style_string() const
  51. {
  52. switch (m_style) {
  53. case Style::Narrow:
  54. return "narrow"sv;
  55. case Style::Short:
  56. return "short"sv;
  57. case Style::Long:
  58. return "long"sv;
  59. default:
  60. VERIFY_NOT_REACHED();
  61. }
  62. }
  63. }