More purity to make it easier to borrow strings in format strings.

This commit is contained in:
Eric Holk 2012-07-24 12:11:29 -07:00
parent f5be06fa1f
commit 7ecddb2771
3 changed files with 9 additions and 9 deletions

View file

@ -1616,7 +1616,7 @@ fn cmd_sources(c: cargo) {
if vec::len(c.opts.free) < 3u {
for c.sources.each_value |v| {
info(#fmt("%s (%s) via %s",
copy v.name, copy v.url, copy v.method));
v.name, v.url, v.method));
}
ret;
}

View file

@ -312,7 +312,7 @@ mod rt {
let mut s = str::from_char(c);
ret pad(cv, s, pad_nozero);
}
fn conv_str(cv: conv, s: &str) -> ~str {
pure fn conv_str(cv: conv, s: &str) -> ~str {
// For strings, precision is the maximum characters
// displayed
let mut unpadded = alt cv.precision {
@ -323,7 +323,7 @@ mod rt {
} else { s.to_unique() }
}
};
ret pad(cv, unpadded, pad_nozero);
ret unchecked { pad(cv, unpadded, pad_nozero) };
}
fn conv_float(cv: conv, f: float) -> ~str {
let (to_str, digits) = alt cv.precision {
@ -398,7 +398,7 @@ mod rt {
pad_float { {might_zero_pad:true, signed:true } }
pad_unsigned { {might_zero_pad:true, signed:false} }
};
fn have_precision(cv: conv) -> bool {
pure fn have_precision(cv: conv) -> bool {
ret alt cv.precision { count_implied { false } _ { true } };
}
let zero_padding = {
@ -428,7 +428,7 @@ mod rt {
}
ret padstr + s;
}
fn have_flag(flags: u32, f: u32) -> bool {
pure fn have_flag(flags: u32, f: u32) -> bool {
flags & f != 0
}
}

View file

@ -1934,7 +1934,7 @@ trait str_slice {
fn is_whitespace() -> bool;
fn is_alphanumeric() -> bool;
pure fn len() -> uint;
fn slice(begin: uint, end: uint) -> ~str;
pure fn slice(begin: uint, end: uint) -> ~str;
fn split(sepfn: fn(char) -> bool) -> ~[~str];
fn split_char(sep: char) -> ~[~str];
fn split_str(sep: &a/str) -> ~[~str];
@ -1944,7 +1944,7 @@ trait str_slice {
fn to_upper() -> ~str;
fn escape_default() -> ~str;
fn escape_unicode() -> ~str;
fn to_unique() -> ~str;
pure fn to_unique() -> ~str;
}
/// Extension methods for strings
@ -2013,7 +2013,7 @@ impl extensions/& of str_slice for &str {
* beyond the last character of the string
*/
#[inline]
fn slice(begin: uint, end: uint) -> ~str { slice(self, begin, end) }
pure fn slice(begin: uint, end: uint) -> ~str { slice(self, begin, end) }
/// Splits a string into substrings using a character function
#[inline]
fn split(sepfn: fn(char) -> bool) -> ~[~str] { split(self, sepfn) }
@ -2053,7 +2053,7 @@ impl extensions/& of str_slice for &str {
fn escape_unicode() -> ~str { escape_unicode(self) }
#[inline]
fn to_unique() -> ~str { self.slice(0, self.len()) }
pure fn to_unique() -> ~str { self.slice(0, self.len()) }
}
#[cfg(test)]