ListFormat.h 837 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. #include <AK/Vector.h>
  9. #include <LibUnicode/Locale.h>
  10. namespace Unicode {
  11. enum class ListFormatType {
  12. Conjunction,
  13. Disjunction,
  14. Unit,
  15. };
  16. ListFormatType list_format_type_from_string(StringView);
  17. StringView list_format_type_to_string(ListFormatType);
  18. class ListFormat {
  19. public:
  20. static NonnullOwnPtr<ListFormat> create(StringView locale, ListFormatType, Style);
  21. virtual ~ListFormat() = default;
  22. struct Partition {
  23. StringView type;
  24. String value;
  25. };
  26. virtual String format(ReadonlySpan<String> list) const = 0;
  27. virtual Vector<Partition> format_to_parts(ReadonlySpan<String> list) const = 0;
  28. protected:
  29. ListFormat() = default;
  30. };
  31. }