Skip to content

Commit c339314

Browse files
committed
---
yaml --- r: 63170 b: refs/heads/snap-stage3 c: 8c59d92 h: refs/heads/master v: v3
1 parent 1f2f9fa commit c339314

File tree

2 files changed

+69
-21
lines changed

2 files changed

+69
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ccd0ac59e9a918f3c2a174e31213286dc6867d37
4+
refs/heads/snap-stage3: 8c59d920a12fe40398a0033438ff426bb3387fd0
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/str.rs

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ pub fn from_chars(chs: &[char]) -> ~str {
155155
buf
156156
}
157157

158-
/// A function version of the `.push_str`, required for `fmt!` during
159-
/// the bootstrap. Use `lhs.push_str(rhs)` instead of this.
160-
#[doc="hidden"]
158+
#[doc(hidden)]
161159
pub fn push_str(lhs: &mut ~str, rhs: &str) {
162160
lhs.push_str(rhs)
163161
}
@@ -1604,25 +1602,9 @@ pub trait StrSlice<'self> {
16041602
fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> StrCharSplitIterator<'self, Sep>;
16051603
fn split_options_iter<Sep: CharEq>(&self, sep: Sep, count: uint, allow_trailing_empty: bool)
16061604
-> StrCharSplitIterator<'self, Sep>;
1607-
/// An iterator over the start and end indices of each match of
1608-
/// `sep` within `self`.
16091605
fn matches_index_iter(&self, sep: &'self str) -> StrMatchesIndexIterator<'self>;
1610-
/**
1611-
* An iterator over the substrings of `self` separated by `sep`.
1612-
*
1613-
* # Example
1614-
*
1615-
* ~~~ {.rust}
1616-
* let v: ~[&str] = ".XXX.YYY.".split_str_iter(".").collect()
1617-
* assert_eq!(v, ["", "XXX", "YYY", ""]);
1618-
* ~~~
1619-
*/
16201606
fn split_str_iter(&self, &'self str) -> StrStrSplitIterator<'self>;
1621-
/// An iterator over the lines of a string (subsequences separated
1622-
/// by `\n`).
16231607
fn line_iter(&self) -> StrCharSplitIterator<'self, char>;
1624-
/// An iterator over the words of a string (subsequences separated
1625-
/// by any sequence of whitespace).
16261608
fn word_iter(&self) -> WordIterator<'self>;
16271609
fn ends_with(&self, needle: &str) -> bool;
16281610
fn is_empty(&self) -> bool;
@@ -1681,14 +1663,23 @@ impl<'self> StrSlice<'self> for &'self str {
16811663
fn contains_char(&self, needle: char) -> bool {
16821664
self.find(needle).is_some()
16831665
}
1684-
1666+
/// An iterator over the characters of `self`. Note, this iterates
1667+
/// over unicode code-points, not unicode graphemes.
1668+
///
1669+
/// # Example
1670+
///
1671+
/// ~~~ {.rust}
1672+
/// let v: ~[char] = "abc åäö".iter().collect();
1673+
/// assert_eq!(v, ~['a', 'b', 'c', ' ', 'å', 'ä', 'ö']);
1674+
/// ~~~
16851675
#[inline]
16861676
fn iter(&self) -> StrCharIterator<'self> {
16871677
StrCharIterator {
16881678
index: 0,
16891679
string: *self
16901680
}
16911681
}
1682+
/// An iterator over the characters of `self`, in reverse order.
16921683
#[inline]
16931684
fn rev_iter(&self) -> StrCharRevIterator<'self> {
16941685
StrCharRevIterator {
@@ -1697,20 +1688,47 @@ impl<'self> StrSlice<'self> for &'self str {
16971688
}
16981689
}
16991690
1691+
/// An iterator over the bytes of `self`
1692+
#[inline]
17001693
fn bytes_iter(&self) -> StrBytesIterator<'self> {
17011694
StrBytesIterator { it: as_bytes_slice(*self).iter() }
17021695
}
1696+
/// An iterator over the bytes of `self`, in reverse order
1697+
#[inline]
17031698
fn bytes_rev_iter(&self) -> StrBytesRevIterator<'self> {
17041699
StrBytesRevIterator { it: as_bytes_slice(*self).rev_iter() }
17051700
}
17061701
1702+
/// An iterator over substrings of `self`, separated by characters
1703+
/// matched by `sep`.
1704+
///
1705+
/// # Example
1706+
///
1707+
/// ~~~ {.rust}
1708+
/// let v: ~[&str] = "Mary had a little lamb".split_iter(' ').collect();
1709+
/// assert_eq!(v, ~["Mary", "had", "a", "little", "lamb"]);
1710+
///
1711+
/// let v: ~[&str] = "abc1def2ghi".split_iter(|c: char| c.is_digit()).collect();
1712+
/// assert_eq!(v, ~["abc", "def", "ghi"]);
1713+
/// ~~~
1714+
#[inline]
17071715
fn split_iter<Sep: CharEq>(&self, sep: Sep) -> StrCharSplitIterator<'self, Sep> {
17081716
self.split_options_iter(sep, self.len(), true)
17091717
}
17101718
1719+
/// An iterator over substrings of `self`, separated by characters
1720+
/// matched by `sep`, restricted to splitting at most `count`
1721+
/// times.
1722+
#[inline]
17111723
fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> StrCharSplitIterator<'self, Sep> {
17121724
self.split_options_iter(sep, count, true)
17131725
}
1726+
1727+
/// An iterator over substrings of `self`, separated by characters
1728+
/// matched by `sep`, splitting at most `count` times, and
1729+
/// possibly not including the trailing empty substring, if it
1730+
/// exists.
1731+
#[inline]
17141732
fn split_options_iter<Sep: CharEq>(&self, sep: Sep, count: uint, allow_trailing_empty: bool)
17151733
-> StrCharSplitIterator<'self, Sep> {
17161734
let only_ascii = sep.only_ascii();
@@ -1724,6 +1742,9 @@ impl<'self> StrSlice<'self> for &'self str {
17241742
only_ascii: only_ascii
17251743
}
17261744
}
1745+
/// An iterator over the start and end indices of each match of
1746+
/// `sep` within `self`.
1747+
#[inline]
17271748
fn matches_index_iter(&self, sep: &'self str) -> StrMatchesIndexIterator<'self> {
17281749
assert!(!sep.is_empty())
17291750
StrMatchesIndexIterator {
@@ -1732,6 +1753,17 @@ impl<'self> StrSlice<'self> for &'self str {
17321753
position: 0
17331754
}
17341755
}
1756+
/**
1757+
* An iterator over the substrings of `self` separated by `sep`.
1758+
*
1759+
* # Example
1760+
*
1761+
* ~~~ {.rust}
1762+
* let v: ~[&str] = "abcXXXabcYYYabc".split_str_iter("abc").collect()
1763+
* assert_eq!(v, ["", "XXX", "YYY", ""]);
1764+
* ~~~
1765+
*/
1766+
#[inline]
17351767
fn split_str_iter(&self, sep: &'self str) -> StrStrSplitIterator<'self> {
17361768
StrStrSplitIterator {
17371769
it: self.matches_index_iter(sep),
@@ -1740,9 +1772,15 @@ impl<'self> StrSlice<'self> for &'self str {
17401772
}
17411773
}
17421774
1775+
/// An iterator over the lines of a string (subsequences separated
1776+
/// by `\n`).
1777+
#[inline]
17431778
fn line_iter(&self) -> StrCharSplitIterator<'self, char> {
17441779
self.split_options_iter('\n', self.len(), false)
17451780
}
1781+
/// An iterator over the words of a string (subsequences separated
1782+
/// by any sequence of whitespace).
1783+
#[inline]
17461784
fn word_iter(&self) -> WordIterator<'self> {
17471785
self.split_iter(char::is_whitespace).filter(|s| !s.is_empty())
17481786
}
@@ -1791,14 +1829,24 @@ impl<'self> StrSlice<'self> for &'self str {
17911829
assert!(self.is_char_boundary(end));
17921830
unsafe { raw::slice_bytes(*self, begin, end) }
17931831
}
1832+
/// Returns a slice of the string from `begin` to its end.
1833+
///
1834+
/// Fails when `begin` does not point to a valid character, or is
1835+
/// out of bounds.
17941836
#[inline]
17951837
fn slice_from(&self, begin: uint) -> &'self str {
17961838
self.slice(begin, self.len())
17971839
}
1840+
/// Returns a slice of the string from the beginning to byte
1841+
/// `end`.
1842+
///
1843+
/// Fails when `end` does not point to a valid character, or is
1844+
/// out of bounds.
17981845
#[inline]
17991846
fn slice_to(&self, end: uint) -> &'self str {
18001847
self.slice(0, end)
18011848
}
1849+
/// Checks if `needle` is a prefix of the string.
18021850
#[inline]
18031851
fn starts_with<'a>(&self, needle: &'a str) -> bool {
18041852
starts_with(*self, needle)

0 commit comments

Comments
 (0)