Skip to content

Commit c187cbf

Browse files
committed
syntax: add ClassUnicode::is_all_ascii
This mirrors the same routine on ClassBytes. This is useful when translating an HIR to an NFA and one wants to write a fast path for the common all ASCII case.
1 parent 17304c5 commit c187cbf

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

regex-syntax/src/hir/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,13 @@ impl ClassUnicode {
938938
pub fn symmetric_difference(&mut self, other: &ClassUnicode) {
939939
self.set.symmetric_difference(&other.set);
940940
}
941+
942+
/// Returns true if and only if this character class will either match
943+
/// nothing or only ASCII bytes. Stated differently, this returns false
944+
/// if and only if this class contains a non-ASCII codepoint.
945+
pub fn is_all_ascii(&self) -> bool {
946+
self.set.intervals().last().map_or(true, |r| r.end <= '\x7F')
947+
}
941948
}
942949

943950
/// An iterator over all ranges in a Unicode character class.

0 commit comments

Comments
 (0)