/* * 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 Optional next_grapheme_segmentation_boundary(ViewType const& view, size_t index) { Optional result; for_each_grapheme_segmentation_boundary(view, [&](auto boundary) { if (boundary > index) { result = boundary; return IterationDecision::Break; } return IterationDecision::Continue; }); return result; } template Optional previous_grapheme_segmentation_boundary(ViewType const& view, size_t index) { Optional result; for_each_grapheme_segmentation_boundary(view, [&](auto boundary) { if (boundary < index) { result = boundary; return IterationDecision::Continue; } return IterationDecision::Break; }); return result; } 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 Optional next_word_segmentation_boundary(ViewType const& view, size_t index) { Optional result; for_each_word_segmentation_boundary(view, [&](auto boundary) { if (boundary > index) { result = boundary; return IterationDecision::Break; } return IterationDecision::Continue; }); return result; } template Optional previous_word_segmentation_boundary(ViewType const& view, size_t index) { Optional result; for_each_word_segmentation_boundary(view, [&](auto boundary) { if (boundary < index) { result = boundary; return IterationDecision::Continue; } return IterationDecision::Break; }); return result; } 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 Optional next_sentence_segmentation_boundary(ViewType const& view, size_t index) { Optional result; for_each_sentence_segmentation_boundary(view, [&](auto boundary) { if (boundary > index) { result = boundary; return IterationDecision::Break; } return IterationDecision::Continue; }); return result; } template Optional previous_sentence_segmentation_boundary(ViewType const& view, size_t index) { Optional result; for_each_sentence_segmentation_boundary(view, [&](auto boundary) { if (boundary < index) { result = boundary; return IterationDecision::Continue; } return IterationDecision::Break; }); return result; } }