diff options
Diffstat (limited to 'src/makefile/token.rs')
-rw-r--r-- | src/makefile/token.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/makefile/token.rs b/src/makefile/token.rs index dad4694..7b88823 100644 --- a/src/makefile/token.rs +++ b/src/makefile/token.rs @@ -155,6 +155,19 @@ impl TokenString { } }) } + + /// Returns (token index within string, pattern index within token). + pub fn find(&self, pattern: &str) -> Option<(usize, usize)> { + self.0 + .iter() + .enumerate() + .find_map(|(token_index, token)| match token { + Token::Text(text) => text + .find(pattern) + .map(|pattern_index| (token_index, pattern_index)), + _ => None, + }) + } } impl fmt::Display for TokenString { |