mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-05 09:06:08 +00:00
LibLine: Port text segmentation to the ICU text segmenter
This commit is contained in:
parent
12f177e9e9
commit
3974996e95
Notes:
sideshowbarker
2024-07-17 08:59:18 +09:00
Author: https://github.com/trflynn89
Commit: 3974996e95
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/218
2 changed files with 5 additions and 9 deletions
|
@ -7,4 +7,4 @@ set(SOURCES
|
||||||
)
|
)
|
||||||
|
|
||||||
serenity_lib(LibLine line)
|
serenity_lib(LibLine line)
|
||||||
target_link_libraries(LibLine PRIVATE LibCore LibUnicode)
|
target_link_libraries(LibLine PRIVATE LibCore LibLocale)
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include <LibCore/Event.h>
|
#include <LibCore/Event.h>
|
||||||
#include <LibCore/EventLoop.h>
|
#include <LibCore/EventLoop.h>
|
||||||
#include <LibCore/Notifier.h>
|
#include <LibCore/Notifier.h>
|
||||||
#include <LibUnicode/Segmentation.h>
|
#include <LibLocale/Segmenter.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
@ -1916,8 +1916,10 @@ StringMetrics Editor::actual_rendered_string_metrics(Utf32View const& view, RedB
|
||||||
|
|
||||||
auto mask_it = masks.begin();
|
auto mask_it = masks.begin();
|
||||||
|
|
||||||
|
auto segmenter = Locale::Segmenter::create(Locale::SegmenterGranularity::Grapheme);
|
||||||
Vector<size_t> grapheme_breaks;
|
Vector<size_t> grapheme_breaks;
|
||||||
Unicode::for_each_grapheme_segmentation_boundary(view, [&](size_t offset) -> IterationDecision {
|
|
||||||
|
segmenter->for_each_boundary(view, [&](size_t offset) -> IterationDecision {
|
||||||
if (offset >= view.length())
|
if (offset >= view.length())
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
|
|
||||||
|
@ -1925,12 +1927,6 @@ StringMetrics Editor::actual_rendered_string_metrics(Utf32View const& view, RedB
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
|
||||||
// In case Unicode data isn't available, default to using code points as grapheme boundaries.
|
|
||||||
if (grapheme_breaks.is_empty()) {
|
|
||||||
for (size_t i = 0; i < view.length(); ++i)
|
|
||||||
grapheme_breaks.append(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t break_index = 0; break_index < grapheme_breaks.size(); ++break_index) {
|
for (size_t break_index = 0; break_index < grapheme_breaks.size(); ++break_index) {
|
||||||
auto i = grapheme_breaks[break_index];
|
auto i = grapheme_breaks[break_index];
|
||||||
auto c = view[i];
|
auto c = view[i];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue