update to handle strings as lists.

This commit is contained in:
Mark Thom
2018-08-22 00:26:48 -06:00
parent 013eb29e2b
commit f861b7a80e
14 changed files with 187 additions and 60 deletions

View File

@@ -18,7 +18,7 @@ impl Hash for StringListWrapper {
pub struct StringList {
body: TabledRc<StringListWrapper>,
cursor: usize, // use this to generate a chars() iterator on the fly,
// and skip over the first cursor chars.
// and skip over the first cursor chars.
expandable: bool
}
@@ -63,17 +63,32 @@ impl StringList {
}
}
#[inline]
pub fn cursor(&self) -> usize {
self.cursor
}
#[inline]
pub fn head(&self) -> Option<char> {
self.borrow()[self.cursor ..].chars().next()
}
#[inline]
pub fn tail(&self) -> Self {
let mut new_string_list = self.clone();
if let Some(c) = self.borrow()[self.cursor ..].chars().next() {
if let Some(c) = self.head() {
new_string_list.cursor += c.len_utf8();
}
new_string_list
}
#[inline]
pub fn is_empty(&self) -> bool {
self.borrow().len() == self.cursor
}
#[inline]
pub fn borrow(&self) -> Ref<String> {
self.body.0.borrow()