Trait pattern_lexer::pattern::Pattern
source · pub trait Pattern<'a> {
// Required method
fn find_in(&self, value: &'a str) -> Vec<Match<'a>>;
// Provided methods
fn find_prefix_in(&self, value: &'a str) -> Vec<Match<'a>> { ... }
fn find_suffix_in(&self, value: &'a str) -> Vec<Match<'a>> { ... }
fn find_one_in(&self, value: &'a str) -> Option<Match<'a>> { ... }
fn find_one_prefix_in(&self, value: &'a str) -> Option<Match<'a>> { ... }
fn find_one_suffix_in(&self, value: &'a str) -> Option<Match<'a>> { ... }
}Expand description
A string Pattern.
The type implementing it can be used as a pattern for rust &str.
By default it is implemented for the following types:
| Pattern type | Match condition |
|––––––––––––––––|—————————————–|
| rust char | is contained in string |
| rust `&str | is substring |
| rust String | is substring |
| rust `&[char] | any char is contained in string |
| rust `&[&str] | any &str is substring |
| rust F: Fn(&str) -> bool | F returns rust true for substring |
| rust Regex | rust Regex match substring |
Required Methods§
Provided Methods§
sourcefn find_prefix_in(&self, value: &'a str) -> Vec<Match<'a>>
fn find_prefix_in(&self, value: &'a str) -> Vec<Match<'a>>
Find all occurences of the pattern in the given value that are prefixes.
Examples
use lexer::pattern::{Match, Pattern};
assert!("ab".find_prefix_in("cdab").is_empty());
assert_eq!("ab".find_prefix_in("abcd"), vec![Match::new("abcd", 0, 2)]);sourcefn find_suffix_in(&self, value: &'a str) -> Vec<Match<'a>>
fn find_suffix_in(&self, value: &'a str) -> Vec<Match<'a>>
Find all occurences of the pattern in the given value that are suffixes.
Examples
use lexer::pattern::{Match, Pattern};
assert!("ab".find_suffix_in("abcd").is_empty());
assert_eq!("ab".find_suffix_in("cdab"), vec![Match::new("cdab", 2, 4)]);sourcefn find_one_in(&self, value: &'a str) -> Option<Match<'a>>
fn find_one_in(&self, value: &'a str) -> Option<Match<'a>>
Find one occurrence of the pattern in the given value.
Examples
use lexer::pattern::{Match, Pattern};
assert!("ab".find_one_in("cd").is_none());
assert_eq!("ab".find_one_in("cdab"), Some(Match::new("cdab", 2, 4)));sourcefn find_one_prefix_in(&self, value: &'a str) -> Option<Match<'a>>
fn find_one_prefix_in(&self, value: &'a str) -> Option<Match<'a>>
Find one occurrence of the pattern in the given value that is prefix.
Examples
use lexer::pattern::{Match, Pattern};
assert!("ab".find_one_prefix_in("cdab").is_none());
assert_eq!("ab".find_one_prefix_in("abcd"), Some(Match::new("abcd", 0, 2)));sourcefn find_one_suffix_in(&self, value: &'a str) -> Option<Match<'a>>
fn find_one_suffix_in(&self, value: &'a str) -> Option<Match<'a>>
Find one occurrence of the pattern in the given value that is suffix.
Examples
use lexer::pattern::{Match, Pattern};
assert!("ab".find_one_suffix_in("abcd").is_none());
assert_eq!("ab".find_one_suffix_in("cdab"), Some(Match::new("cdab", 2, 4)));