about summary refs log tree commit diff
path: root/src/libterm/terminfo/parser
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2014-05-13 17:26:41 -0700
committerPatrick Walton <pcwalton@mimiga.net>2014-05-14 18:29:13 -0700
commitded860c0e89e6f33dece7f65bb71419b515314eb (patch)
tree0faf10cc076c3ead5da9ae4c1c252e2fd611e332 /src/libterm/terminfo/parser
parent93499b1eaf74a58ff7de3ac9240afc4796ef57c8 (diff)
downloadrust-ded860c0e89e6f33dece7f65bb71419b515314eb.tar.gz
rust-ded860c0e89e6f33dece7f65bb71419b515314eb.zip
libterm: Remove all uses of `~str` from `libterm`
Diffstat (limited to 'src/libterm/terminfo/parser')
-rw-r--r--src/libterm/terminfo/parser/compiled.rs53
1 files changed, 33 insertions, 20 deletions
diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs
index 2b50a20ac6a..5a1c8ea02e2 100644
--- a/src/libterm/terminfo/parser/compiled.rs
+++ b/src/libterm/terminfo/parser/compiled.rs
@@ -160,9 +160,12 @@ pub static stringnames: &'static[&'static str] = &'static[ "cbt", "_", "cr", "cs
 
 /// Parse a compiled terminfo entry, using long capability names if `longnames` is true
 pub fn parse(file: &mut io::Reader, longnames: bool)
-             -> Result<Box<TermInfo>, ~str> {
+             -> Result<Box<TermInfo>, StrBuf> {
     macro_rules! try( ($e:expr) => (
-        match $e { Ok(e) => e, Err(e) => return Err(format!("{}", e)) }
+        match $e {
+            Ok(e) => e,
+            Err(e) => return Err(format_strbuf!("{}", e))
+        }
     ) )
 
     let bnames;
@@ -182,8 +185,10 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
     // Check magic number
     let magic = try!(file.read_le_u16());
     if magic != 0x011A {
-        return Err(format!("invalid magic number: expected {:x} but found {:x}",
-                           0x011A, magic as uint));
+        return Err(format_strbuf!("invalid magic number: expected {:x} but \
+                                   found {:x}",
+                                  0x011A,
+                                  magic as uint));
     }
 
     let names_bytes          = try!(file.read_le_i16()) as int;
@@ -195,24 +200,30 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
     assert!(names_bytes          > 0);
 
     if (bools_bytes as uint) > boolnames.len() {
-        return Err("incompatible file: more booleans than expected".to_owned());
+        return Err("incompatible file: more booleans than \
+                    expected".to_strbuf());
     }
 
     if (numbers_count as uint) > numnames.len() {
-        return Err("incompatible file: more numbers than expected".to_owned());
+        return Err("incompatible file: more numbers than \
+                    expected".to_strbuf());
     }
 
     if (string_offsets_count as uint) > stringnames.len() {
-        return Err("incompatible file: more string offsets than expected".to_owned());
+        return Err("incompatible file: more string offsets than \
+                    expected".to_strbuf());
     }
 
     // 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".to_owned()),
+        Some(s) => s.to_owned(),
+        None => return Err("input not utf-8".to_strbuf()),
     };
 
-    let term_names: Vec<~str> = names_str.split('|').map(|s| s.to_owned()).collect();
+    let term_names: Vec<StrBuf> = names_str.split('|')
+                                           .map(|s| s.to_strbuf())
+                                           .collect();
 
     try!(file.read_byte()); // consume NUL
 
@@ -221,7 +232,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_owned(), true);
+                bools_map.insert(bnames[i as uint].to_strbuf(), true);
             }
         }
     }
@@ -235,7 +246,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_owned(), n);
+                numbers_map.insert(nnames[i as uint].to_strbuf(), n);
             }
         }
     }
@@ -251,7 +262,8 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
         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".to_owned());
+            return Err("error: hit EOF before end of string \
+                        table".to_strbuf());
         }
 
         for (i, v) in string_offsets.iter().enumerate() {
@@ -269,7 +281,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_owned(), Vec::new());
+                string_map.insert(name.to_strbuf(), Vec::new());
                 continue;
             }
 
@@ -279,13 +291,14 @@ pub fn parse(file: &mut io::Reader, longnames: bool)
                 .iter().position(|&b| b == 0);
             match nulpos {
                 Some(len) => {
-                    string_map.insert(name.to_owned(),
+                    string_map.insert(name.to_strbuf(),
                                       Vec::from_slice(
                                           string_table.slice(offset as uint,
                                           offset as uint + len)))
                 },
                 None => {
-                    return Err("invalid file: missing NUL in string_table".to_owned());
+                    return Err("invalid file: missing NUL in \
+                                string_table".to_strbuf());
                 }
             };
         }
@@ -303,12 +316,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_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")));
+    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")));
     box TermInfo {
-        names: vec!("cygwin".to_owned()), // msys is a fork of an older cygwin version
+        names: vec!("cygwin".to_strbuf()), // msys is a fork of an older cygwin version
         bools: HashMap::new(),
         numbers: HashMap::new(),
         strings: strings