1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
//! Segment strings by lines, graphemes, words, and sentences.
//!
//! This module is published as its own crate ([`icu_segmenter`](https://docs.rs/icu_segmenter/latest/icu_segmenter/))
//! and as part of the [`icu`](https://docs.rs/icu/latest/icu/) crate. See the latter for more details on the ICU4X project.
//!
//! This module contains segmenter implementation for the following rules.
//!
//! - Line segmenter that is compatible with [Unicode Standard Annex #14][UAX14], _Unicode Line
//! Breaking Algorithm_, with options to tailor line-breaking behavior for CSS [`line-break`] and
//! [`word-break`] properties.
//! - Grapheme cluster segmenter, word segmenter, and sentence segmenter that are compatible with
//! [Unicode Standard Annex #29][UAX29], _Unicode Text Segmentation_.
//!
//! [UAX14]: https://www.unicode.org/reports/tr14/
//! [UAX29]: https://www.unicode.org/reports/tr29/
//! [`line-break`]: https://drafts.csswg.org/css-text-3/#line-break-property
//! [`word-break`]: https://drafts.csswg.org/css-text-3/#word-break-property
//!
//! # Examples
//!
//! ## Line Break
//!
//! Find line break opportunities:
//!
//!```rust
//! use icu::segmenter::LineSegmenter;
//!
//! let segmenter = LineSegmenter::new_auto();
//!
//! let breakpoints: Vec<usize> = segmenter
//! .segment_str("Hello World. Xin chào thế giới!")
//! .collect();
//! assert_eq!(&breakpoints, &[0, 6, 13, 17, 23, 29, 36]);
//! ```
//!
//! See [`LineSegmenter`] for more examples.
//!
//! ## Grapheme Cluster Break
//!
//! Find all grapheme cluster boundaries:
//!
//!```rust
//! use icu::segmenter::GraphemeClusterSegmenter;
//!
//! let segmenter = GraphemeClusterSegmenter::new();
//!
//! let breakpoints: Vec<usize> = segmenter
//! .segment_str("Hello World. Xin chào thế giới!")
//! .collect();
//! assert_eq!(
//! &breakpoints,
//! &[
//! 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
//! 19, 21, 22, 23, 24, 25, 28, 29, 30, 31, 34, 35, 36
//! ]
//! );
//! ```
//!
//! See [`GraphemeClusterSegmenter`] for more examples.
//!
//! ## Word Break
//!
//! Find all word boundaries:
//!
//!```rust
//! use icu::segmenter::WordSegmenter;
//!
//! let segmenter = WordSegmenter::new_auto();
//!
//! let breakpoints: Vec<usize> = segmenter
//! .segment_str("Hello World. Xin chào thế giới!")
//! .collect();
//! assert_eq!(
//! &breakpoints,
//! &[0, 5, 6, 11, 12, 13, 16, 17, 22, 23, 28, 29, 35, 36]
//! );
//! ```
//!
//! See [`WordSegmenter`] for more examples.
//!
//! ## Sentence Break
//!
//! Segment the string into sentences:
//!
//!```rust
//! use icu::segmenter::SentenceSegmenter;
//!
//! let segmenter = SentenceSegmenter::new();
//!
//! let breakpoints: Vec<usize> = segmenter
//! .segment_str("Hello World. Xin chào thế giới!")
//! .collect();
//! assert_eq!(&breakpoints, &[0, 13, 36]);
//! ```
//!
//! See [`SentenceSegmenter`] for more examples.
// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(
not(test),
deny(
clippy::indexing_slicing,
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::exhaustive_structs,
clippy::exhaustive_enums,
missing_debug_implementations,
)
)]
#![warn(missing_docs)]
extern crate alloc;
mod complex;
mod error;
mod indices;
mod iterator_helpers;
mod rule_segmenter;
mod grapheme;
mod line;
mod sentence;
mod word;
pub mod provider;
// Main Segmenter and BreakIterator public types
pub use crate::grapheme::GraphemeClusterBreakIterator;
pub use crate::grapheme::GraphemeClusterSegmenter;
pub use crate::line::LineBreakIterator;
pub use crate::line::LineSegmenter;
pub use crate::sentence::SentenceBreakIterator;
pub use crate::sentence::SentenceSegmenter;
pub use crate::word::WordBreakIterator;
pub use crate::word::WordSegmenter;
// Options structs and enums
pub use crate::line::LineBreakOptions;
pub use crate::line::LineBreakStrictness;
pub use crate::line::LineBreakWordOption;
pub use crate::word::WordType;
// Typedefs
pub use crate::grapheme::GraphemeClusterBreakIteratorLatin1;
pub use crate::grapheme::GraphemeClusterBreakIteratorPotentiallyIllFormedUtf8;
pub use crate::grapheme::GraphemeClusterBreakIteratorUtf16;
pub use crate::grapheme::GraphemeClusterBreakIteratorUtf8;
pub use crate::line::LineBreakIteratorLatin1;
pub use crate::line::LineBreakIteratorPotentiallyIllFormedUtf8;
pub use crate::line::LineBreakIteratorUtf16;
pub use crate::line::LineBreakIteratorUtf8;
pub use crate::sentence::SentenceBreakIteratorLatin1;
pub use crate::sentence::SentenceBreakIteratorPotentiallyIllFormedUtf8;
pub use crate::sentence::SentenceBreakIteratorUtf16;
pub use crate::sentence::SentenceBreakIteratorUtf8;
pub use crate::word::WordBreakIteratorLatin1;
pub use crate::word::WordBreakIteratorPotentiallyIllFormedUtf8;
pub use crate::word::WordBreakIteratorUtf16;
pub use crate::word::WordBreakIteratorUtf8;
pub use error::SegmenterError;
#[doc(no_inline)]
pub use SegmenterError as Error;