- Notifications
You must be signed in to change notification settings - Fork61
Unicode sentence boundaries#24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
4 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletionCargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletionsscripts/unicode.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletionsscripts/unicode_gen_breaktests.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
40 changes: 39 additions & 1 deletionsrc/lib.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -8,7 +8,7 @@ | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
//! Iterators which split strings on Grapheme Cluster, WordorSentence boundaries, according | ||
//! to the [Unicode Standard Annex #29](http://www.unicode.org/reports/tr29/) rules. | ||
//! | ||
//! ```rust | ||
@@ -67,10 +67,12 @@ pub use grapheme::{Graphemes, GraphemeIndices}; | ||
pub use grapheme::{GraphemeCursor, GraphemeIncomplete}; | ||
pub use tables::UNICODE_VERSION; | ||
pub use word::{UWordBounds, UWordBoundIndices, UnicodeWords}; | ||
pub use sentence::{USentenceBounds, USentenceBoundIndices, UnicodeSentences}; | ||
mod grapheme; | ||
mod tables; | ||
mod word; | ||
mod sentence; | ||
#[cfg(test)] | ||
mod test; | ||
@@ -174,6 +176,27 @@ pub trait UnicodeSegmentation { | ||
/// assert_eq!(&swi1[..], b); | ||
/// ``` | ||
fn split_word_bound_indices<'a>(&'a self) -> UWordBoundIndices<'a>; | ||
/// Returns an iterator over substrings of `self` separated on | ||
/// [UAX#29 sentence boundaries](http://www.unicode.org/reports/tr29/#Sentence_Boundaries). | ||
/// | ||
/// The concatenation of the substrings returned by this function is just the original string. | ||
fn unicode_sentences<'a>(&'a self) -> UnicodeSentences<'a>; | ||
/// Returns an iterator over substrings of `self` separated on | ||
/// [UAX#29 sentence boundaries](http://www.unicode.org/reports/tr29/#Sentence_Boundaries). | ||
/// | ||
/// Here, "sentences" are just those substrings which, after splitting on | ||
tomcumming marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
/// UAX#29 sentence boundaries, contain any alphanumeric characters. That is, the | ||
/// substring must contain at least one character with the | ||
/// [Alphabetic](http://unicode.org/reports/tr44/#Alphabetic) | ||
/// property, or with | ||
/// [General_Category=Number](http://unicode.org/reports/tr44/#General_Category_Values). | ||
fn split_sentence_bounds<'a>(&'a self) -> USentenceBounds<'a>; | ||
tomcumming marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
/// Returns an iterator over substrings of `self`, split on UAX#29 sentence boundaries, | ||
/// and their offsets. See `split_sentence_bounds()` for more information. | ||
fn split_sentence_bound_indices<'a>(&'a self) -> USentenceBoundIndices<'a>; | ||
} | ||
impl UnicodeSegmentation for str { | ||
@@ -201,4 +224,19 @@ impl UnicodeSegmentation for str { | ||
fn split_word_bound_indices(&self) -> UWordBoundIndices { | ||
word::new_word_bound_indices(self) | ||
} | ||
#[inline] | ||
fn unicode_sentences(&self) -> UnicodeSentences { | ||
sentence::new_unicode_sentences(self) | ||
} | ||
#[inline] | ||
fn split_sentence_bounds(&self) -> USentenceBounds { | ||
sentence::new_sentence_bounds(self) | ||
} | ||
#[inline] | ||
fn split_sentence_bound_indices(&self) -> USentenceBoundIndices { | ||
sentence::new_sentence_bound_indices(self) | ||
} | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.