aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/token.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/makefile/token.rs')
-rw-r--r--src/makefile/token.rs21
1 files changed, 21 insertions, 0 deletions
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 {