From d74606ead60d524eb72afad2cd8b45facd6c5d40 Mon Sep 17 00:00:00 2001 From: Marvin Löbel Date: Sat, 23 Mar 2013 17:25:16 +0100 Subject: pre-rebase commit --- src/libstd/getopts.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index de8a8f34381..f837f776b96 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -601,7 +601,7 @@ pub mod groups { row += match short_name.len() { 0 => ~"", 1 => ~"-" + short_name + " ", - _ => fail!(~"the short name should only be 1 char long"), + _ => fail!(~"the short name should only be 1 ascii char long"), }; // long option @@ -617,6 +617,7 @@ pub mod groups { Maybe => ~"[" + hint + ~"]", }; + // FIXME: #5516 // here we just need to indent the start of the description let rowlen = row.len(); row += if rowlen < 24 { @@ -625,8 +626,22 @@ pub mod groups { desc_sep }; + // Normalize desc to contain words seperated by one space character + let mut desc_normalized_whitespace = ~str + for desc.each_word |word| { + desc_normalized_whitespace.push_str(word); + desc_normalized_whitespace.push_char(' '); + } + + // FIXME: #5516 + let mut desc_rows: ~[~str] = ~[]; + for desc_normalized_whitespace.each_split_within(54) |substr| { + desc_rows.push(~substr); + } + + // FIXME: #5516 // wrapped description - row += str::connect(str::split_within(desc, 54), desc_sep); + row += str::connect(desc_rows, desc_sep); row }); -- cgit 1.4.1-3-g733a5 From b9de2b5787440bbb196fd38223ef4a6a6f196f83 Mon Sep 17 00:00:00 2001 From: Marvin Löbel Date: Sun, 24 Mar 2013 07:51:18 +0100 Subject: Switched over a bunch of splitting funktions to non-allocating iterators --- src/libcore/num/strconv.rs | 8 +-- src/libcore/os.rs | 3 +- src/libcore/path.rs | 33 ++++++++---- src/libcore/rand.rs | 4 +- src/libcore/str.rs | 114 +++++++++++++++++++++------------------- src/librustc/metadata/cstore.rs | 4 +- src/librustc/middle/resolve.rs | 5 +- src/libstd/base64.rs | 30 ++++++----- src/libstd/getopts.rs | 13 ++--- src/libstd/json.rs | 3 +- src/libstd/net_ip.rs | 4 +- src/libstd/net_url.rs | 4 +- src/libsyntax/parse/comments.rs | 8 ++- 13 files changed, 135 insertions(+), 98 deletions(-) (limited to 'src/libstd') diff --git a/src/libcore/num/strconv.rs b/src/libcore/num/strconv.rs index e73a4a2ccaa..ce6c015c131 100644 --- a/src/libcore/num/strconv.rs +++ b/src/libcore/num/strconv.rs @@ -132,10 +132,10 @@ impl_NumStrConv_Integer!(u64) // Special value strings as [u8] consts. -const inf_buf: [u8*3] = ['i' as u8, 'n' as u8, 'f' as u8]; -const positive_inf_buf: [u8*4] = ['+' as u8, 'i' as u8, 'n' as u8, 'f' as u8]; -const negative_inf_buf: [u8*4] = ['-' as u8, 'i' as u8, 'n' as u8, 'f' as u8]; -const nan_buf: [u8*3] = ['N' as u8, 'a' as u8, 'N' as u8]; +static inf_buf: [u8*3] = ['i' as u8, 'n' as u8, 'f' as u8]; +static positive_inf_buf: [u8*4] = ['+' as u8, 'i' as u8, 'n' as u8, 'f' as u8]; +static negative_inf_buf: [u8*4] = ['-' as u8, 'i' as u8, 'n' as u8, 'f' as u8]; +static nan_buf: [u8*3] = ['N' as u8, 'a' as u8, 'N' as u8]; /** * Converts a number to its string representation as a byte vector. diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 3c2dbf7ea15..9aa00e8e457 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -218,7 +218,8 @@ pub fn env() -> ~[(~str,~str)] { fn env_convert(input: ~[~str]) -> ~[(~str, ~str)] { let mut pairs = ~[]; for input.each |p| { - let vs = str::splitn_char(*p, '=', 1); + let mut vs = ~[]; + for str::each_splitn_char(*p, '=', 1) |s| { vs.push(s.to_owned()) } debug!("splitting: len: %u", vs.len()); fail_unless!(vs.len() == 2); diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 76aaf14d4ac..3d06809a452 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -381,7 +381,8 @@ impl ToStr for PosixPath { impl GenericPath for PosixPath { fn from_str(s: &str) -> PosixPath { - let mut components = str::split_nonempty(s, |c| c == '/'); + let mut components = ~[]; + for str::each_split_nonempty(s, |c| c == '/') |s| { components.push(s.to_owned()) } let is_absolute = (s.len() != 0 && s[0] == '/' as u8); return PosixPath { is_absolute: is_absolute, components: components } @@ -504,9 +505,10 @@ impl GenericPath for PosixPath { fn push_many(&self, cs: &[~str]) -> PosixPath { let mut v = copy self.components; for cs.each |e| { - let mut ss = str::split_nonempty( - *e, - |c| windows::is_sep(c as u8)); + let mut ss = ~[]; + for str::each_split_nonempty(*e, |c| windows::is_sep(c as u8)) |s| { + ss.push(s.to_owned()) + } unsafe { v.push_all_move(ss); } } PosixPath { is_absolute: self.is_absolute, @@ -515,7 +517,10 @@ impl GenericPath for PosixPath { fn push(&self, s: &str) -> PosixPath { let mut v = copy self.components; - let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8)); + let mut ss = ~[]; + for str::each_split_nonempty(s, |c| windows::is_sep(c as u8)) |s| { + ss.push(s.to_owned()) + } unsafe { v.push_all_move(ss); } PosixPath { components: v, ..copy *self } } @@ -590,8 +595,10 @@ impl GenericPath for WindowsPath { } } - let mut components = - str::split_nonempty(rest, |c| windows::is_sep(c as u8)); + let mut components = ~[]; + for str::each_split_nonempty(rest, |c| windows::is_sep(c as u8)) |s| { + components.push(s.to_owned()) + } let is_absolute = (rest.len() != 0 && windows::is_sep(rest[0])); return WindowsPath { host: host, device: device, @@ -759,9 +766,10 @@ impl GenericPath for WindowsPath { fn push_many(&self, cs: &[~str]) -> WindowsPath { let mut v = copy self.components; for cs.each |e| { - let mut ss = str::split_nonempty( - *e, - |c| windows::is_sep(c as u8)); + let mut ss = ~[]; + for str::each_split_nonempty(*e, |c| windows::is_sep(c as u8)) |s| { + ss.push(s.to_owned()) + } unsafe { v.push_all_move(ss); } } // tedious, but as-is, we can't use ..self @@ -775,7 +783,10 @@ impl GenericPath for WindowsPath { fn push(&self, s: &str) -> WindowsPath { let mut v = copy self.components; - let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8)); + let mut ss = ~[]; + for str::each_split_nonempty(s, |c| windows::is_sep(c as u8)) |s| { + ss.push(s.to_owned()) + } unsafe { v.push_all_move(ss); } return WindowsPath { components: v, ..copy *self } } diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 3085269f692..afa4ea66ca6 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -327,7 +327,9 @@ impl RngUtil for @Rng { */ fn gen_char_from(&self, chars: &str) -> char { fail_unless!(!chars.is_empty()); - self.choose(str::chars(chars)) + let mut cs = ~[]; + for str::each_char(chars) |c| { cs.push(c) } + self.choose(cs) } /// Return a random bool diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 28f76125746..4fc960a7c04 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -463,7 +463,7 @@ pub fn each_split_char_nonempty(s: &str, sep: char, it: &fn(&str) -> bool) { } fn each_split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool, - allow_trailing_empty: bool), it: &fn(&str) -> bool) { + allow_trailing_empty: bool, it: &fn(&str) -> bool) { if sep < 128u as char { let b = sep as u8, l = len(s); let mut done = 0u; @@ -513,8 +513,8 @@ pub fn each_split_nonempty(s: &str, sepfn: &fn(char) -> bool, it: &fn(&str) -> b each_split_inner(s, sepfn, len(s), false, false, it) } -pure fn each_split_inner(s: &str, sepfn: &fn(cc: char) -> bool, count: uint, - allow_empty: bool, allow_trailing_empty: bool), it: &fn(&str) -> bool) { +fn each_split_inner(s: &str, sepfn: &fn(cc: char) -> bool, count: uint, + allow_empty: bool, allow_trailing_empty: bool, it: &fn(&str) -> bool) { let l = len(s); let mut i = 0u, start = 0u, done = 0u; while i < l && done < count { @@ -534,7 +534,7 @@ pure fn each_split_inner(s: &str, sepfn: &fn(cc: char) -> bool, count: uint, } // See Issue #1932 for why this is a naive search -fn iter_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { +fn iter_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint) -> bool) { let sep_len = len(sep), l = len(s); fail_unless!(sep_len > 0u); let mut i = 0u, match_start = 0u, match_i = 0u; @@ -545,7 +545,7 @@ fn iter_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { match_i += 1u; // Found a match if match_i == sep_len { - f(match_start, i + 1u); + if !f(match_start, i + 1u) { return; } match_i = 0u; } i += 1u; @@ -561,10 +561,10 @@ fn iter_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { } } -fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { +fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint) -> bool) { let mut last_end = 0u; - do iter_matches(s, sep) |from, to| { - f(last_end, from); + for iter_matches(s, sep) |from, to| { + if !f(last_end, from) { return; } last_end = to; } f(last_end, len(s)); @@ -580,13 +580,13 @@ fn iter_between_matches(s: &'a str, sep: &'b str, f: &fn(uint, uint)) { * ~~~ */ pub fn each_split_str(s: &'a str, sep: &'b str, it: &fn(&str) -> bool) { - do iter_between_matches(s, sep) |from, to| { + for iter_between_matches(s, sep) |from, to| { if !it( unsafe { raw::slice_bytes(s, from, to) } ) { return; } } } pub fn each_split_str_nonempty(s: &'a str, sep: &'b str, it: &fn(&str) -> bool) { - do iter_between_matches(s, sep) |from, to| { + for iter_between_matches(s, sep) |from, to| { if to > from { if !it( unsafe { raw::slice_bytes(s, from, to) } ) { return; } } @@ -630,7 +630,7 @@ pub fn levdistance(s: &str, t: &str) -> uint { /** * Splits a string into a vector of the substrings separated by LF ('\n'). */ -pub fn each_line(s: &str, it: &fn(&str) -> bool) { each_split_char(s, '\n', it) } +pub fn each_line(s: &str, it: &fn(&str) -> bool) { each_split_char_no_trailing(s, '\n', it) } /** * Splits a string into a vector of the substrings separated by LF ('\n') @@ -656,52 +656,56 @@ pub fn each_word(s: &str, it: &fn(&str) -> bool) { * each of which is less bytes long than a limit */ pub fn each_split_within(ss: &str, lim: uint, it: &fn(&str) -> bool) { - let words = str::words(ss); - - // empty? - if words == ~[] { return ~[]; } - - let mut rows : ~[~str] = ~[]; - let mut row : ~str = ~""; - - for words.each |wptr| { - let word = copy *wptr; - - // if adding this word to the row would go over the limit, - // then start a new row - if row.len() + word.len() + 1 > lim { - rows.push(copy row); // save previous row - row = word; // start a new one - } else { - if row.len() > 0 { row += ~" " } // separate words - row += word; // append to this row - } + // Just for fun, let's write this as an automaton + enum SplitWithinState { + A, // Leading whitespace, initial state + B, // Words + C, // Internal and trailing whitespace } + enum Whitespace { Ws, Cr } + enum LengthLimit { UnderLim, OverLim } - // save the last row - if row != ~"" { rows.push(row); } + let mut slice_start = 0; + let mut last_start = 0; + let mut last_end = 0; + let mut state = A; - rows - // NOTE: Finish change here + let mut cont = true; + let slice = || { cont = it(ss.slice(slice_start, last_end)) }; - let mut last_slice_i = 0, last_word_i = 0, word_start = true; - for each_chari(s) |i, c| { - if (i - last_slice_i) <= lim { - if char::is_whitespace(c) { + let machine = |i: uint, c: char| { + let whitespace = if char::is_whitespace(c) { Ws } else { Cr }; + let limit = if (i - slice_start + 1) <= lim { UnderLim } else { OverLim }; - } else { + state = match (state, whitespace, limit) { + (A, Ws, _) => { A } + (A, Cr, _) => { slice_start = i; last_start = i; B } - } - } else { + (B, Cr, UnderLim) => { B } + (B, Cr, OverLim) if (i - last_start + 1) > lim + => { fail!(~"word longer than limit!") } + (B, Cr, OverLim) => { slice(); slice_start = last_start; B } + (B, Ws, UnderLim) => { last_end = i; C } + (B, Ws, OverLim) => { last_end = i; slice(); A } - } + (C, Cr, UnderLim) => { last_start = i; B } + (C, Cr, OverLim) => { slice(); slice_start = i; last_start = i; last_end = i; B } + (C, Ws, OverLim) => { slice(); A } + (C, Ws, UnderLim) => { C } + }; + cont + }; + str::each_chari(ss, machine); + // Let the automaton 'run out' + let mut fake_i = ss.len(); + while cont && match state { B | C => true, A => false } { + machine(fake_i, ' '); + fake_i += 1; } } - - /// Convert a string to lowercase. ASCII only pub fn to_lower(s: &str) -> ~str { map(s, @@ -731,7 +735,7 @@ pub fn to_upper(s: &str) -> ~str { */ pub fn replace(s: &str, from: &str, to: &str) -> ~str { let mut result = ~"", first = true; - do iter_between_matches(s, from) |start, end| { + for iter_between_matches(s, from) |start, end| { if first { first = false; } else { @@ -2286,9 +2290,9 @@ pub trait StrSlice { fn len(&self) -> uint; fn char_len(&self) -> uint; fn slice(&self, begin: uint, end: uint) -> &'self str; - fn split(&self, sepfn: &fn(char) -> bool) -> ~[~str]; - fn split_char(&self, sep: char) -> ~[~str]; - fn split_str(&self, sep: &'a str) -> ~[~str]; + fn each_split(&self, sepfn: &fn(char) -> bool, it: &fn(&str) -> bool); + fn each_split_char(&self, sep: char, it: &fn(&str) -> bool); + fn each_split_str(&self, sep: &'a str, it: &fn(&str) -> bool); fn starts_with(&self, needle: &'a str) -> bool; fn substr(&self, begin: uint, n: uint) -> &'self str; fn to_lower(&self) -> ~str; @@ -2408,20 +2412,24 @@ impl StrSlice for &'self str { } /// Splits a string into substrings using a character function #[inline] - fn split(&self, sepfn: &fn(char) -> bool) -> ~[~str] { - split(*self, sepfn) + fn each_split(&self, sepfn: &fn(char) -> bool, it: &fn(&str) -> bool) { + each_split(*self, sepfn, it) } /** * Splits a string into substrings at each occurrence of a given character */ #[inline] - fn split_char(&self, sep: char) -> ~[~str] { split_char(*self, sep) } + fn each_split_char(&self, sep: char, it: &fn(&str) -> bool) { + each_split_char(*self, sep, it) + } /** * Splits a string into a vector of the substrings separated by a given * string */ #[inline] - fn split_str(&self, sep: &'a str) -> ~[~str] { split_str(*self, sep) } + fn each_split_str(&self, sep: &'a str, it: &fn(&str) -> bool) { + each_split_str(*self, sep, it) + } /// Returns true if one string starts with another #[inline] fn starts_with(&self, needle: &'a str) -> bool { diff --git a/src/librustc/metadata/cstore.rs b/src/librustc/metadata/cstore.rs index 581ad5336de..018a365f37f 100644 --- a/src/librustc/metadata/cstore.rs +++ b/src/librustc/metadata/cstore.rs @@ -120,7 +120,9 @@ pub fn get_used_libraries(cstore: @mut CStore) -> ~[~str] { } pub fn add_used_link_args(cstore: @mut CStore, args: &str) { - cstore.used_link_args.push_all(args.split_char(' ')); + for args.each_split_char(' ') |s| { + cstore.used_link_args.push(s.to_owned()); + } } pub fn get_used_link_args(cstore: @mut CStore) -> ~[~str] { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 00883b28b04..079110e67f5 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -76,7 +76,7 @@ use syntax::visit::{visit_mod, visit_ty, vt}; use syntax::opt_vec::OptVec; use core::option::{Some, get, is_some, is_none}; -use core::str::{connect, split_str}; +use core::str::{connect, each_split_str}; use core::hashmap::linear::LinearMap; use std::oldmap::HashMap; @@ -1696,7 +1696,8 @@ pub impl Resolver { entry: %s (%?)", path_string, def_like); - let mut pieces = split_str(path_string, ~"::"); + let mut pieces = ~[]; + for each_split_str(path_string, "::") |s| { pieces.push(s.to_owned()) } let final_ident_str = pieces.pop(); let final_ident = self.session.ident_of(final_ident_str); diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index ff026324404..b11ad7052b9 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -16,12 +16,16 @@ pub trait ToBase64 { fn to_base64(&self) -> ~str; } +static CHARS: &'static[char] = &[ + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' +]; + impl ToBase64 for &'self [u8] { fn to_base64(&self) -> ~str { - let chars = str::chars( - ~"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" - ); - let mut s = ~""; unsafe { let len = self.len(); @@ -35,10 +39,10 @@ impl ToBase64 for &'self [u8] { (self[i + 2u] as uint); // This 24-bit number gets separated into four 6-bit numbers. - str::push_char(&mut s, chars[(n >> 18u) & 63u]); - str::push_char(&mut s, chars[(n >> 12u) & 63u]); - str::push_char(&mut s, chars[(n >> 6u) & 63u]); - str::push_char(&mut s, chars[n & 63u]); + str::push_char(&mut s, CHARS[(n >> 18u) & 63u]); + str::push_char(&mut s, CHARS[(n >> 12u) & 63u]); + str::push_char(&mut s, CHARS[(n >> 6u) & 63u]); + str::push_char(&mut s, CHARS[n & 63u]); i += 3u; } @@ -49,17 +53,17 @@ impl ToBase64 for &'self [u8] { 0 => (), 1 => { let n = (self[i] as uint) << 16u; - str::push_char(&mut s, chars[(n >> 18u) & 63u]); - str::push_char(&mut s, chars[(n >> 12u) & 63u]); + str::push_char(&mut s, CHARS[(n >> 18u) & 63u]); + str::push_char(&mut s, CHARS[(n >> 12u) & 63u]); str::push_char(&mut s, '='); str::push_char(&mut s, '='); } 2 => { let n = (self[i] as uint) << 16u | (self[i + 1u] as uint) << 8u; - str::push_char(&mut s, chars[(n >> 18u) & 63u]); - str::push_char(&mut s, chars[(n >> 12u) & 63u]); - str::push_char(&mut s, chars[(n >> 6u) & 63u]); + str::push_char(&mut s, CHARS[(n >> 18u) & 63u]); + str::push_char(&mut s, CHARS[(n >> 12u) & 63u]); + str::push_char(&mut s, CHARS[(n >> 6u) & 63u]); str::push_char(&mut s, '='); } _ => fail!(~"Algebra is broken, please alert the math police") diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index f837f776b96..ae783fb9b69 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -244,7 +244,8 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result { let mut i_arg = None; if cur[1] == '-' as u8 { let tail = str::slice(cur, 2, curlen).to_owned(); - let tail_eq = str::splitn_char(tail, '=', 1); + let mut tail_eq = ~[]; + for str::each_splitn_char(tail, '=', 1) |s| { tail_eq.push(s.to_owned()) } if tail_eq.len() <= 1 { names = ~[Long(tail)]; } else { @@ -627,16 +628,16 @@ pub mod groups { }; // Normalize desc to contain words seperated by one space character - let mut desc_normalized_whitespace = ~str - for desc.each_word |word| { + let mut desc_normalized_whitespace = ~""; + for str::each_word(desc) |word| { desc_normalized_whitespace.push_str(word); desc_normalized_whitespace.push_char(' '); } // FIXME: #5516 - let mut desc_rows: ~[~str] = ~[]; - for desc_normalized_whitespace.each_split_within(54) |substr| { - desc_rows.push(~substr); + let mut desc_rows = ~[]; + for str::each_split_within(desc_normalized_whitespace, 54) |substr| { + desc_rows.push(substr.to_owned()); } // FIXME: #5516 diff --git a/src/libstd/json.rs b/src/libstd/json.rs index a9b9b2977cd..f39e406bc00 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -806,7 +806,8 @@ impl serialize::Decoder for Decoder<'self> { } fn read_char(&self) -> char { - let v = str::chars(self.read_owned_str()); + let mut v = ~[]; + for str::each_char(self.read_owned_str()) |c| { v.push(c) } if v.len() != 1 { fail!(~"string must have one character") } v[0] } diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index 15593571b43..4d82d35cc32 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -197,7 +197,9 @@ pub mod v4 { } } pub fn parse_to_ipv4_rep(ip: &str) -> result::Result { - let parts = vec::map(str::split_char(ip, '.'), |s| { + let mut parts = ~[]; + for str::each_split_char(ip, '.') |s| { parts.push(s.to_owned()) } + let parts = vec::map(parts, |s| { match uint::from_str(*s) { Some(n) if n <= 255 => n, _ => 256 diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 21b60584635..9caab11d643 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -344,8 +344,8 @@ fn userinfo_to_str(userinfo: &UserInfo) -> ~str { fn query_from_str(rawquery: &str) -> Query { let mut query: Query = ~[]; if str::len(rawquery) != 0 { - for str::split_char(rawquery, '&').each |p| { - let (k, v) = split_char_first(*p, '='); + for str::each_split_char(rawquery, '&') |p| { + let (k, v) = split_char_first(p, '='); // FIXME(#3722): unsafe only because decode_inner does (string) IO unsafe {query.push((decode_component(k), decode_component(v)));} }; diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 3f8a5588c71..1b6b25db38a 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -99,7 +99,8 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { } return do lines.map |line| { - let chars = str::chars(*line); + let mut chars = ~[]; + for str::each_char(*line) |c| { chars.push(c) } if i > chars.len() { ~"" } else { @@ -116,7 +117,10 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { } if comment.starts_with(~"/*") { - let lines = str::lines_any(comment.slice(3u, comment.len() - 2u).to_owned()); + let mut lines = ~[]; + for str::each_line_any(comment.slice(3u, comment.len() - 2u)) |line| { + lines.push(line.to_owned()) + } let lines = vertical_trim(lines); let lines = block_trim(lines, ~"\t ", None); let lines = block_trim(lines, ~"*", Some(1u)); -- cgit 1.4.1-3-g733a5 From c99488b3a4045171e36bcd2a89e742ac06d3ba72 Mon Sep 17 00:00:00 2001 From: Marvin Löbel Date: Mon, 25 Mar 2013 02:49:42 +0100 Subject: Isolated bug, static vector seems to behave differently than fixed sized one --- src/libcore/str.rs | 30 ------------------------------ src/libstd/base64.rs | 2 +- 2 files changed, 1 insertion(+), 31 deletions(-) (limited to 'src/libstd') diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 4fc960a7c04..96cadadfe89 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -994,7 +994,6 @@ pub fn eachi_reverse(s: &str, it: &fn(uint, u8) -> bool) { } } - /// Iterate over each char of a string, without allocating #[inline(always)] pub fn each_char(s: &str, it: &fn(char) -> bool) { @@ -1042,35 +1041,6 @@ pub fn each_chari_reverse(s: &str, it: &fn(uint, char) -> bool) { } } -///////////////////////////////////////////////////////////////////////////////////////////////// -// NOTE: Remove afterwards -/* /// Apply a function to each substring after splitting by character -pub fn split_char_each(ss: &str, cc: char, ff: &fn(v: &str) -> bool) { - vec::each(split_char(ss, cc), |s| ff(*s)) -} - -** - * Apply a function to each substring after splitting by character, up to - * `count` times - * -pub fn splitn_char_each(ss: &str, sep: char, count: uint, - ff: &fn(v: &str) -> bool) { - vec::each(splitn_char(ss, sep, count), |s| ff(*s)) -} - -/ Apply a function to each word -pub fn words_each(ss: &str, ff: &fn(v: &str) -> bool) { - vec::each(words(ss), |s| ff(*s)) -} - -** - * Apply a function to each line (by '\n') - * -pub fn lines_each(ss: &str, ff: &fn(v: &str) -> bool) { - vec::each(lines(ss), |s| ff(*s)) -} */ -///////////////////////////////////////////////////////////////////////////////////////////////// - /* Section: Searching */ diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index b11ad7052b9..02858de9b34 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -16,7 +16,7 @@ pub trait ToBase64 { fn to_base64(&self) -> ~str; } -static CHARS: &'static[char] = &[ +static CHARS: [char * 64] = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', -- cgit 1.4.1-3-g733a5