LibWeb: Port text segmentation to the ICU text segmenter

This commit is contained in:
Timothy Flynn 2024-06-19 09:02:21 -04:00 committed by Andreas Kling
commit 12f177e9e9
Notes: sideshowbarker 2024-07-17 03:27:40 +09:00
5 changed files with 40 additions and 20 deletions

View file

@ -6,7 +6,7 @@
*/
#include <AK/Utf8View.h>
#include <LibUnicode/Segmentation.h>
#include <LibLocale/Segmenter.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/Position.h>
#include <LibWeb/DOM/Text.h>
@ -40,9 +40,8 @@ bool Position::increment_offset()
return false;
auto& node = verify_cast<DOM::Text>(*m_node);
auto text = Utf8View(node.data());
if (auto offset = Unicode::next_grapheme_segmentation_boundary(text, m_offset); offset.has_value()) {
if (auto offset = node.segmenter().next_boundary(m_offset); offset.has_value()) {
m_offset = *offset;
return true;
}
@ -57,9 +56,8 @@ bool Position::decrement_offset()
return false;
auto& node = verify_cast<DOM::Text>(*m_node);
auto text = Utf8View(node.data());
if (auto offset = Unicode::previous_grapheme_segmentation_boundary(text, m_offset); offset.has_value()) {
if (auto offset = node.segmenter().previous_boundary(m_offset); offset.has_value()) {
m_offset = *offset;
return true;
}