Segmenter.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
  3. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/String.h>
  9. #include <LibJS/Runtime/Object.h>
  10. namespace JS::Intl {
  11. class Segmenter final : public Object {
  12. JS_OBJECT(Segmenter, Object);
  13. public:
  14. enum class SegmenterGranularity {
  15. Grapheme,
  16. Word,
  17. Sentence,
  18. };
  19. virtual ~Segmenter() override = default;
  20. String const& locale() const { return m_locale; }
  21. void set_locale(String locale) { m_locale = move(locale); }
  22. SegmenterGranularity segmenter_granularity() const { return m_segmenter_granularity; }
  23. void set_segmenter_granularity(StringView);
  24. StringView segmenter_granularity_string() const;
  25. private:
  26. explicit Segmenter(Object& prototype);
  27. String m_locale; // [[Locale]]
  28. SegmenterGranularity m_segmenter_granularity { SegmenterGranularity::Grapheme }; // [[SegmenterGranularity]]
  29. };
  30. ThrowCompletionOr<NonnullGCPtr<Object>> create_segment_data_object(VM&, Segmenter const&, Utf16View const&, double start_index, double end_index);
  31. enum class Direction {
  32. Before,
  33. After,
  34. };
  35. double find_boundary(Segmenter const&, Utf16View const&, double start_index, Direction);
  36. }