From 40920ea9d255f704116064d0b831666c7416caf2 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sun, 28 Mar 2021 00:36:23 -0600 Subject: add (& somewhat test!) GNUful conditionals --- src/makefile/token.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/makefile/token.rs') diff --git a/src/makefile/token.rs b/src/makefile/token.rs index 811f30f..86c442b 100644 --- a/src/makefile/token.rs +++ b/src/makefile/token.rs @@ -47,6 +47,13 @@ impl TokenString { None } + pub(crate) fn starts_with(&self, pattern: &str) -> bool { + match self.0.first() { + Some(Token::Text(t)) => t.starts_with(pattern), + _ => false, + } + } + pub(crate) fn ends_with(&self, pattern: &str) -> bool { match self.0.last() { Some(Token::Text(t)) => t.ends_with(pattern), @@ -54,6 +61,14 @@ impl TokenString { } } + pub(crate) fn strip_prefix(&mut self, suffix: &str) { + if let Some(Token::Text(t)) = self.0.first_mut() { + if let Some(x) = t.strip_prefix(suffix) { + *t = x.into() + } + } + } + pub(crate) fn strip_suffix(&mut self, suffix: &str) { if let Some(Token::Text(t)) = self.0.last_mut() { if let Some(x) = t.strip_suffix(suffix) { @@ -71,6 +86,12 @@ impl TokenString { *t = t.trim_start().into(); } } + + pub(crate) fn trim_end(&mut self) { + if let Some(Token::Text(t)) = self.0.last_mut() { + *t = t.trim_end().into(); + } + } } impl fmt::Display for TokenString { -- cgit v1.2.3