diff options
| author | Richo Healey <richo@psych0tik.net> | 2014-04-15 18:17:48 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2014-04-18 17:25:34 -0700 |
| commit | 919889a1d688a6bbe2edac8705f048f06b1b455c (patch) | |
| tree | 322a69fa39bdaf37bbfffc84020acbd4c87871d0 /src/libterm | |
| parent | b75683cadf6c4c55360202cd6a0106be80532451 (diff) | |
| download | rust-919889a1d688a6bbe2edac8705f048f06b1b455c.tar.gz rust-919889a1d688a6bbe2edac8705f048f06b1b455c.zip | |
Replace all ~"" with "".to_owned()
Diffstat (limited to 'src/libterm')
| -rw-r--r-- | src/libterm/lib.rs | 4 | ||||
| -rw-r--r-- | src/libterm/terminfo/parm.rs | 114 | ||||
| -rw-r--r-- | src/libterm/terminfo/parser/compiled.rs | 24 | ||||
| -rw-r--r-- | src/libterm/terminfo/searcher.rs | 4 |
4 files changed, 77 insertions, 69 deletions
diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 84ba122631e..9e3be403065 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -129,7 +129,7 @@ impl<T: Writer> Terminal<T> { pub fn new(out: T) -> Result<Terminal<T>, ~str> { let term = match os::getenv("TERM") { Some(t) => t, - None => return Err(~"TERM environment variable undefined") + None => return Err("TERM environment variable undefined".to_owned()) }; let mut file = match open(term) { @@ -251,7 +251,7 @@ impl<T: Writer> Terminal<T> { cap = self.ti.strings.find_equiv(&("op")); } } - let s = cap.map_or(Err(~"can't find terminfo capability `sgr0`"), |op| { + let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_owned()), |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 408d452adba..993b69be881 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") + _ => return Err("a non-char was used with %c".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '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") + _ => return Err("a non-str was used with %l".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '+' => 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 +") + _ => return Err("non-numbers on stack with +".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '-' => 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 -") + _ => return Err("non-numbers on stack with -".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '*' => 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 *") + _ => return Err("non-numbers on stack with *".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '/' => 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 /") + _ => return Err("non-numbers on stack with /".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '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 %") + _ => return Err("non-numbers on stack with %".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '&' => 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 &") + _ => return Err("non-numbers on stack with &".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '|' => 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 |") + _ => return Err("non-numbers on stack with |".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '^' => 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 ^") + _ => return Err("non-numbers on stack with ^".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '=' => 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 =") + _ => return Err("non-numbers on stack with =".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '>' => 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 >") + _ => return Err("non-numbers on stack with >".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '<' => 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 <") + _ => return Err("non-numbers on stack with <".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '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") + _ => return Err("non-numbers on stack with logical and".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '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") + _ => return Err("non-numbers on stack with logical or".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '!' => 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") + _ => return Err("non-number on stack with logical not".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '~' => if stack.len() > 0 { match stack.pop().unwrap() { Number(x) => stack.push(Number(!x)), - _ => return Err(~"non-number on stack with %~") + _ => return Err("non-number on stack with %~".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, '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") + (_, _) => return Err("first two params not numbers with %i".to_owned()) }, // 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") }, + } else { return Err("stack is empty".to_owned()) }, ':'|'#'|' '|'.'|'0'..'9' => { let mut flags = Flags::new(); let mut fstate = FormatStateFlags; @@ -273,9 +273,10 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) match stack.pop().unwrap() { Number(0) => state = SeekIfElse(0), Number(_) => (), - _ => return Err(~"non-number on stack with conditional") + _ => return Err("non-number on stack \ + with conditional".to_owned()) } - } else { return Err(~"stack is empty") }, + } else { return Err("stack is empty".to_owned()) }, 'e' => state = SeekIfEnd(0), ';' => (), @@ -286,7 +287,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") + None => return Err("bad param number".to_owned()) }].clone()); }, SetVar => { @@ -294,14 +295,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") } + } else { return Err("stack is empty".to_owned()) } } 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") } + } else { return Err("stack is empty".to_owned()) } } else { - return Err(~"bad variable name in %P"); + return Err("bad variable name in %P".to_owned()); } }, GetVar => { @@ -312,7 +313,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"); + return Err("bad variable name in %g".to_owned()); } }, CharConstant => { @@ -321,7 +322,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) }, CharClose => { if cur != '\'' { - return Err(~"malformed character constant"); + return Err("malformed character constant".to_owned()); } }, IntConstant(i) => { @@ -334,7 +335,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") + _ => return Err("bad int constant".to_owned()) } } FormatPattern(ref mut flags, ref mut fstate) => { @@ -345,7 +346,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") }, + } else { return Err("stack is empty".to_owned()) }, (FormatStateFlags,'#') => { flags.alternate = true; } @@ -368,7 +369,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") } + if flags.width < old { return Err("format width overflow".to_owned()) } } (FormatStateWidth,'.') => { *fstate = FormatStatePrecision; @@ -376,9 +377,11 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) (FormatStatePrecision,'0'..'9') => { let old = flags.precision; flags.precision = flags.precision * 10 + (cur as uint - '0' as uint); - if flags.precision < old { return Err(~"format precision overflow") } + if flags.precision < old { + return Err("format precision overflow".to_owned()) + } } - _ => return Err(~"invalid format specifier") + _ => return Err("invalid format specifier".to_owned()) } } SeekIfElse(level) => { @@ -485,7 +488,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,~str> { (FormatOctal, _) => format!("{:o}", d).into_bytes(), (FormatHex, _) => format!("{:x}", d).into_bytes(), (FormatHEX, _) => format!("{:X}", d).into_bytes(), - (FormatString, _) => return Err(~"non-number on stack with %s"), + (FormatString, _) => return Err("non-number on stack with %s".to_owned()), }; let mut s: Vec<u8> = s.move_iter().collect(); if flags.precision > s.len() { @@ -596,7 +599,11 @@ mod test { let res = expand(cap.as_bytes(), [], vars); assert!(res.is_err(), "Op {} succeeded incorrectly with 0 stack entries", *cap); - let p = if *cap == "%s" || *cap == "%l" { String(~"foo") } else { Number(97) }; + let p = if *cap == "%s" || *cap == "%l" { + String("foo".to_owned()) + } else { + Number(97) + }; let res = expand(bytes!("%p1").iter().map(|x| *x).collect::<Vec<_>>() .append(cap.as_bytes()).as_slice(), [p], @@ -671,9 +678,10 @@ 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"), String(~"foo"), String(~"f"), String(~"foo")], vars), + [String("foo".to_owned()), String("foo".to_owned()), + String("f".to_owned()), String("foo".to_owned())], vars), Ok(bytes!("foofoo ffo").iter().map(|x| *x).collect())); - assert_eq!(expand(bytes!("%p1%:-4.2s"), [String(~"foo")], vars), + assert_eq!(expand(bytes!("%p1%:-4.2s"), [String("foo".to_owned())], 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 37ef3c133a5..e27f4652305 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -195,21 +195,21 @@ pub fn parse(file: &mut io::Reader, assert!(names_bytes > 0); if (bools_bytes as uint) > boolnames.len() { - return Err(~"incompatible file: more booleans than expected"); + return Err("incompatible file: more booleans than expected".to_owned()); } if (numbers_count as uint) > numnames.len() { - return Err(~"incompatible file: more numbers than expected"); + return Err("incompatible file: more numbers than expected".to_owned()); } if (string_offsets_count as uint) > stringnames.len() { - return Err(~"incompatible file: more string offsets than expected"); + return Err("incompatible file: more string offsets than expected".to_owned()); } // 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_owned(), None => return Err(~"input not utf-8"), + Some(s) => s.to_owned(), None => return Err("input not utf-8".to_owned()), }; let term_names: Vec<~str> = names_str.split('|').map(|s| s.to_owned()).collect(); @@ -221,7 +221,7 @@ pub fn parse(file: &mut io::Reader, for i in range(0, bools_bytes) { let b = try!(file.read_byte()); if b < 0 { - return Err(~"error: expected more bools but hit EOF"); + return Err("error: expected more bools but hit EOF".to_owned()); } else if b == 1 { bools_map.insert(bnames[i as uint].to_owned(), true); } @@ -253,7 +253,7 @@ pub fn parse(file: &mut io::Reader, let string_table = try!(file.read_exact(string_table_bytes as uint)); if string_table.len() != string_table_bytes as uint { - return Err(~"error: hit EOF before end of string table"); + return Err("error: hit EOF before end of string table".to_owned()); } for (i, v) in string_offsets.iter().enumerate() { @@ -287,7 +287,7 @@ pub fn parse(file: &mut io::Reader, offset as uint + len))) }, None => { - return Err(~"invalid file: missing NUL in string_table"); + return Err("invalid file: missing NUL in string_table".to_owned()); } }; } @@ -300,12 +300,12 @@ pub fn parse(file: &mut io::Reader, /// Create a dummy TermInfo struct for msys terminals pub fn msys_terminfo() -> ~TermInfo { let mut strings = HashMap::new(); - strings.insert(~"sgr0", Vec::from_slice(bytes!("\x1b[0m"))); - strings.insert(~"bold", Vec::from_slice(bytes!("\x1b[1m"))); - strings.insert(~"setaf", Vec::from_slice(bytes!("\x1b[3%p1%dm"))); - strings.insert(~"setab", Vec::from_slice(bytes!("\x1b[4%p1%dm"))); + strings.insert("sgr0".to_owned(), Vec::from_slice(bytes!("\x1b[0m"))); + strings.insert("bold".to_owned(), Vec::from_slice(bytes!("\x1b[1m"))); + strings.insert("setaf".to_owned(), Vec::from_slice(bytes!("\x1b[3%p1%dm"))); + strings.insert("setab".to_owned(), Vec::from_slice(bytes!("\x1b[4%p1%dm"))); ~TermInfo { - names: vec!(~"cygwin"), // msys is a fork of an older cygwin version + names: vec!("cygwin".to_owned()), // 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 b5792c66a0d..12540f52581 100644 --- a/src/libterm/terminfo/searcher.rs +++ b/src/libterm/terminfo/searcher.rs @@ -99,10 +99,10 @@ fn test_get_dbpath_for_term() { let p = get_dbpath_for_term(t).expect("no terminfo entry found"); p.as_str().unwrap().to_owned() }; - assert!(x("screen") == ~"/usr/share/terminfo/s/screen"); + assert!(x("screen") == "/usr/share/terminfo/s/screen".to_owned()); assert!(get_dbpath_for_term("") == None); setenv("TERMINFO_DIRS", ":"); - assert!(x("screen") == ~"/usr/share/terminfo/s/screen"); + assert!(x("screen") == "/usr/share/terminfo/s/screen".to_owned()); unsetenv("TERMINFO_DIRS"); } |
