about summary refs log tree commit diff
path: root/src/libterm/terminfo
diff options
context:
space:
mode:
authorAndre Bogus <bogusandre@gmail.com>2015-09-08 00:36:29 +0200
committerAndre Bogus <bogusandre@gmail.com>2015-09-08 00:36:29 +0200
commit9cca96545faf2cfc972cc67b83deae2a78935c43 (patch)
treeef675da82a1ce1b23173921957f6a6a167ad8db8 /src/libterm/terminfo
parent7bf626a68045be1d1a4fac9a635113bb7775b6bb (diff)
downloadrust-9cca96545faf2cfc972cc67b83deae2a78935c43.tar.gz
rust-9cca96545faf2cfc972cc67b83deae2a78935c43.zip
some more clippy-based improvements
Diffstat (limited to 'src/libterm/terminfo')
-rw-r--r--src/libterm/terminfo/mod.rs8
-rw-r--r--src/libterm/terminfo/parm.rs102
-rw-r--r--src/libterm/terminfo/parser/compiled.rs30
3 files changed, 70 insertions, 70 deletions
diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs
index 4840cd1fdda..ffe896b93a7 100644
--- a/src/libterm/terminfo/mod.rs
+++ b/src/libterm/terminfo/mod.rs
@@ -151,7 +151,7 @@ impl<T: Write+Send+'static> Terminal<T> for TerminfoTerminal<T> {
                 cap = self.ti.strings.get("op");
             }
         }
-        let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_string()), |op| {
+        let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_owned()), |op| {
             expand(op, &[], &mut Variables::new())
         });
         if s.is_ok() {
@@ -211,9 +211,9 @@ impl<T: Write+Send+'static> TerminfoTerminal<T> {
                      inf.numbers.get("colors").map_or(0, |&n| n)
                  } else { 0 };
 
-        return Some(box TerminfoTerminal {out: out,
-                                          ti: inf,
-                                          num_colors: nc});
+        Some(box TerminfoTerminal {out: out,
+                                   ti: inf,
+                                   num_colors: nc})
     }
 
     fn dim_if_necessary(&self, color: color::Color) -> color::Color {
diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs
index 14a9d2677e2..9110be33907 100644
--- a/src/libterm/terminfo/parm.rs
+++ b/src/libterm/terminfo/parm.rs
@@ -133,9 +133,9 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
                                     c as u8
                                 })
                             }
-                            _       => return Err("a non-char was used with %c".to_string())
+                            _       => return Err("a non-char was used with %c".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } else { return Err("stack is empty".to_owned()) },
                     'p' => state = PushParam,
                     'P' => state = SetVar,
                     'g' => state = GetVar,
