aboutsummaryrefslogtreecommitdiffstats
path: root/src/regex
diff options
context:
space:
mode:
Diffstat (limited to 'src/regex')
-rw-r--r--src/regex/byte_range.rs48
-rw-r--r--src/regex/enfa.rs2
2 files changed, 32 insertions, 18 deletions
diff --git a/src/regex/byte_range.rs b/src/regex/byte_range.rs
index b7642c1..5123da5 100644
--- a/src/regex/byte_range.rs
+++ b/src/regex/byte_range.rs
@@ -36,45 +36,43 @@ impl ByteRange {
if ranges.is_empty() {
return vec![];
}
-
- let mut points: Vec<u8> = Vec::new();
+
+ let mut points: Vec<u16> = Vec::new();
for r in &ranges {
- points.push(r.from);
- if r.to != u8::MAX {
- points.push(r.to + 1);
- }
+ points.push(r.from as u16);
+ points.push((r.to as u16) + 1);
}
-
+
points.sort_unstable();
points.dedup();
-
+
let mut out = Vec::new();
-
+
for window in points.windows(2) {
let start = window[0];
let end_exclusive = window[1];
-
+
if start >= end_exclusive {
continue;
}
-
+
let mut active = false;
-
+
for r in &ranges {
- if r.from <= start && start <= r.to {
+ if r.from as u16 <= start && start <= r.to as u16 {
active = true;
break;
}
}
-
+
if active {
out.push(ByteRange {
- from: start,
- to: end_exclusive - 1,
+ from: start as u8,
+ to: (end_exclusive - 1) as u8,
});
}
}
-
+
out
}
}
@@ -94,6 +92,22 @@ fn byterange_test() {
);
}
+#[test]
+fn byterange_test_0_128() {
+ assert_eq!(
+ ByteRange::split_to_disjoint(vec![ByteRange::new_range(0, 128)]),
+ vec![ByteRange::new_range(0, 128)]
+ );
+}
+
+#[test]
+fn byterange_test_0_255() {
+ assert_eq!(
+ ByteRange::split_to_disjoint(vec![ByteRange::new_range(0, 255)]),
+ vec![ByteRange::new_range(0, 255)]
+ );
+}
+
impl std::fmt::Debug for ByteRange {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.from == self.to {
diff --git a/src/regex/enfa.rs b/src/regex/enfa.rs
index c740915..ea3bc93 100644
--- a/src/regex/enfa.rs
+++ b/src/regex/enfa.rs
@@ -664,7 +664,7 @@ impl TryFrom<Pattern> for ENFA {
has_submatches: false,
},
Pattern::CharacterClass(Class::Everything) => {
- Self::try_from(Pattern::Range(0, 254))?
+ Self::try_from(Pattern::Range(0, 255))?
}
Pattern::CharacterClass(_) => {
return Err(EnfaTranslationError::CharacterClassNotSupported);