mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Fix: ends-with (#2034)
This commit is contained in:
parent
5b36b46230
commit
dacab7869f
@ -116,7 +116,22 @@ impl Str {
|
|||||||
match pattern {
|
match pattern {
|
||||||
StrPattern::Str(pat) => self.0.ends_with(pat.as_str()),
|
StrPattern::Str(pat) => self.0.ends_with(pat.as_str()),
|
||||||
StrPattern::Regex(re) => {
|
StrPattern::Regex(re) => {
|
||||||
re.find_iter(self).last().map_or(false, |m| m.end() == self.0.len())
|
let mut start_byte = 0;
|
||||||
|
while let Some(mat) = re.find_at(self, start_byte) {
|
||||||
|
if mat.end() == self.0.len() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// There might still be a match overlapping this one, so
|
||||||
|
// restart at the next code point
|
||||||
|
if let Some(c) = &self[mat.start()..].chars().next() {
|
||||||
|
start_byte = mat.start() + c.len_utf8();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user