@@ -144,112 +144,112 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
                     'l' => if !stack.is_empty() {
                         match stack.pop().unwrap() {
                             Words(s) => stack.push(Number(s.len() as isize)),
-                            _        => return Err("a non-str was used with %l".to_string())
+                            _        => return Err("a non-str was used with %l".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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 +".to_string())
+                            _ => return Err("non-numbers on stack with +".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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 -".to_string())
+                            _ => return Err("non-numbers on stack with -".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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 *".to_string())
+                            _ => return Err("non-numbers on stack with *".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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 /".to_string())
+                            _ => return Err("non-numbers on stack with /".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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 %".to_string())
+                            _ => return Err("non-numbers on stack with %".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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 &".to_string())
+                            _ => return Err("non-numbers on stack with &".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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 |".to_string())
+                            _ => return Err("non-numbers on stack with |".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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 ^".to_string())
+                            _ => return Err("non-numbers on stack with ^".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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 =".to_string())
+                            _ => return Err("non-numbers on stack with =".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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 >".to_string())
+                            _ => return Err("non-numbers on stack with >".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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 <".to_string())
+                            _ => return Err("non-numbers on stack with <".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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".to_string())
+                            _ => return Err("non-numbers on stack with logical and".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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".to_string())
+                            _ => return Err("non-numbers on stack with logical or".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } else { return Err("stack is empty".to_owned()) },
                     '!' => if !stack.is_empty() {
                         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_string())
+                            _ => return Err("non-number on stack with logical not".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } else { return Err("stack is empty".to_owned()) },
                     '~' => if !stack.is_empty() {
                         match stack.pop().unwrap() {
                             Number(x) => stack.push(Number(!x)),
-                            _         => return Err("non-number on stack with %~".to_string())
+                            _         => return Err("non-number on stack with %~".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } 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".to_string())
+                        (_, _) => return Err("first two params not numbers with %i".to_owned())
                     },
 
                     // printf-style support for %doxXs
@@ -258,7 +258,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())
-                    } else { return Err("stack is empty".to_string()) },
+                    } else { return Err("stack is empty".to_owned()) },
                     ':'|'#'|' '|'.'|'0'...'9' => {
                         let mut flags = Flags::new();
                         let mut fstate = FormatStateFlags;
@@ -283,9 +283,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_string())
+                                                    with conditional".to_owned())
                         }
-                    } else { return Err("stack is empty".to_string()) },
+                    } else { return Err("stack is empty".to_owned()) },
                     'e' => state = SeekIfEnd(0),
                     ';' => (),
 
@@ -298,7 +298,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
                 // params are 1-indexed
                 stack.push(mparams[match cur.to_digit(10) {
                     Some(d) => d as usize - 1,
-                    None => return Err("bad param number".to_string())
+                    None => return Err("bad param number".to_owned())
                 }].clone());
             },
             SetVar => {
@@ -306,14 +306,14 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
                     if !stack.is_empty() {
                         let idx = (cur as u8) - b'A';
                         vars.sta[idx as usize] = stack.pop().unwrap();
-                    } else { return Err("stack is empty".to_string()) }
+                    } else { return Err("stack is empty".to_owned()) }
                 } else if cur >= 'a' && cur <= 'z' {
                     if !stack.is_empty() {
                         let idx = (cur as u8) - b'a';
                         vars.dyn[idx as usize] = stack.pop().unwrap();
-                    } else { return Err("stack is empty".to_string()) }
+                    } else { return Err("stack is empty".to_owned()) }
                 } else {
-                    return Err("bad variable name in %P".to_string());
+                    return Err("bad variable name in %P".to_owned());
                 }
             },
             GetVar => {
@@ -324,7 +324,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
                     let idx = (cur as u8) - b'a';
                     stack.push(vars.dyn[idx as usize].clone());
                 } else {
-                    return Err("bad variable name in %g".to_string());
+                    return Err("bad variable name in %g".to_owned());
                 }
             },
             CharConstant => {
@@ -333,7 +333,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
             },
             CharClose => {
                 if cur != '\'' {
-                    return Err("malformed character constant".to_string());
+                    return Err("malformed character constant".to_owned());
                 }
             },
             IntConstant(i) => {
@@ -346,7 +346,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
                         state = IntConstant(i*10 + (cur as isize - '0' as isize));
                         old_state = Nothing;
                     }
-                    _ => return Err("bad isize constant".to_string())
+                    _ => return Err("bad isize constant".to_owned())
                 }
             }
             FormatPattern(ref mut flags, ref mut fstate) => {
@@ -358,7 +358,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
                         output.push_all(&res.unwrap());
                         // will cause state to go to Nothing
                         old_state = FormatPattern(*flags, *fstate);
-                    } else { return Err("stack is empty".to_string()) },
+                    } else { return Err("stack is empty".to_owned()) },
                     (FormatStateFlags,'#') => {
                         flags.alternate = true;
                     }
@@ -381,7 +381,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 usize - '0' as usize);
-                        if flags.width < old { return Err("format width overflow".to_string()) }
+                        if flags.width < old { return Err("format width overflow".to_owned()) }
                     }
                     (FormatStateWidth,'.') => {
                         *fstate = FormatStatePrecision;
@@ -390,10 +390,10 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables)
                         let old = flags.precision;
                         flags.precision = flags.precision * 10 + (cur as usize - '0' as usize);
                         if flags.precision < old {
-                            return Err("format precision overflow".to_string())
+                            return Err("format precision overflow".to_owned())
                         }
                     }
-                    _ => return Err("invalid format specifier".to_string())
+                    _ => return Err("invalid format specifier".to_owned())
                 }
             }
             SeekIfElse(level) => {
@@ -502,7 +502,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_string())
+                    return Err("non-number on stack with %s".to_owned())
                 }
             };
             let mut s: Vec<u8> = s.into_iter().collect();
@@ -692,7 +692,7 @@ mod tests {
                             Words("f".to_string()),
                             Words("foo".to_string())], vars),
                    Ok("foofoo ffo".bytes().collect::<Vec<_>>()));
