LibWeb: Rename CharacterData's segmenter indicate it is for graphemes

We will be adding a word segmenter as well, so this is to disambiguate
the two.

(cherry picked from commit eece7697fdcaf50eed98fff069c5e678ac425784;
amended to fix conflict due to Serenity's Segmenter still being in
LibLocale, while upstream combined LibLocale and LibUnicode)
This commit is contained in:
Timothy Flynn authored and Nico Weber committed 2024-11-26 16:03:32 -05:00
1 parent f1ad3f7969
commit d4c5942664
4 files changed
+12 -12

No files matched your search

@@ -128,8 +128,8 @@ WebIDL::ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t coun
document().set_needs_layout();
if (m_segmenter)
m_segmenter->set_segmented_text(m_data);
if (m_grapheme_segmenter)
m_grapheme_segmenter->set_segmented_text(m_data);
return {};
}
@@ -155,14 +155,14 @@ WebIDL::ExceptionOr<void> CharacterData::delete_data(size_t offset, size_t count
return replace_data(offset, count, String {});
}
Locale::Segmenter& CharacterData::segmenter()
Locale::Segmenter& CharacterData::grapheme_segmenter()
{
if (!m_segmenter) {
m_segmenter = Locale::Segmenter::create(Locale::SegmenterGranularity::Grapheme);
m_segmenter->set_segmented_text(m_data);
if (!m_grapheme_segmenter) {
m_grapheme_segmenter = Locale::Segmenter::create(Locale::SegmenterGranularity::Grapheme);
m_grapheme_segmenter->set_segmented_text(m_data);
}
return *m_segmenter;
return *m_grapheme_segmenter;
}
}
@@ -40,7 +40,7 @@ public:
WebIDL::ExceptionOr<void> delete_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units);
WebIDL::ExceptionOr<void> replace_data(size_t offset_in_utf16_code_units, size_t count_in_utf16_code_units, String const&);
Locale::Segmenter& segmenter();
Locale::Segmenter& grapheme_segmenter();
protected:
CharacterData(Document&, NodeType, String const&);
@@ -50,7 +50,7 @@ protected:
private:
String m_data;
OwnPtr<Locale::Segmenter> m_segmenter;
OwnPtr<Locale::Segmenter> m_grapheme_segmenter;
};
}
+2 -2
View File
@@ -41,7 +41,7 @@ bool Position::increment_offset()
auto& node = verify_cast<DOM::Text>(*m_node);
if (auto offset = node.segmenter().next_boundary(m_offset); offset.has_value()) {
if (auto offset = node.grapheme_segmenter().next_boundary(m_offset); offset.has_value()) {
m_offset = *offset;
return true;
}
@@ -57,7 +57,7 @@ bool Position::decrement_offset()
auto& node = verify_cast<DOM::Text>(*m_node);
if (auto offset = node.segmenter().previous_boundary(m_offset); offset.has_value()) {
if (auto offset = node.grapheme_segmenter().previous_boundary(m_offset); offset.has_value()) {
m_offset = *offset;
return true;
}
@@ -22,7 +22,7 @@ void EditEventHandler::handle_delete_character_after(JS::NonnullGCPtr<DOM::Docum
auto& node = verify_cast<DOM::Text>(*cursor_position->node());
auto& text = node.data();
auto next_offset = node.segmenter().next_boundary(cursor_position->offset());
auto next_offset = node.grapheme_segmenter().next_boundary(cursor_position->offset());
if (!next_offset.has_value()) {
// FIXME: Move to the next node and delete the first character there.
return;