Segmenter.h 1.3 KB

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