Skip to content

Commit c765c59

Browse files
author
Daniel Patterson
committed
core::str - making StrSlice trait functions pure
1 parent cd6f24f commit c765c59

File tree

1 file changed

+55
-53
lines changed

1 file changed

+55
-53
lines changed

src/libcore/str.rs

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ pub pure fn is_whitespace(s: &str) -> bool {
13611361
*
13621362
* Alphanumeric characters are determined by `char::is_alphanumeric`
13631363
*/
1364-
fn is_alphanumeric(s: &str) -> bool {
1364+
pure fn is_alphanumeric(s: &str) -> bool {
13651365
return all(s, char::is_alphanumeric);
13661366
}
13671367

@@ -2030,22 +2030,22 @@ pub mod raw {
20302030
}
20312031

20322032
pub trait UniqueStr {
2033-
fn trim() -> self;
2034-
fn trim_left() -> self;
2035-
fn trim_right() -> self;
2033+
pure fn trim() -> self;
2034+
pure fn trim_left() -> self;
2035+
pure fn trim_right() -> self;
20362036
}
20372037

20382038
/// Extension methods for strings
20392039
impl ~str: UniqueStr {
20402040
/// Returns a string with leading and trailing whitespace removed
20412041
#[inline]
2042-
fn trim() -> ~str { trim(self) }
2042+
pure fn trim() -> ~str { trim(self) }
20432043
/// Returns a string with leading whitespace removed
20442044
#[inline]
2045-
fn trim_left() -> ~str { trim_left(self) }
2045+
pure fn trim_left() -> ~str { trim_left(self) }
20462046
/// Returns a string with trailing whitespace removed
20472047
#[inline]
2048-
fn trim_right() -> ~str { trim_right(self) }
2048+
pure fn trim_right() -> ~str { trim_right(self) }
20492049
}
20502050

20512051
#[cfg(notest)]
@@ -2062,33 +2062,33 @@ pub mod traits {
20622062
pub mod traits {}
20632063

20642064
pub trait StrSlice {
2065-
fn all(it: fn(char) -> bool) -> bool;
2066-
fn any(it: fn(char) -> bool) -> bool;
2067-
fn contains(needle: &a/str) -> bool;
2068-
fn contains_char(needle: char) -> bool;
2069-
fn each(it: fn(u8) -> bool);
2070-
fn eachi(it: fn(uint, u8) -> bool);
2071-
fn each_char(it: fn(char) -> bool);
2072-
fn each_chari(it: fn(uint, char) -> bool);
2073-
fn ends_with(needle: &str) -> bool;
2074-
fn is_empty() -> bool;
2075-
fn is_not_empty() -> bool;
2076-
fn is_whitespace() -> bool;
2077-
fn is_alphanumeric() -> bool;
2065+
pure fn all(it: fn(char) -> bool) -> bool;
2066+
pure fn any(it: fn(char) -> bool) -> bool;
2067+
pure fn contains(needle: &a/str) -> bool;
2068+
pure fn contains_char(needle: char) -> bool;
2069+
pure fn each(it: fn(u8) -> bool);
2070+
pure fn eachi(it: fn(uint, u8) -> bool);
2071+
pure fn each_char(it: fn(char) -> bool);
2072+
pure fn each_chari(it: fn(uint, char) -> bool);
2073+
pure fn ends_with(needle: &str) -> bool;
2074+
pure fn is_empty() -> bool;
2075+
pure fn is_not_empty() -> bool;
2076+
pure fn is_whitespace() -> bool;
2077+
pure fn is_alphanumeric() -> bool;
20782078
pure fn len() -> uint;
20792079
pure fn slice(begin: uint, end: uint) -> ~str;
2080-
fn split(sepfn: fn(char) -> bool) -> ~[~str];
2081-
fn split_char(sep: char) -> ~[~str];
2082-
fn split_str(sep: &a/str) -> ~[~str];
2083-
fn starts_with(needle: &a/str) -> bool;
2084-
fn substr(begin: uint, n: uint) -> ~str;
2080+
pure fn split(sepfn: fn(char) -> bool) -> ~[~str];
2081+
pure fn split_char(sep: char) -> ~[~str];
2082+
pure fn split_str(sep: &a/str) -> ~[~str];
2083+
pure fn starts_with(needle: &a/str) -> bool;
2084+
pure fn substr(begin: uint, n: uint) -> ~str;
20852085
pure fn to_lower() -> ~str;
20862086
pure fn to_upper() -> ~str;
2087-
fn escape_default() -> ~str;
2088-
fn escape_unicode() -> ~str;
2089-
fn trim() -> ~str;
2090-
fn trim_left() -> ~str;
2091-
fn trim_right() -> ~str;
2087+
pure fn escape_default() -> ~str;
2088+
pure fn escape_unicode() -> ~str;
2089+
pure fn trim() -> ~str;
2090+
pure fn trim_left() -> ~str;
2091+
pure fn trim_right() -> ~str;
20922092
pure fn to_unique() -> ~str;
20932093
pure fn char_at(i: uint) -> char;
20942094
}
@@ -2100,54 +2100,56 @@ impl &str: StrSlice {
21002100
* contains no characters
21012101
*/
21022102
#[inline]
2103-
fn all(it: fn(char) -> bool) -> bool { all(self, it) }
2103+
pure fn all(it: fn(char) -> bool) -> bool { all(self, it) }
21042104
/**
21052105
* Return true if a predicate matches any character (and false if it
21062106
* matches none or there are no characters)
21072107
*/
21082108
#[inline]
2109-
fn any(it: fn(char) -> bool) -> bool { any(self, it) }
2109+
pure fn any(it: fn(char) -> bool) -> bool { any(self, it) }
21102110
/// Returns true if one string contains another
21112111
#[inline]
2112-
fn contains(needle: &a/str) -> bool { contains(self, needle) }
2112+
pure fn contains(needle: &a/str) -> bool { contains(self, needle) }
21132113
/// Returns true if a string contains a char
21142114
#[inline]
2115-
fn contains_char(needle: char) -> bool { contains_char(self, needle) }
2115+
pure fn contains_char(needle: char) -> bool {
2116+
contains_char(self, needle)
2117+
}
21162118
/// Iterate over the bytes in a string
21172119
#[inline]
2118-
fn each(it: fn(u8) -> bool) { each(self, it) }
2120+
pure fn each(it: fn(u8) -> bool) { each(self, it) }
21192121
/// Iterate over the bytes in a string, with indices
21202122
#[inline]
2121-
fn eachi(it: fn(uint, u8) -> bool) { eachi(self, it) }
2123+
pure fn eachi(it: fn(uint, u8) -> bool) { eachi(self, it) }
21222124
/// Iterate over the chars in a string
21232125
#[inline]
2124-
fn each_char(it: fn(char) -> bool) { each_char(self, it) }
2126+
pure fn each_char(it: fn(char) -> bool) { each_char(self, it) }
21252127
/// Iterate over the chars in a string, with indices
21262128
#[inline]
2127-
fn each_chari(it: fn(uint, char) -> bool) { each_chari(self, it) }
2129+
pure fn each_chari(it: fn(uint, char) -> bool) { each_chari(self, it) }
21282130
/// Returns true if one string ends with another
21292131
#[inline]
2130-
fn ends_with(needle: &str) -> bool { ends_with(self, needle) }
2132+
pure fn ends_with(needle: &str) -> bool { ends_with(self, needle) }
21312133
/// Returns true if the string has length 0
21322134
#[inline]
2133-
fn is_empty() -> bool { is_empty(self) }
2135+
pure fn is_empty() -> bool { is_empty(self) }
21342136
/// Returns true if the string has length greater than 0
21352137
#[inline]
2136-
fn is_not_empty() -> bool { is_not_empty(self) }
2138+
pure fn is_not_empty() -> bool { is_not_empty(self) }
21372139
/**
21382140
* Returns true if the string contains only whitespace
21392141
*
21402142
* Whitespace characters are determined by `char::is_whitespace`
21412143
*/
21422144
#[inline]
2143-
fn is_whitespace() -> bool { is_whitespace(self) }
2145+
pure fn is_whitespace() -> bool { is_whitespace(self) }
21442146
/**
21452147
* Returns true if the string contains only alphanumerics
21462148
*
21472149
* Alphanumeric characters are determined by `char::is_alphanumeric`
21482150
*/
21492151
#[inline]
2150-
fn is_alphanumeric() -> bool { is_alphanumeric(self) }
2152+
pure fn is_alphanumeric() -> bool { is_alphanumeric(self) }
21512153
#[inline]
21522154
/// Returns the size in bytes not counting the null terminator
21532155
pure fn len() -> uint { len(self) }
@@ -2162,29 +2164,29 @@ impl &str: StrSlice {
21622164
pure fn slice(begin: uint, end: uint) -> ~str { slice(self, begin, end) }
21632165
/// Splits a string into substrings using a character function
21642166
#[inline]
2165-
fn split(sepfn: fn(char) -> bool) -> ~[~str] { split(self, sepfn) }
2167+
pure fn split(sepfn: fn(char) -> bool) -> ~[~str] { split(self, sepfn) }
21662168
/**
21672169
* Splits a string into substrings at each occurrence of a given character
21682170
*/
21692171
#[inline]
2170-
fn split_char(sep: char) -> ~[~str] { split_char(self, sep) }
2172+
pure fn split_char(sep: char) -> ~[~str] { split_char(self, sep) }
21712173
/**
21722174
* Splits a string into a vector of the substrings separated by a given
21732175
* string
21742176
*/
21752177
#[inline]
2176-
fn split_str(sep: &a/str) -> ~[~str] { split_str(self, sep) }
2178+
pure fn split_str(sep: &a/str) -> ~[~str] { split_str(self, sep) }
21772179
/// Returns true if one string starts with another
21782180
#[inline]
2179-
fn starts_with(needle: &a/str) -> bool { starts_with(self, needle) }
2181+
pure fn starts_with(needle: &a/str) -> bool { starts_with(self, needle) }
21802182
/**
21812183
* Take a substring of another.
21822184
*
21832185
* Returns a string containing `n` characters starting at byte offset
21842186
* `begin`.
21852187
*/
21862188
#[inline]
2187-
fn substr(begin: uint, n: uint) -> ~str { substr(self, begin, n) }
2189+
pure fn substr(begin: uint, n: uint) -> ~str { substr(self, begin, n) }
21882190
/// Convert a string to lowercase
21892191
#[inline]
21902192
pure fn to_lower() -> ~str { to_lower(self) }
@@ -2193,20 +2195,20 @@ impl &str: StrSlice {
21932195
pure fn to_upper() -> ~str { to_upper(self) }
21942196
/// Escape each char in `s` with char::escape_default.
21952197
#[inline]
2196-
fn escape_default() -> ~str { escape_default(self) }
2198+
pure fn escape_default() -> ~str { escape_default(self) }
21972199
/// Escape each char in `s` with char::escape_unicode.
21982200
#[inline]
2199-
fn escape_unicode() -> ~str { escape_unicode(self) }
2201+
pure fn escape_unicode() -> ~str { escape_unicode(self) }
22002202

22012203
/// Returns a string with leading and trailing whitespace removed
22022204
#[inline]
2203-
fn trim() -> ~str { trim(self) }
2205+
pure fn trim() -> ~str { trim(self) }
22042206
/// Returns a string with leading whitespace removed
22052207
#[inline]
2206-
fn trim_left() -> ~str { trim_left(self) }
2208+
pure fn trim_left() -> ~str { trim_left(self) }
22072209
/// Returns a string with trailing whitespace removed
22082210
#[inline]
2209-
fn trim_right() -> ~str { trim_right(self) }
2211+
pure fn trim_right() -> ~str { trim_right(self) }
22102212

22112213
#[inline]
22122214
pure fn to_unique() -> ~str { self.slice(0, self.len()) }

0 commit comments

Comments
 (0)