refactor check_for_substitution

No behavior change, just flatter and simpler code
This commit is contained in:
Aleksey Kladov
2019-07-02 11:06:01 +03:00
parent 40ab9d2bd5
commit dc088b26ce
2 changed files with 72 additions and 67 deletions

View File

@@ -84,28 +84,6 @@ impl<'a> StringReader<'a> {
Ok(ret_val)
}
/// Immutably extract string if found at current position with given delimiters
fn peek_delimited(&self, from_ch: char, to_ch: char) -> Option<String> {
let mut pos = self.pos;
let mut idx = self.src_index(pos);
let mut ch = char_at(&self.src, idx);
if ch != from_ch {
return None;
}
pos = pos + Pos::from_usize(ch.len_utf8());
let start_pos = pos;
idx = self.src_index(pos);
while idx < self.end_src_index {
ch = char_at(&self.src, idx);
if ch == to_ch {
return Some(self.src[self.src_index(start_pos)..self.src_index(pos)].to_string());
}
pos = pos + Pos::from_usize(ch.len_utf8());
idx = self.src_index(pos);
}
return None;
}
fn try_real_token(&mut self) -> Result<Token, ()> {
let mut t = self.try_next_token()?;
loop {