Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7bd5b4d

Browse files
authored
Merge pull request#16 from mbrubeck/as_str
Add as_str methods to iterator types
2 parentsb61677d +b96840c commit7bd5b4d

File tree

5 files changed

+93
-3
lines changed

5 files changed

+93
-3
lines changed

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name ="unicode-segmentation"
4-
version ="1.0.3"
4+
version ="1.1.0"
55
authors = ["kwantam <kwantam@gmail.com>"]
66

77
homepage ="https://github.com/unicode-rs/unicode-segmentation"

‎README.md‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,23 @@ to your `Cargo.toml`:
4040

4141
```toml
4242
[dependencies]
43-
unicode-segmentation ="1.0.2"
43+
unicode-segmentation ="1.1.0"
4444
```
45+
46+
#Change Log
47+
48+
##1.1.0
49+
50+
* Add`as_str` methods to the iterator types.
51+
52+
##1.0.3
53+
54+
* Code cleanup and additional tests.
55+
56+
##1.0.1
57+
58+
* Fix a bug affecting some grapheme clusters containing Prepend characters.
59+
60+
##1.0.0
61+
62+
* Upgrade to Unicode 9.0.0.

‎src/grapheme.rs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ pub struct GraphemeIndices<'a> {
1919
iter:Graphemes<'a>,
2020
}
2121

22+
impl<'a>GraphemeIndices<'a>{
23+
#[inline]
24+
/// View the underlying data (the part yet to be iterated) as a slice of the original string.
25+
///
26+
/// ```rust
27+
/// # use unicode_segmentation::UnicodeSegmentation;
28+
/// let mut iter = "abc".grapheme_indices(true);
29+
/// assert_eq!(iter.as_str(), "abc");
30+
/// iter.next();
31+
/// assert_eq!(iter.as_str(), "bc");
32+
/// iter.next();
33+
/// iter.next();
34+
/// assert_eq!(iter.as_str(), "");
35+
/// ```
36+
pubfnas_str(&self) ->&'astr{
37+
self.iter.as_str()
38+
}
39+
}
40+
2241
impl<'a>IteratorforGraphemeIndices<'a>{
2342
typeItem =(usize,&'astr);
2443

@@ -51,6 +70,25 @@ pub struct Graphemes<'a> {
5170
regional_count_back:Option<usize>,
5271
}
5372

73+
impl<'a>Graphemes<'a>{
74+
#[inline]
75+
/// View the underlying data (the part yet to be iterated) as a slice of the original string.
76+
///
77+
/// ```rust
78+
/// # use unicode_segmentation::UnicodeSegmentation;
79+
/// let mut iter = "abc".graphemes(true);
80+
/// assert_eq!(iter.as_str(), "abc");
81+
/// iter.next();
82+
/// assert_eq!(iter.as_str(), "bc");
83+
/// iter.next();
84+
/// iter.next();
85+
/// assert_eq!(iter.as_str(), "");
86+
/// ```
87+
pubfnas_str(&self) ->&'astr{
88+
self.string
89+
}
90+
}
91+
5492
// state machine for cluster boundary rules
5593
#[derive(Copy,Clone,PartialEq,Eq)]
5694
enumGraphemeState{

‎src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
//!
4747
//! ```toml
4848
//! [dependencies]
49-
//! unicode-segmentation = "1.0.2"
49+
//! unicode-segmentation = "1.1.0"
5050
//! ```
5151
5252
#![deny(missing_docs, unsafe_code)]

‎src/word.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ pub struct UWordBoundIndices<'a> {
5050
iter:UWordBounds<'a>,
5151
}
5252

53+
impl<'a>UWordBoundIndices<'a>{
54+
#[inline]
55+
/// View the underlying data (the part yet to be iterated) as a slice of the original string.
56+
///
57+
/// ```rust
58+
/// # use unicode_segmentation::UnicodeSegmentation;
59+
/// let mut iter = "Hello world".split_word_bound_indices();
60+
/// assert_eq!(iter.as_str(), "Hello world");
61+
/// iter.next();
62+
/// assert_eq!(iter.as_str(), " world");
63+
/// iter.next();
64+
/// assert_eq!(iter.as_str(), "world");
65+
/// ```
66+
pubfnas_str(&self) ->&'astr{
67+
self.iter.as_str()
68+
}
69+
}
70+
5371
impl<'a>IteratorforUWordBoundIndices<'a>{
5472
typeItem =(usize,&'astr);
5573

@@ -569,6 +587,22 @@ impl<'a> DoubleEndedIterator for UWordBounds<'a> {
569587
}
570588

571589
impl<'a>UWordBounds<'a>{
590+
#[inline]
591+
/// View the underlying data (the part yet to be iterated) as a slice of the original string.
592+
///
593+
/// ```rust
594+
/// # use unicode_segmentation::UnicodeSegmentation;
595+
/// let mut iter = "Hello world".split_word_bounds();
596+
/// assert_eq!(iter.as_str(), "Hello world");
597+
/// iter.next();
598+
/// assert_eq!(iter.as_str(), " world");
599+
/// iter.next();
600+
/// assert_eq!(iter.as_str(), "world");
601+
/// ```
602+
pubfnas_str(&self) ->&'astr{
603+
self.string
604+
}
605+
572606
#[inline]
573607
fnget_next_cat(&self,idx:usize) ->Option<WordCat>{
574608
use tables::wordas wd;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp