diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-10 00:44:58 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-06-10 23:02:54 +1000 |
| commit | c32fb53cf9ae20a657d17bd8e2f0b36863096583 (patch) | |
| tree | 928280b4bfcde6b9765de76f956624a735eafde9 /src/libextra | |
| parent | b29cd22bce6325a60788ab84f989bd2e82fcaaf4 (diff) | |
| download | rust-c32fb53cf9ae20a657d17bd8e2f0b36863096583.tar.gz rust-c32fb53cf9ae20a657d17bd8e2f0b36863096583.zip | |
std: remove str::{len, slice, is_empty} in favour of methods.
Diffstat (limited to 'src/libextra')
| -rw-r--r-- | src/libextra/getopts.rs | 2 | ||||
| -rw-r--r-- | src/libextra/net_tcp.rs | 2 | ||||
| -rw-r--r-- | src/libextra/net_url.rs | 50 | ||||
| -rw-r--r-- | src/libextra/rope.rs | 14 | ||||
| -rw-r--r-- | src/libextra/sha1.rs | 3 | ||||
| -rw-r--r-- | src/libextra/time.rs | 6 |
6 files changed, 37 insertions, 40 deletions
diff --git a/src/libextra/getopts.rs b/src/libextra/getopts.rs index af026473a1b..111de53052c 100644 --- a/src/libextra/getopts.rs +++ b/src/libextra/getopts.rs @@ -247,7 +247,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result { let mut names; let mut i_arg = None; if cur[1] == '-' as u8 { - let tail = str::slice(cur, 2, curlen); + let tail = cur.slice(2, curlen); let tail_eq: ~[&str] = tail.split_iter('=').collect(); if tail_eq.len() <= 1 { names = ~[Long(tail.to_owned())]; diff --git a/src/libextra/net_tcp.rs b/src/libextra/net_tcp.rs index 87ebfdfb797..9026dc25b2d 100644 --- a/src/libextra/net_tcp.rs +++ b/src/libextra/net_tcp.rs @@ -1809,7 +1809,7 @@ mod test { } fn buf_write<W:io::Writer>(w: &W, val: &str) { - debug!("BUF_WRITE: val len %?", str::len(val)); + debug!("BUF_WRITE: val len %?", val.len()); do str::byte_slice(val) |b_slice| { debug!("BUF_WRITE: b_slice len %?", b_slice.len()); diff --git a/src/libextra/net_url.rs b/src/libextra/net_url.rs index f7e86b00d23..6fd6fa3acd9 100644 --- a/src/libextra/net_url.rs +++ b/src/libextra/net_url.rs @@ -291,7 +291,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> { fn split_char_first(s: &str, c: char) -> (~str, ~str) { - let len = str::len(s); + let len = s.len(); let mut index = len; let mut mat = 0; do io::with_str_reader(s) |rdr| { @@ -307,16 +307,16 @@ fn split_char_first(s: &str, c: char) -> (~str, ~str) { } } if index+mat == len { - return (str::slice(s, 0, index).to_owned(), ~""); + return (s.slice(0, index).to_owned(), ~""); } else { - return (str::slice(s, 0, index).to_owned(), - str::slice(s, index + mat, str::len(s)).to_owned()); + return (s.slice(0, index).to_owned(), + s.slice(index + mat, s.len()).to_owned()); } } fn userinfo_from_str(uinfo: &str) -> UserInfo { let (user, p) = split_char_first(uinfo, ':'); - let pass = if str::len(p) == 0 { + let pass = if p.is_empty() { None } else { Some(p) @@ -333,7 +333,7 @@ fn userinfo_to_str(userinfo: &UserInfo) -> ~str { fn query_from_str(rawquery: &str) -> Query { let mut query: Query = ~[]; - if str::len(rawquery) != 0 { + if !rawquery.is_empty() { for rawquery.split_iter('&').advance |p| { let (k, v) = split_char_first(p, '='); query.push((decode_component(k), decode_component(v))); @@ -373,7 +373,7 @@ pub fn get_scheme(rawurl: &str) -> Result<(~str, ~str), ~str> { return Err(~"url: Scheme cannot be empty."); } else { return Ok((rawurl.slice(0,i).to_owned(), - rawurl.slice(i+1,str::len(rawurl)).to_owned())); + rawurl.slice(i+1,rawurl.len()).to_owned())); } } _ => { @@ -475,7 +475,7 @@ fn get_authority(rawurl: &str) -> } Ip6Host => { if colon_count > 7 { - host = str::slice(rawurl, begin, i).to_owned(); + host = rawurl.slice(begin, i).to_owned(); pos = i; st = InPort; } @@ -492,13 +492,13 @@ fn get_authority(rawurl: &str) -> colon_count = 0; // reset count match st { Start => { - let user = str::slice(rawurl, begin, i).to_owned(); + let user = rawurl.slice(begin, i).to_owned(); userinfo = Some(UserInfo::new(user, None)); st = InHost; } PassHostPort => { - let user = str::slice(rawurl, begin, pos).to_owned(); - let pass = str::slice(rawurl, pos+1, i).to_owned(); + let user = rawurl.slice(begin, pos).to_owned(); + let pass = rawurl.slice(pos+1, i).to_owned(); userinfo = Some(UserInfo::new(user, Some(pass))); st = InHost; } @@ -529,31 +529,31 @@ fn get_authority(rawurl: &str) -> match st { Start => { if host_is_end_plus_one() { - host = str::slice(rawurl, begin, end+1).to_owned(); + host = rawurl.slice(begin, end+1).to_owned(); } else { - host = str::slice(rawurl, begin, end).to_owned(); + host = rawurl.slice(begin, end).to_owned(); } } PassHostPort | Ip6Port => { if in != Digit { return Err(~"Non-digit characters in port."); } - host = str::slice(rawurl, begin, pos).to_owned(); - port = Some(str::slice(rawurl, pos+1, end).to_owned()); + host = rawurl.slice(begin, pos).to_owned(); + port = Some(rawurl.slice(pos+1, end).to_owned()); } Ip6Host | InHost => { - host = str::slice(rawurl, begin, end).to_owned(); + host = rawurl.slice(begin, end).to_owned(); } InPort => { if in != Digit { return Err(~"Non-digit characters in port."); } - port = Some(str::slice(rawurl, pos+1, end).to_owned()); + port = Some(rawurl.slice(pos+1, end).to_owned()); } } let rest = if host_is_end_plus_one() { ~"" } - else { str::slice(rawurl, end, len).to_owned() }; + else { rawurl.slice(end, len).to_owned() }; return Ok((userinfo, host, port, rest)); } @@ -561,7 +561,7 @@ fn get_authority(rawurl: &str) -> // returns the path and unparsed part of url, or an error fn get_path(rawurl: &str, authority: bool) -> Result<(~str, ~str), ~str> { - let len = str::len(rawurl); + let len = rawurl.len(); let mut end = len; for rawurl.iter().enumerate().advance |(i,c)| { match c { @@ -585,8 +585,8 @@ fn get_path(rawurl: &str, authority: bool) -> } } - return Ok((decode_component(str::slice(rawurl, 0, end)), - str::slice(rawurl, end, len).to_owned())); + return Ok((decode_component(rawurl.slice(0, end)), + rawurl.slice(end, len).to_owned())); } // returns the parsed query and the fragment, if present @@ -594,16 +594,16 @@ fn get_query_fragment(rawurl: &str) -> Result<(Query, Option<~str>), ~str> { if !str::starts_with(rawurl, "?") { if str::starts_with(rawurl, "#") { - let f = decode_component(str::slice(rawurl, + let f = decode_component(rawurl.slice( 1, - str::len(rawurl))); + rawurl.len())); return Ok((~[], Some(f))); } else { return Ok((~[], None)); } } - let (q, r) = split_char_first(str::slice(rawurl, 1, rawurl.len()), '#'); - let f = if str::len(r) != 0 { + let (q, r) = split_char_first(rawurl.slice(1, rawurl.len()), '#'); + let f = if r.len() != 0 { Some(decode_component(r)) } else { None }; return Ok((query_from_str(q), f)); } diff --git a/src/libextra/rope.rs b/src/libextra/rope.rs index 413a498a20e..1b58aa68f77 100644 --- a/src/libextra/rope.rs +++ b/src/libextra/rope.rs @@ -71,7 +71,7 @@ pub fn empty() -> Rope { * * the function runs in linear time. */ pub fn of_str(str: @~str) -> Rope { - return of_substr(str, 0u, str::len(*str)); + return of_substr(str, 0u, str.len()); } /** @@ -98,7 +98,7 @@ pub fn of_str(str: @~str) -> Rope { */ pub fn of_substr(str: @~str, byte_offset: uint, byte_len: uint) -> Rope { if byte_len == 0u { return node::Empty; } - if byte_offset + byte_len > str::len(*str) { fail!(); } + if byte_offset + byte_len > str.len() { fail!(); } return node::Content(node::of_substr(str, byte_offset, byte_len)); } @@ -657,7 +657,7 @@ pub mod node { * the length of `str`. */ pub fn of_str(str: @~str) -> @Node { - return of_substr(str, 0u, str::len(*str)); + return of_substr(str, 0u, str.len()); } /** @@ -705,7 +705,7 @@ pub mod node { */ pub fn of_substr_unsafer(str: @~str, byte_start: uint, byte_len: uint, char_len: uint) -> @Node { - assert!((byte_start + byte_len <= str::len(*str))); + assert!((byte_start + byte_len <= str.len())); let candidate = @Leaf(Leaf { byte_offset: byte_start, byte_len: byte_len, @@ -1292,9 +1292,7 @@ mod tests { node::Leaf(x) => { str::push_str( str, - str::slice( - *x.content, x.byte_offset, - x.byte_offset + x.byte_len)); + x.content.slice(x.byte_offset, x.byte_offset + x.byte_len)); } node::Concat(ref x) => { aux(str, x.left); @@ -1340,7 +1338,7 @@ mod tests { assert!(rope_to_string(r) == *sample); let mut string_iter = 0u; - let string_len = str::len(*sample); + let string_len = sample.len(); let mut rope_iter = iterator::char::start(r); let mut equal = true; while equal { diff --git a/src/libextra/sha1.rs b/src/libextra/sha1.rs index 3ad2e727a5d..658621e25bd 100644 --- a/src/libextra/sha1.rs +++ b/src/libextra/sha1.rs @@ -281,7 +281,6 @@ pub fn sha1() -> @Sha1 { mod tests { use sha1; - use core::str; use core::vec; #[test] @@ -396,7 +395,7 @@ mod tests { // Test that it works when accepting the message in pieces for tests.each |t| { - let len = str::len(t.input); + let len = t.input.len(); let mut left = len; while left > 0u { let take = (left + 1u) / 2u; diff --git a/src/libextra/time.rs b/src/libextra/time.rs index e1c78f729a4..f545b28c507 100644 --- a/src/libextra/time.rs +++ b/src/libextra/time.rs @@ -279,7 +279,7 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> { match strs[i] { // can't use let due to stage0 bugs (ref needle, value) => { if match_str(ss, pos, *needle) { - return Some((value, pos + str::len(*needle))); + return Some((value, pos + needle.len())); } } } @@ -598,7 +598,7 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> { // It's odd, but to maintain compatibility with c's // strptime we ignore the timezone. let mut pos = pos; - let len = str::len(s); + let len = s.len(); while pos < len { let range = str::char_range_at(s, pos); pos = range.next; @@ -651,7 +651,7 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> { tm_nsec: 0_i32, }; let mut pos = 0u; - let len = str::len(s); + let len = s.len(); let mut result = Err(~"Invalid time"); while !rdr.eof() && pos < len { |
