|
95 | 95 | reserve_at_least,
|
96 | 96 | capacity,
|
97 | 97 |
|
98 |
| - unsafe; |
| 98 | + unsafe, |
| 99 | + extensions; |
99 | 100 |
|
100 | 101 | #[abi = "cdecl"]
|
101 | 102 | native mod rustrt {
|
@@ -1730,6 +1731,88 @@ mod unsafe {
|
1730 | 1731 | }
|
1731 | 1732 | }
|
1732 | 1733 |
|
| 1734 | +#[doc = "Extension methods for strings"] |
| 1735 | +impl extensions for str { |
| 1736 | + #[doc = " |
| 1737 | + Return true if a predicate matches all characters or if the string |
| 1738 | + contains no characters |
| 1739 | + "] |
| 1740 | + #[inline] |
| 1741 | + fn all(it: fn(char) -> bool) -> bool { all(self, it) } |
| 1742 | + #[doc = " |
| 1743 | + Return true if a predicate matches any character (and false if it |
| 1744 | + matches none or there are no characters) |
| 1745 | + "] |
| 1746 | + #[inline] |
| 1747 | + fn any(it: fn(char) -> bool) -> bool { any(self, it) } |
| 1748 | + #[doc = "Returns true if one string contains another"] |
| 1749 | + #[inline] |
| 1750 | + fn contains(needle: str) -> bool { contains(self, needle) } |
| 1751 | + #[doc = "Returns true if one string ends with another"] |
| 1752 | + #[inline] |
| 1753 | + fn ends_with(needle: str) -> bool { ends_with(self, needle) } |
| 1754 | + #[doc = "Returns true if the string has length 0"] |
| 1755 | + #[inline] |
| 1756 | + fn is_empty() -> bool { is_empty(self) } |
| 1757 | + #[doc = "Returns true if the string has length greater than 0"] |
| 1758 | + #[inline] |
| 1759 | + fn is_not_empty() -> bool { is_not_empty(self) } |
| 1760 | + #[doc = " |
| 1761 | + Returns true if the string contains only whitespace |
| 1762 | +
|
| 1763 | + Whitespace characters are determined by `char::is_whitespace` |
| 1764 | + "] |
| 1765 | + #[inline] |
| 1766 | + fn is_whitespace() -> bool { is_whitespace(self) } |
| 1767 | + #[doc = " |
| 1768 | + Returns a slice of the given string from the byte range [`begin`..`end`) |
| 1769 | +
|
| 1770 | + Fails when `begin` and `end` do not point to valid characters or |
| 1771 | + beyond the last character of the string |
| 1772 | + "] |
| 1773 | + #[inline] |
| 1774 | + fn slice(begin: uint, end: uint) -> str { slice(self, begin, end) } |
| 1775 | + #[doc = "Splits a string into substrings using a character function"] |
| 1776 | + #[inline] |
| 1777 | + fn split(sepfn: fn(char) -> bool) -> [str] { split(self, sepfn) } |
| 1778 | + #[doc = " |
| 1779 | + Splits a string into substrings at each occurrence of a given character |
| 1780 | + "] |
| 1781 | + #[inline] |
| 1782 | + fn split_char(sep: char) -> [str] { split_char(self, sep) } |
| 1783 | + #[doc = " |
| 1784 | + Splits a string into a vector of the substrings separated by a given |
| 1785 | + string |
| 1786 | + "] |
| 1787 | + #[inline] |
| 1788 | + fn split_str(sep: str) -> [str] { split_str(self, sep) } |
| 1789 | + #[doc = "Returns true if one string starts with another"] |
| 1790 | + #[inline] |
| 1791 | + fn starts_with(needle: str) -> bool { starts_with(self, needle) } |
| 1792 | + #[doc = " |
| 1793 | + Take a substring of another. |
| 1794 | +
|
| 1795 | + Returns a string containing `n` characters starting at byte offset |
| 1796 | + `begin`. |
| 1797 | + "] |
| 1798 | + #[inline] |
| 1799 | + fn substr(begin: uint, n: uint) -> str { substr(self, begin, n) } |
| 1800 | + #[doc = "Convert a string to lowercase"] |
| 1801 | + #[inline] |
| 1802 | + fn to_lower() -> str { to_lower(self) } |
| 1803 | + #[doc = "Convert a string to uppercase"] |
| 1804 | + #[inline] |
| 1805 | + fn to_upper() -> str { to_upper(self) } |
| 1806 | + #[doc = "Returns a string with leading and trailing whitespace removed"] |
| 1807 | + #[inline] |
| 1808 | + fn trim() -> str { trim(self) } |
| 1809 | + #[doc = "Returns a string with leading whitespace removed"] |
| 1810 | + #[inline] |
| 1811 | + fn trim_left() -> str { trim_left(self) } |
| 1812 | + #[doc = "Returns a string with trailing whitespace removed"] |
| 1813 | + #[inline] |
| 1814 | + fn trim_right() -> str { trim_right(self) } |
| 1815 | +} |
1733 | 1816 |
|
1734 | 1817 | #[cfg(test)]
|
1735 | 1818 | mod tests {
|
|
0 commit comments