aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/token.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-03-28 00:36:23 -0600
committerMelody Horn <melody@boringcactus.com>2021-03-28 00:36:23 -0600
commit40920ea9d255f704116064d0b831666c7416caf2 (patch)
treebd0021cec78eb94cb2cb998c638d6b4cb52e3484 /src/makefile/token.rs
parent2cd4d0f968c8097566edc0c6fbee10baf4b2647a (diff)
downloadmakers-40920ea9d255f704116064d0b831666c7416caf2.tar.gz
makers-40920ea9d255f704116064d0b831666c7416caf2.zip
add (& somewhat test!) GNUful conditionals
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 {