/* * Copyright (c) 2022, Idan Horowitz * Copyright (c) 2023, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Unicode { using SegmentationCallback = Function; void for_each_grapheme_segmentation_boundary(Utf8View const&, SegmentationCallback); void for_each_grapheme_segmentation_boundary(Utf16View const&, SegmentationCallback); void for_each_grapheme_segmentation_boundary(Utf32View const&, SegmentationCallback); template Vector find_grapheme_segmentation_boundaries(ViewType const& view) { Vector boundaries; for_each_grapheme_segmentation_boundary(view, [&](auto boundary) { boundaries.append(boundary); return IterationDecision::Continue; }); return boundaries; } void for_each_word_segmentation_boundary(Utf8View const&, SegmentationCallback); void for_each_word_segmentation_boundary(Utf16View const&, SegmentationCallback); void for_each_word_segmentation_boundary(Utf32View const&, SegmentationCallback); template Vector find_word_segmentation_boundaries(ViewType const& view) { Vector boundaries; for_each_word_segmentation_boundary(view, [&](auto boundary) { boundaries.append(boundary); return IterationDecision::Continue; }); return boundaries; } void for_each_sentence_segmentation_boundary(Utf8View const&, SegmentationCallback); void for_each_sentence_segmentation_boundary(Utf16View const&, SegmentationCallback); void for_each_sentence_segmentation_boundary(Utf32View const&, SegmentationCallback); template Vector find_sentence_segmentation_boundaries(ViewType const& view) { Vector boundaries; for_each_sentence_segmentation_boundary(view, [&](auto boundary) { boundaries.append(boundary); return IterationDecision::Continue; }); return boundaries; } }