diff options
| author | Richo Healey <richo@psych0tik.net> | 2014-05-25 03:17:19 -0700 |
|---|---|---|
| committer | Richo Healey <richo@psych0tik.net> | 2014-05-27 12:59:31 -0700 |
| commit | 1f1b2e42d76ba1cd884adc49922636a6c2ac1b2f (patch) | |
| tree | 2a56d5ceda84c1a58796fe0fc4e7cea38a9336f6 /src/libterm | |
| parent | 4348e23b269739657d934b532ad061bfd6d92309 (diff) | |
| download | rust-1f1b2e42d76ba1cd884adc49922636a6c2ac1b2f.tar.gz rust-1f1b2e42d76ba1cd884adc49922636a6c2ac1b2f.zip | |
std: Rename strbuf operations to string
[breaking-change]
Diffstat (limited to 'src/libterm')
| -rw-r--r-- | src/libterm/terminfo/mod.rs | 2 | ||||
| -rw-r--r-- | src/libterm/terminfo/parm.rs | 112 | ||||
| -rw-r--r-- | src/libterm/terminfo/parser/compiled.rs | 32 | ||||
| -rw-r--r-- | src/libterm/terminfo/searcher.rs | 8 |
4 files changed, 77 insertions, 77 deletions
diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index 716f96b1872..7fe9ea33c25 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -186,7 +186,7 @@ impl<T: Writer> Terminal<T> for TerminfoTerminal<T> { cap = self.ti.strings.find_equiv(&("op")); } } - let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_strbuf()), |op| { + let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_string()), |op| { expand(op.as_slice(), [], &mut Variables::new()) }); if s.is_ok() { diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index 6b96a78b24d..db9509a9dd2 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -124,9 +124,9 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) match stack.pop().unwrap() { // if c is 0, use 0200 (128) for ncurses compatibility Number(c) => output.push(if c == 0 { 128 } else { c } as u8), - _ => return Err("a non-char was used with %c".to_strbuf()) + _ => return Err("a non-char was used with %c".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, 'p' => state = PushParam, 'P' => state = SetVar, 'g' => state = GetVar, @@ -135,112 +135,112 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) 'l' => if stack.len() > 0 { match stack.pop().unwrap() { String(s) => stack.push(Number(s.len() as int)), - _ => return Err("a non-str was used with %l".to_strbuf()) + _ => return Err("a non-str was used with %l".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '+' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x + y)), - _ => return Err("non-numbers on stack with +".to_strbuf()) + _ => return Err("non-numbers on stack with +".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '-' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x - y)), - _ => return Err("non-numbers on stack with -".to_strbuf()) + _ => return Err("non-numbers on stack with -".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '*' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x * y)), - _ => return Err("non-numbers on stack with *".to_strbuf()) + _ => return Err("non-numbers on stack with *".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '/' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x / y)), - _ => return Err("non-numbers on stack with /".to_strbuf()) + _ => return Err("non-numbers on stack with /".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, 'm' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x % y)), - _ => return Err("non-numbers on stack with %".to_strbuf()) + _ => return Err("non-numbers on stack with %".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '&' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x & y)), - _ => return Err("non-numbers on stack with &".to_strbuf()) + _ => return Err("non-numbers on stack with &".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '|' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x | y)), - _ => return Err("non-numbers on stack with |".to_strbuf()) + _ => return Err("non-numbers on stack with |".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '^' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(x ^ y)), - _ => return Err("non-numbers on stack with ^".to_strbuf()) + _ => return Err("non-numbers on stack with ^".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '=' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x == y { 1 } else { 0 })), - _ => return Err("non-numbers on stack with =".to_strbuf()) + _ => return Err("non-numbers on stack with =".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '>' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x > y { 1 } else { 0 })), - _ => return Err("non-numbers on stack with >".to_strbuf()) + _ => return Err("non-numbers on stack with >".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '<' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(y), Number(x)) => stack.push(Number(if x < y { 1 } else { 0 })), - _ => return Err("non-numbers on stack with <".to_strbuf()) + _ => return Err("non-numbers on stack with <".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, 'A' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(0), Number(_)) => stack.push(Number(0)), (Number(_), Number(0)) => stack.push(Number(0)), (Number(_), Number(_)) => stack.push(Number(1)), - _ => return Err("non-numbers on stack with logical and".to_strbuf()) + _ => return Err("non-numbers on stack with logical and".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, 'O' => if stack.len() > 1 { match (stack.pop().unwrap(), stack.pop().unwrap()) { (Number(0), Number(0)) => stack.push(Number(0)), (Number(_), Number(_)) => stack.push(Number(1)), - _ => return Err("non-numbers on stack with logical or".to_strbuf()) + _ => return Err("non-numbers on stack with logical or".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '!' => if stack.len() > 0 { match stack.pop().unwrap() { Number(0) => stack.push(Number(1)), Number(_) => stack.push(Number(0)), - _ => return Err("non-number on stack with logical not".to_strbuf()) + _ => return Err("non-number on stack with logical not".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, '~' => if stack.len() > 0 { match stack.pop().unwrap() { Number(x) => stack.push(Number(!x)), - _ => return Err("non-number on stack with %~".to_strbuf()) + _ => return Err("non-number on stack with %~".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, 'i' => match (mparams[0].clone(), mparams[1].clone()) { (Number(x), Number(y)) => { mparams[0] = Number(x+1); mparams[1] = Number(y+1); }, - (_, _) => return Err("first two params not numbers with %i".to_strbuf()) + (_, _) => return Err("first two params not numbers with %i".to_string()) }, // printf-style support for %doxXs @@ -249,7 +249,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) let res = format(stack.pop().unwrap(), FormatOp::from_char(cur), flags); if res.is_err() { return res } output.push_all(res.unwrap().as_slice()) - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, ':'|'#'|' '|'.'|'0'..'9' => { let mut flags = Flags::new(); let mut fstate = FormatStateFlags; @@ -274,9 +274,9 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) Number(0) => state = SeekIfElse(0), Number(_) => (), _ => return Err("non-number on stack \ - with conditional".to_strbuf()) + with conditional".to_string()) } - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, 'e' => state = SeekIfEnd(0), ';' => (), @@ -291,7 +291,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) // params are 1-indexed stack.push(mparams[match char::to_digit(cur, 10) { Some(d) => d - 1, - None => return Err("bad param number".to_strbuf()) + None => return Err("bad param number".to_string()) }].clone()); }, SetVar => { @@ -299,14 +299,14 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) if stack.len() > 0 { let idx = (cur as u8) - ('A' as u8); vars.sta[idx as uint] = stack.pop().unwrap(); - } else { return Err("stack is empty".to_strbuf()) } + } else { return Err("stack is empty".to_string()) } } else if cur >= 'a' && cur <= 'z' { if stack.len() > 0 { let idx = (cur as u8) - ('a' as u8); vars.dyn[idx as uint] = stack.pop().unwrap(); - } else { return Err("stack is empty".to_strbuf()) } + } else { return Err("stack is empty".to_string()) } } else { - return Err("bad variable name in %P".to_strbuf()); + return Err("bad variable name in %P".to_string()); } }, GetVar => { @@ -317,7 +317,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) let idx = (cur as u8) - ('a' as u8); stack.push(vars.dyn[idx as uint].clone()); } else { - return Err("bad variable name in %g".to_strbuf()); + return Err("bad variable name in %g".to_string()); } }, CharConstant => { @@ -326,7 +326,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) }, CharClose => { if cur != '\'' { - return Err("malformed character constant".to_strbuf()); + return Err("malformed character constant".to_string()); } }, IntConstant(i) => { @@ -339,7 +339,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) state = IntConstant(i*10 + (cur as int - '0' as int)); old_state = Nothing; } - _ => return Err("bad int constant".to_strbuf()) + _ => return Err("bad int constant".to_string()) } } FormatPattern(ref mut flags, ref mut fstate) => { @@ -350,7 +350,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) if res.is_err() { return res } output.push_all(res.unwrap().as_slice()); old_state = state; // will cause state to go to Nothing - } else { return Err("stack is empty".to_strbuf()) }, + } else { return Err("stack is empty".to_string()) }, (FormatStateFlags,'#') => { flags.alternate = true; } @@ -373,7 +373,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) (FormatStateWidth,'0'..'9') => { let old = flags.width; flags.width = flags.width * 10 + (cur as uint - '0' as uint); - if flags.width < old { return Err("format width overflow".to_strbuf()) } + if flags.width < old { return Err("format width overflow".to_string()) } } (FormatStateWidth,'.') => { *fstate = FormatStatePrecision; @@ -382,10 +382,10 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) let old = flags.precision; flags.precision = flags.precision * 10 + (cur as uint - '0' as uint); if flags.precision < old { - return Err("format precision overflow".to_strbuf()) + return Err("format precision overflow".to_string()) } } - _ => return Err("invalid format specifier".to_strbuf()) + _ => return Err("invalid format specifier".to_string()) } } SeekIfElse(level) => { @@ -493,7 +493,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,String> { (FormatHex, _) => format!("{:x}", d).into_bytes(), (FormatHEX, _) => format!("{:X}", d).into_bytes(), (FormatString, _) => { - return Err("non-number on stack with %s".to_strbuf()) + return Err("non-number on stack with %s".to_string()) } }; let mut s: Vec<u8> = s.move_iter().collect(); @@ -607,7 +607,7 @@ mod test { assert!(res.is_err(), "Op {} succeeded incorrectly with 0 stack entries", *cap); let p = if *cap == "%s" || *cap == "%l" { - String("foo".to_strbuf()) + String("foo".to_string()) } else { Number(97) }; @@ -685,12 +685,12 @@ mod test { let mut varstruct = Variables::new(); let vars = &mut varstruct; assert_eq!(expand(bytes!("%p1%s%p2%2s%p3%2s%p4%.2s"), - [String("foo".to_strbuf()), - String("foo".to_strbuf()), - String("f".to_strbuf()), - String("foo".to_strbuf())], vars), + [String("foo".to_string()), + String("foo".to_string()), + String("f".to_string()), + String("foo".to_string())], vars), Ok(bytes!("foofoo ffo").iter().map(|x| *x).collect())); - assert_eq!(expand(bytes!("%p1%:-4.2s"), [String("foo".to_strbuf())], vars), + assert_eq!(expand(bytes!("%p1%:-4.2s"), [String("foo".to_string())], vars), Ok(bytes!("fo ").iter().map(|x| *x).collect())); assert_eq!(expand(bytes!("%p1%d%p1%.3d%p1%5d%p1%:+d"), [Number(1)], vars), diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index 33589f29624..1a42addb4bd 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -201,29 +201,29 @@ pub fn parse(file: &mut io::Reader, longnames: bool) if (bools_bytes as uint) > boolnames.len() { return Err("incompatible file: more booleans than \ - expected".to_strbuf()); + expected".to_string()); } if (numbers_count as uint) > numnames.len() { return Err("incompatible file: more numbers than \ - expected".to_strbuf()); + expected".to_string()); } if (string_offsets_count as uint) > stringnames.len() { return Err("incompatible file: more string offsets than \ - expected".to_strbuf()); + expected".to_string()); } // don't read NUL let bytes = try!(file.read_exact(names_bytes as uint - 1)); let names_str = match str::from_utf8(bytes.as_slice()) { Some(s) => s.to_string(), - None => return Err("input not utf-8".to_strbuf()), + None => return Err("input not utf-8".to_string()), }; let term_names: Vec<String> = names_str.as_slice() .split('|') - .map(|s| s.to_strbuf()) + .map(|s| s.to_string()) .collect(); try!(file.read_byte()); // consume NUL @@ -233,7 +233,7 @@ pub fn parse(file: &mut io::Reader, longnames: bool) for i in range(0, bools_bytes) { let b = try!(file.read_byte()); if b == 1 { - bools_map.insert(bnames[i as uint].to_strbuf(), true); + bools_map.insert(bnames[i as uint].to_string(), true); } } } @@ -247,7 +247,7 @@ pub fn parse(file: &mut io::Reader, longnames: bool) for i in range(0, numbers_count) { let n = try!(file.read_le_u16()); if n != 0xFFFF { - numbers_map.insert(nnames[i as uint].to_strbuf(), n); + numbers_map.insert(nnames[i as uint].to_string(), n); } } } @@ -264,7 +264,7 @@ pub fn parse(file: &mut io::Reader, longnames: bool) if string_table.len() != string_table_bytes as uint { return Err("error: hit EOF before end of string \ - table".to_strbuf()); + table".to_string()); } for (i, v) in string_offsets.iter().enumerate() { @@ -282,7 +282,7 @@ pub fn parse(file: &mut io::Reader, longnames: bool) if offset == 0xFFFE { // undocumented: FFFE indicates cap@, which means the capability is not present // unsure if the handling for this is correct - string_map.insert(name.to_strbuf(), Vec::new()); + string_map.insert(name.to_string(), Vec::new()); continue; } @@ -292,14 +292,14 @@ pub fn parse(file: &mut io::Reader, longnames: bool) .iter().position(|&b| b == 0); match nulpos { Some(len) => { - string_map.insert(name.to_strbuf(), + string_map.insert(name.to_string(), Vec::from_slice( string_table.slice(offset as uint, offset as uint + len))) }, None => { return Err("invalid file: missing NUL in \ - string_table".to_strbuf()); + string_table".to_string()); } }; } @@ -317,12 +317,12 @@ pub fn parse(file: &mut io::Reader, longnames: bool) /// Create a dummy TermInfo struct for msys terminals pub fn msys_terminfo() -> Box<TermInfo> { let mut strings = HashMap::new(); - strings.insert("sgr0".to_strbuf(), Vec::from_slice(bytes!("\x1b[0m"))); - strings.insert("bold".to_strbuf(), Vec::from_slice(bytes!("\x1b[1m"))); - strings.insert("setaf".to_strbuf(), Vec::from_slice(bytes!("\x1b[3%p1%dm"))); - strings.insert("setab".to_strbuf(), Vec::from_slice(bytes!("\x1b[4%p1%dm"))); + strings.insert("sgr0".to_string(), Vec::from_slice(bytes!("\x1b[0m"))); + strings.insert("bold".to_string(), Vec::from_slice(bytes!("\x1b[1m"))); + strings.insert("setaf".to_string(), Vec::from_slice(bytes!("\x1b[3%p1%dm"))); + strings.insert("setab".to_string(), Vec::from_slice(bytes!("\x1b[4%p1%dm"))); box TermInfo { - names: vec!("cygwin".to_strbuf()), // msys is a fork of an older cygwin version + names: vec!("cygwin".to_string()), // msys is a fork of an older cygwin version bools: HashMap::new(), numbers: HashMap::new(), strings: strings diff --git a/src/libterm/terminfo/searcher.rs b/src/libterm/terminfo/searcher.rs index 5c800c75432..84f0a4e3565 100644 --- a/src/libterm/terminfo/searcher.rs +++ b/src/libterm/terminfo/searcher.rs @@ -40,7 +40,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<Box<Path>> { if i == "" { dirs_to_search.push(Path::new("/usr/share/terminfo")); } else { - dirs_to_search.push(Path::new(i.to_strbuf())); + dirs_to_search.push(Path::new(i.to_string())); } }, // Found nothing in TERMINFO_DIRS, use the default paths: @@ -99,12 +99,12 @@ fn test_get_dbpath_for_term() { // FIXME (#9639): This needs to handle non-utf8 paths fn x(t: &str) -> String { let p = get_dbpath_for_term(t).expect("no terminfo entry found"); - p.as_str().unwrap().to_strbuf() + p.as_str().unwrap().to_string() }; - assert!(x("screen") == "/usr/share/terminfo/s/screen".to_strbuf()); + assert!(x("screen") == "/usr/share/terminfo/s/screen".to_string()); assert!(get_dbpath_for_term("") == None); setenv("TERMINFO_DIRS", ":"); - assert!(x("screen") == "/usr/share/terminfo/s/screen".to_strbuf()); + assert!(x("screen") == "/usr/share/terminfo/s/screen".to_string()); unsetenv("TERMINFO_DIRS"); } |
