mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-09-14 16:31:03 +03:00
improve id wildcast
This commit is contained in:
@@ -6817,12 +6817,12 @@ fn wildcard_match(pattern: &str, text: &str) -> bool {
|
|||||||
let (mut pi, mut ti) = (0, 0);
|
let (mut pi, mut ti) = (0, 0);
|
||||||
let mut star: Option<(usize, usize)> = None;
|
let mut star: Option<(usize, usize)> = None;
|
||||||
while ti < t.len() {
|
while ti < t.len() {
|
||||||
if pi < p.len() && (p[pi] == '?' || p[pi] == t[ti]) {
|
if pi < p.len() && p[pi] == '*' {
|
||||||
pi += 1;
|
|
||||||
ti += 1;
|
|
||||||
} else if pi < p.len() && p[pi] == '*' {
|
|
||||||
star = Some((pi + 1, ti));
|
star = Some((pi + 1, ti));
|
||||||
pi += 1;
|
pi += 1;
|
||||||
|
} else if pi < p.len() && (p[pi] == '?' || p[pi] == t[ti]) {
|
||||||
|
pi += 1;
|
||||||
|
ti += 1;
|
||||||
} else if let Some((sp, st)) = star {
|
} else if let Some((sp, st)) = star {
|
||||||
pi = sp;
|
pi = sp;
|
||||||
ti = st + 1;
|
ti = st + 1;
|
||||||
@@ -6854,8 +6854,10 @@ mod test {
|
|||||||
// '*' matches any sequence.
|
// '*' matches any sequence.
|
||||||
assert!(wildcard_match("*", "123456789"));
|
assert!(wildcard_match("*", "123456789"));
|
||||||
assert!(wildcard_match("*", ""));
|
assert!(wildcard_match("*", ""));
|
||||||
|
assert!(wildcard_match("*", "*abc"));
|
||||||
assert!(wildcard_match("123*", "123456789"));
|
assert!(wildcard_match("123*", "123456789"));
|
||||||
assert!(wildcard_match("123*", "123"));
|
assert!(wildcard_match("123*", "123"));
|
||||||
|
assert!(wildcard_match("12*", "12*9"));
|
||||||
assert!(!wildcard_match("123*", "124456789"));
|
assert!(!wildcard_match("123*", "124456789"));
|
||||||
assert!(wildcard_match("*789", "123456789"));
|
assert!(wildcard_match("*789", "123456789"));
|
||||||
assert!(wildcard_match("1*9", "123456789"));
|
assert!(wildcard_match("1*9", "123456789"));
|
||||||
|
|||||||
Reference in New Issue
Block a user