From 1fcc81291dcc3a23fedc853d7d036a3191d37675 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 1 Apr 2013 20:38:04 -0500 Subject: actually, these can all be method calls --- src/term.rs | 29 ++++++++++++++--------------- src/util.rs | 22 +++++++++++----------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/term.rs b/src/term.rs index 575be96..a9f09bc 100644 --- a/src/term.rs +++ b/src/term.rs @@ -69,39 +69,38 @@ fn Writer (cleanup: bool) -> Writer { impl Writer { fn clear (&mut self) { - str::push_str(&mut self.buf, escape("clear")); + self.buf.push_str(escape("clear")); } fn move (&mut self, col: uint, row: uint) { if col == 0u && row == 0u { - str::push_str(&mut self.buf, escape("home")); + self.buf.push_str(escape("home")); } else { - str::push_str(&mut self.buf, - escape2("cup", row as int, col as int)); + self.buf.push_str(escape2("cup", row as int, col as int)); } } fn cursor (&mut self, enabled: bool) { if enabled { - str::push_str(&mut self.buf, escape("civis")); + self.buf.push_str(escape("civis")); } else { - str::push_str(&mut self.buf, escape("cnorm")); + self.buf.push_str(escape("cnorm")); } } fn alternate_screen (&mut self, enable: bool) { if enable { - str::push_str(&mut self.buf, escape("smcup")); + self.buf.push_str(escape("smcup")); } else { - str::push_str(&mut self.buf, escape("rmcup")); + self.buf.push_str(escape("rmcup")); } } fn write (&mut self, text: &str) { - str::push_str(&mut self.buf, text); + self.buf.push_str(text); } fn flush (&mut self) { @@ -151,7 +150,7 @@ pub fn Reader (cleanup: bool) -> Reader { impl Reader { fn read (&mut self) -> Option { - if str::len(self.buf) > 0 { + if self.buf.len() > 0 { return Some(self.next_key()); } @@ -183,7 +182,7 @@ impl Reader { } match util::timed_read(1000000) { - Some(next) => { str::push_char(&mut buf, next) } + Some(next) => { buf.push_char(next) } None => { self.unget(buf); return self.read(); @@ -193,13 +192,13 @@ impl Reader { } fn unget (&mut self, buf: &str) { - str::push_str(&mut self.buf, buf); + self.buf.push_str(buf); } fn next_key (&mut self) -> Keypress { - assert!(str::len(self.buf) > 0); - for uint::range_rev(str::len(self.buf), 0) |i| { - match self.escapes.find(str::slice(self.buf, 0, i)) { + assert!(self.buf.len() > 0); + for uint::range_rev(self.buf.len(), 0) |i| { + match self.escapes.find(self.buf.slice(0, i)) { &Some(k) => { for uint::range(0, i) |_| { str::shift_char(&mut self.buf); diff --git a/src/util.rs b/src/util.rs index 387f6ca..ea3f638 100644 --- a/src/util.rs +++ b/src/util.rs @@ -72,14 +72,14 @@ fn TrieNode () -> TrieNode { impl Trie { pub fn insert (&mut self, s: &str, v: T) { - if str::len(s) == 0 { + if s.len() == 0 { self.root.value = Some(v); } else { let bytes = str::as_bytes_slice(s); self.insert_vec( &mut self.root.children[bytes[0]], - vec::tail(bytes), + bytes.tail(), v ); } @@ -89,7 +89,7 @@ impl Trie { let bytes = str::as_bytes_slice(s); let (prefix_length, node) = self.root.find_prefix_trie(bytes); - if prefix_length == vec::len(bytes) { + if prefix_length == bytes.len() { &node.value } else { @@ -100,8 +100,8 @@ impl Trie { pub fn has_prefix (&self, s: &str) -> bool { let bytes = str::as_bytes_slice(s); let (prefix_length, node) = self.root.find_prefix_trie(bytes); - if prefix_length == vec::len(bytes) { - vec::any(node.children, |child| { child.is_some() }) + if prefix_length == bytes.len() { + node.children.any(|child| { child.is_some() }) } else { false @@ -117,11 +117,11 @@ impl Trie { None => ~TrieNode(), }; - if vec::len(bytes) == 0 { + if bytes.len() == 0 { new.value = Some(v); } else { - self.insert_vec(&mut new.children[bytes[0]], vec::tail(bytes), v); + self.insert_vec(&mut new.children[bytes[0]], bytes.tail(), v); } *loc = Some(new); @@ -130,14 +130,14 @@ impl Trie { impl TrieNode { fn find_prefix_trie (&self, bytes: &[u8]) -> (uint, &'self TrieNode) { - if vec::len(bytes) == 0 { + if bytes.len() == 0 { (0u, self) } else { match self.children[bytes[0]] { Some(ref t) => { let (prefix_length, node) = t.find_prefix_trie( - vec::tail(bytes) + bytes.tail() ); (prefix_length + 1, node) } @@ -236,10 +236,10 @@ pub fn timed_read (timeout: int) -> Option { if next < 0 { return None; } - vec::push(&mut buf, next as u8); + buf.push(next as u8); } - Some(str::char_at(unsafe { str::raw::from_bytes(buf) }, 0)) + Some(unsafe { str::raw::from_bytes(buf) }.char_at(0)) } extern mod io_helper { -- cgit v1.2.3-54-g00ecf