@@ -155,9 +155,7 @@ pub fn from_chars(chs: &[char]) -> ~str {
155
155
buf
156
156
}
157
157
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) ]
161
159
pub fn push_str ( lhs : & mut ~str , rhs : & str ) {
162
160
lhs. push_str ( rhs)
163
161
}
@@ -1604,25 +1602,9 @@ pub trait StrSlice<'self> {
1604
1602
fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> StrCharSplitIterator<'self, Sep>;
1605
1603
fn split_options_iter<Sep: CharEq>(&self, sep: Sep, count: uint, allow_trailing_empty: bool)
1606
1604
-> StrCharSplitIterator<'self, Sep>;
1607
- /// An iterator over the start and end indices of each match of
1608
- /// `sep` within `self`.
1609
1605
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
- */
1620
1606
fn split_str_iter(&self, &'self str) -> StrStrSplitIterator<'self>;
1621
- /// An iterator over the lines of a string (subsequences separated
1622
- /// by `\n `).
1623
1607
fn line_iter(&self) -> StrCharSplitIterator<'self, char>;
1624
- /// An iterator over the words of a string (subsequences separated
1625
- /// by any sequence of whitespace).
1626
1608
fn word_iter(&self) -> WordIterator<'self>;
1627
1609
fn ends_with(&self, needle: &str) -> bool;
1628
1610
fn is_empty(&self) -> bool;
@@ -1681,14 +1663,23 @@ impl<'self> StrSlice<'self> for &'self str {
1681
1663
fn contains_char(&self, needle: char) -> bool {
1682
1664
self.find(needle).is_some()
1683
1665
}
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
+ /// ~~~
1685
1675
#[inline]
1686
1676
fn iter(&self) -> StrCharIterator<'self> {
1687
1677
StrCharIterator {
1688
1678
index: 0,
1689
1679
string: *self
1690
1680
}
1691
1681
}
1682
+ /// An iterator over the characters of `self`, in reverse order.
1692
1683
#[inline]
1693
1684
fn rev_iter(&self) -> StrCharRevIterator<'self> {
1694
1685
StrCharRevIterator {
@@ -1697,20 +1688,47 @@ impl<'self> StrSlice<'self> for &'self str {
1697
1688
}
1698
1689
}
1699
1690
1691
+ /// An iterator over the bytes of `self`
1692
+ #[inline]
1700
1693
fn bytes_iter(&self) -> StrBytesIterator<'self> {
1701
1694
StrBytesIterator { it: as_bytes_slice(*self).iter() }
1702
1695
}
1696
+ /// An iterator over the bytes of `self`, in reverse order
1697
+ #[inline]
1703
1698
fn bytes_rev_iter(&self) -> StrBytesRevIterator<'self> {
1704
1699
StrBytesRevIterator { it: as_bytes_slice(*self).rev_iter() }
1705
1700
}
1706
1701
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]
1707
1715
fn split_iter<Sep: CharEq>(&self, sep: Sep) -> StrCharSplitIterator<'self, Sep> {
1708
1716
self.split_options_iter(sep, self.len(), true)
1709
1717
}
1710
1718
1719
+ /// An iterator over substrings of `self`, separated by characters
1720
+ /// matched by `sep`, restricted to splitting at most `count`
1721
+ /// times.
1722
+ #[inline]
1711
1723
fn splitn_iter<Sep: CharEq>(&self, sep: Sep, count: uint) -> StrCharSplitIterator<'self, Sep> {
1712
1724
self.split_options_iter(sep, count, true)
1713
1725
}
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]
1714
1732
fn split_options_iter<Sep: CharEq>(&self, sep: Sep, count: uint, allow_trailing_empty: bool)
1715
1733
-> StrCharSplitIterator<'self, Sep> {
1716
1734
let only_ascii = sep.only_ascii();
@@ -1724,6 +1742,9 @@ impl<'self> StrSlice<'self> for &'self str {
1724
1742
only_ascii: only_ascii
1725
1743
}
1726
1744
}
1745
+ /// An iterator over the start and end indices of each match of
1746
+ /// `sep` within `self`.
1747
+ #[inline]
1727
1748
fn matches_index_iter(&self, sep: &'self str) -> StrMatchesIndexIterator<'self> {
1728
1749
assert!(!sep.is_empty())
1729
1750
StrMatchesIndexIterator {
@@ -1732,6 +1753,17 @@ impl<'self> StrSlice<'self> for &'self str {
1732
1753
position: 0
1733
1754
}
1734
1755
}
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]
1735
1767
fn split_str_iter(&self, sep: &'self str) -> StrStrSplitIterator<'self> {
1736
1768
StrStrSplitIterator {
1737
1769
it: self.matches_index_iter(sep),
@@ -1740,9 +1772,15 @@ impl<'self> StrSlice<'self> for &'self str {
1740
1772
}
1741
1773
}
1742
1774
1775
+ /// An iterator over the lines of a string (subsequences separated
1776
+ /// by `\n `).
1777
+ #[inline]
1743
1778
fn line_iter(&self) -> StrCharSplitIterator<'self, char> {
1744
1779
self.split_options_iter('\n ', self.len(), false)
1745
1780
}
1781
+ /// An iterator over the words of a string (subsequences separated
1782
+ /// by any sequence of whitespace).
1783
+ #[inline]
1746
1784
fn word_iter(&self) -> WordIterator<'self> {
1747
1785
self.split_iter(char::is_whitespace).filter(|s| !s.is_empty())
1748
1786
}
@@ -1791,14 +1829,24 @@ impl<'self> StrSlice<'self> for &'self str {
1791
1829
assert!(self.is_char_boundary(end));
1792
1830
unsafe { raw::slice_bytes(*self, begin, end) }
1793
1831
}
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.
1794
1836
#[inline]
1795
1837
fn slice_from(&self, begin: uint) -> &'self str {
1796
1838
self.slice(begin, self.len())
1797
1839
}
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.
1798
1845
#[inline]
1799
1846
fn slice_to(&self, end: uint) -> &'self str {
1800
1847
self.slice(0, end)
1801
1848
}
1849
+ /// Checks if `needle` is a prefix of the string.
1802
1850
#[inline]
1803
1851
fn starts_with<'a>(&self, needle: &'a str) -> bool {
1804
1852
starts_with(*self, needle)
0 commit comments