CharacterTypes.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2021-2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteString.h>
  8. #include <AK/Forward.h>
  9. #include <AK/Optional.h>
  10. #include <AK/Span.h>
  11. #include <AK/String.h>
  12. #include <AK/Types.h>
  13. #include <AK/Vector.h>
  14. #include <LibUnicode/Forward.h>
  15. namespace Unicode {
  16. struct CodePointRange {
  17. u32 first { 0 };
  18. u32 last { 0 };
  19. };
  20. struct CodePointRangeComparator {
  21. constexpr int operator()(u32 code_point, CodePointRange const& range)
  22. {
  23. return (code_point > range.last) - (code_point < range.first);
  24. }
  25. };
  26. u32 canonical_combining_class(u32 code_point);
  27. // Note: The single code point case conversions only perform simple case folding.
  28. // Use the full-string transformations for full case folding.
  29. u32 to_unicode_lowercase(u32 code_point);
  30. u32 to_unicode_uppercase(u32 code_point);
  31. u32 to_unicode_titlecase(u32 code_point);
  32. template<typename ViewType>
  33. bool equals_ignoring_case(ViewType, ViewType);
  34. template<typename ViewType>
  35. Optional<size_t> find_ignoring_case(ViewType, ViewType);
  36. Optional<GeneralCategory> general_category_from_string(StringView);
  37. bool code_point_has_general_category(u32 code_point, GeneralCategory general_category);
  38. Optional<Property> property_from_string(StringView);
  39. bool code_point_has_property(u32 code_point, Property property);
  40. bool is_ecma262_property(Property);
  41. Optional<Script> script_from_string(StringView);
  42. bool code_point_has_script(u32 code_point, Script script);
  43. bool code_point_has_script_extension(u32 code_point, Script script);
  44. bool code_point_has_grapheme_break_property(u32 code_point, GraphemeBreakProperty property);
  45. bool code_point_has_word_break_property(u32 code_point, WordBreakProperty property);
  46. bool code_point_has_sentence_break_property(u32 code_point, SentenceBreakProperty property);
  47. Optional<BidirectionalClass> bidirectional_class_from_string(StringView);
  48. Optional<BidirectionalClass> bidirectional_class(u32 code_point);
  49. }