-        assert_eq!(expand(b"%p1%:-4.2s", &[Words("foo".to_string())], vars),
+        assert_eq!(expand(b"%p1%:-4.2s", &[Words("foo".to_owned())], vars),
                    Ok("fo  ".bytes().collect::<Vec<_>>()));
 
         assert_eq!(expand(b"%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 f71f7f7aac5..d29042ae5e7 100644
--- a/src/libterm/terminfo/parser/compiled.rs
+++ b/src/libterm/terminfo/parser/compiled.rs
@@ -205,28 +205,28 @@ pub fn parse(file: &mut Read, longnames: bool)
 
     if (bools_bytes as usize) > boolnames.len() {
         return Err("incompatible file: more booleans than \
-                    expected".to_string());
+                    expected".to_owned());
     }
 
     if (numbers_count as usize) > numnames.len() {
         return Err("incompatible file: more numbers than \
-                    expected".to_string());
+                    expected".to_owned());
     }
 
     if (string_offsets_count as usize) > stringnames.len() {
         return Err("incompatible file: more string offsets than \
-                    expected".to_string());
+                    expected".to_owned());
     }
 
     // don't read NUL
     let bytes = try!(read_exact(file, names_bytes as usize - 1));
     let names_str = match String::from_utf8(bytes) {
         Ok(s)  => s,
-        Err(_) => return Err("input not utf-8".to_string()),
+        Err(_) => return Err("input not utf-8".to_owned()),
     };
 
     let term_names: Vec<String> = names_str.split('|')
-                                           .map(|s| s.to_string())
+                                           .map(str::to_owned)
                                            .collect();
 
     try!(read_byte(file)); // consume NUL
@@ -236,7 +236,7 @@ pub fn parse(file: &mut Read, longnames: bool)
         for i in 0..bools_bytes {
             let b = try!(read_byte(file));
             if b == 1 {
-                bools_map.insert(bnames[i as usize].to_string(), true);
+                bools_map.insert(bnames[i as usize].to_owned(), true);
             }
         }
     }
@@ -250,7 +250,7 @@ pub fn parse(file: &mut Read, longnames: bool)
         for i in 0..numbers_count {
             let n = try!(read_le_u16(file));
             if n != 0xFFFF {
-                numbers_map.insert(nnames[i as usize].to_string(), n);
+                numbers_map.insert(nnames[i as usize].to_owned(), n);
             }
         }
     }
@@ -267,7 +267,7 @@ pub fn parse(file: &mut Read, longnames: bool)
 
         if string_table.len() != string_table_bytes as usize {
             return Err("error: hit EOF before end of string \
-                        table".to_string());
+                        table".to_owned());
         }
 
         for (i, v) in string_offsets.iter().enumerate() {
@@ -285,7 +285,7 @@ pub fn parse(file: &mut Read, 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_string(), Vec::new());
+                string_map.insert(name.to_owned(), Vec::new());
                 continue;
             }
 
@@ -301,7 +301,7 @@ pub fn parse(file: &mut Read, longnames: bool)
                 },
                 None => {
                     return Err("invalid file: missing NUL in \
-                                string_table".to_string());
+                                string_table".to_owned());
                 }
             };
         }
@@ -338,12 +338,12 @@ fn read_exact<R: Read + ?Sized>(r: &mut R, sz: usize) -> io::Result<Vec<u8>> {
 /// Create a dummy TermInfo struct for msys terminals
 pub fn msys_terminfo() -> Box<TermInfo> {
     let mut strings = HashMap::new();
-    strings.insert("sgr0".to_string(), b"\x1B[0m".to_vec());
-    strings.insert("bold".to_string(), b"\x1B[1m".to_vec());
-    strings.insert("setaf".to_string(), b"\x1B[3%p1%dm".to_vec());
-    strings.insert("setab".to_string(), b"\x1B[4%p1%dm".to_vec());
+    strings.insert("sgr0".to_owned(), b"\x1B[0m".to_vec());
+    strings.insert("bold".to_owned(), b"\x1B[1m".to_vec());
+    strings.insert("setaf".to_owned(), b"\x1B[3%p1%dm".to_vec());
+    strings.insert("setab".to_owned(), b"\x1B[4%p1%dm".to_vec());
     box TermInfo {
-        names: vec!("cygwin".to_string()), // 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