Locale.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/StringView.h>
  10. #include <AK/Vector.h>
  11. #include <LibUnicode/Forward.h>
  12. namespace Unicode {
  13. struct LanguageID {
  14. bool is_root { false };
  15. Optional<StringView> language {};
  16. Optional<StringView> script {};
  17. Optional<StringView> region {};
  18. Vector<StringView> variants {};
  19. };
  20. struct LocaleID {
  21. LanguageID language_id {};
  22. };
  23. // Note: These methods only verify that the provided strings match the EBNF grammar of the
  24. // Unicode identifier subtag (i.e. no validation is done that the tags actually exist).
  25. bool is_unicode_language_subtag(StringView);
  26. bool is_unicode_script_subtag(StringView);
  27. bool is_unicode_region_subtag(StringView);
  28. bool is_unicode_variant_subtag(StringView);
  29. Optional<LanguageID> parse_unicode_language_id(StringView);
  30. Optional<LocaleID> parse_unicode_locale_id(StringView);
  31. Optional<String> canonicalize_unicode_locale_id(LocaleID&);
  32. String const& default_locale();
  33. bool is_locale_available(StringView locale);
  34. Optional<StringView> get_locale_territory_mapping(StringView locale, StringView territory);
  35. }