std: replace str::is_{alphanumeric,whitespace} with the methods.
This commit is contained in:
@@ -151,7 +151,7 @@ pub fn paragraphs(s: &str) -> ~[~str] {
|
|||||||
let paras = do lines.iter().fold(~[]) |paras, line| {
|
let paras = do lines.iter().fold(~[]) |paras, line| {
|
||||||
let mut res = paras;
|
let mut res = paras;
|
||||||
|
|
||||||
if str::is_whitespace(*line) {
|
if line.is_whitespace() {
|
||||||
whitespace_lines += 1;
|
whitespace_lines += 1;
|
||||||
} else {
|
} else {
|
||||||
if whitespace_lines > 0 {
|
if whitespace_lines > 0 {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ fn unindent(s: &str) -> ~str {
|
|||||||
let ignore_previous_indents =
|
let ignore_previous_indents =
|
||||||
saw_first_line &&
|
saw_first_line &&
|
||||||
!saw_second_line &&
|
!saw_second_line &&
|
||||||
!str::is_whitespace(*line);
|
!line.is_whitespace();
|
||||||
|
|
||||||
let min_indent = if ignore_previous_indents {
|
let min_indent = if ignore_previous_indents {
|
||||||
uint::max_value
|
uint::max_value
|
||||||
@@ -58,7 +58,7 @@ fn unindent(s: &str) -> ~str {
|
|||||||
saw_second_line = true;
|
saw_second_line = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if str::is_whitespace(*line) {
|
if line.is_whitespace() {
|
||||||
min_indent
|
min_indent
|
||||||
} else {
|
} else {
|
||||||
saw_first_line = true;
|
saw_first_line = true;
|
||||||
@@ -80,7 +80,7 @@ fn unindent(s: &str) -> ~str {
|
|||||||
if !lines.is_empty() {
|
if !lines.is_empty() {
|
||||||
let unindented = ~[lines.head().trim().to_owned()]
|
let unindented = ~[lines.head().trim().to_owned()]
|
||||||
+ do lines.tail().map |line| {
|
+ do lines.tail().map |line| {
|
||||||
if str::is_whitespace(*line) {
|
if line.is_whitespace() {
|
||||||
copy *line
|
copy *line
|
||||||
} else {
|
} else {
|
||||||
assert!(line.len() >= min_indent);
|
assert!(line.len() >= min_indent);
|
||||||
|
|||||||
@@ -981,24 +981,6 @@ fn match_at<'a,'b>(haystack: &'a str, needle: &'b str, at: uint) -> bool {
|
|||||||
Section: String properties
|
Section: String properties
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the string contains only whitespace
|
|
||||||
*
|
|
||||||
* Whitespace characters are determined by `char::is_whitespace`
|
|
||||||
*/
|
|
||||||
pub fn is_whitespace(s: &str) -> bool {
|
|
||||||
s.iter().all(char::is_whitespace)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the string contains only alphanumerics
|
|
||||||
*
|
|
||||||
* Alphanumeric characters are determined by `char::is_alphanumeric`
|
|
||||||
*/
|
|
||||||
fn is_alphanumeric(s: &str) -> bool {
|
|
||||||
s.iter().all(char::is_alphanumeric)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the number of characters that a string holds
|
/// Returns the number of characters that a string holds
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn char_len(s: &str) -> uint { count_chars(s, 0u, s.len()) }
|
pub fn char_len(s: &str) -> uint { count_chars(s, 0u, s.len()) }
|
||||||
@@ -1749,14 +1731,14 @@ impl<'self> StrSlice<'self> for &'self str {
|
|||||||
* Whitespace characters are determined by `char::is_whitespace`
|
* Whitespace characters are determined by `char::is_whitespace`
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_whitespace(&self) -> bool { is_whitespace(*self) }
|
fn is_whitespace(&self) -> bool { self.iter().all(char::is_whitespace) }
|
||||||
/**
|
/**
|
||||||
* Returns true if the string contains only alphanumerics
|
* Returns true if the string contains only alphanumerics
|
||||||
*
|
*
|
||||||
* Alphanumeric characters are determined by `char::is_alphanumeric`
|
* Alphanumeric characters are determined by `char::is_alphanumeric`
|
||||||
*/
|
*/
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_alphanumeric(&self) -> bool { is_alphanumeric(*self) }
|
fn is_alphanumeric(&self) -> bool { self.iter().all(char::is_alphanumeric) }
|
||||||
/// Returns the size in bytes not counting the null terminator
|
/// Returns the size in bytes not counting the null terminator
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn len(&self) -> uint {
|
fn len(&self) -> uint {
|
||||||
@@ -2773,11 +2755,11 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_whitespace() {
|
fn test_is_whitespace() {
|
||||||
assert!(is_whitespace(""));
|
assert!("".is_whitespace());
|
||||||
assert!(is_whitespace(" "));
|
assert!(" ".is_whitespace());
|
||||||
assert!(is_whitespace("\u2009")); // Thin space
|
assert!("\u2009".is_whitespace()); // Thin space
|
||||||
assert!(is_whitespace(" \n\t "));
|
assert!(" \n\t ".is_whitespace());
|
||||||
assert!(!is_whitespace(" _ "));
|
assert!(!" _ ".is_whitespace());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user