Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: optimise single-character groups into a single character #4

Open
kyranet opened this issue Apr 18, 2024 · 0 comments · May be fixed by #11
Open

request: optimise single-character groups into a single character #4

kyranet opened this issue Apr 18, 2024 · 0 comments · May be fixed by #11
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@kyranet
Copy link
Member

kyranet commented Apr 18, 2024

If a single (or group of duplicated characters) entry is wrapped inside [], e.g. [e] or [ee], it should check whether or not the group has one character, and if it does, create a WordPart::Single instead.

word-match/src/word.rs

Lines 70 to 98 in 8ceb4f2

GROUP_START => {
// Found '['
let mut group: Vec<char> = Vec::new();
loop {
match chars.next() {
// If ']' is found, it is the end of the Group
Some(GROUP_END) => {
break;
}
// If '\' is found, it is an escape character, read the next character
Some(ESCAPE) => {
if let Some(c) = chars.next() {
group.push(c);
}
}
// If a character is found, add it to the Group
Some(c) => {
if !group.contains(&c) {
group.push(c);
}
}
// If the end of the word is reached, return an error
None => {
return Err(Error::new(Status::GenericFailure, "Unterminated character group"));
}
}
}
WordPart::Group(group)

@kyranet kyranet added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers and removed help wanted Extra attention is needed labels Apr 18, 2024
@kyranet kyranet linked a pull request May 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant