MCPcopy Create free account
hub / github.com/davidblewett/rure-python / difference

Method difference

regex/regex-syntax/src/hir/interval.rs:380–407  ·  view source on GitHub ↗

Subtract the given range from this range and return the resulting ranges. If subtraction would result in an empty range, then no ranges are returned.

(&self, other: &Self)

Source from the content-addressed store, hash-verified

378 /// If subtraction would result in an empty range, then no ranges are
379 /// returned.
380 fn difference(&self, other: &Self) -> (Option<Self>, Option<Self>) {
381 if self.is_subset(other) {
382 return (None, None);
383 }
384 if self.is_intersection_empty(other) {
385 return (Some(self.clone()), None);
386 }
387 let add_lower = other.lower() > self.lower();
388 let add_upper = other.upper() < self.upper();
389 // We know this because !self.is_subset(other) and the ranges have
390 // a non-empty intersection.
391 assert!(add_lower || add_upper);
392 let mut ret = (None, None);
393 if add_lower {
394 let upper = other.lower().decrement();
395 ret.0 = Some(Self::create(self.lower(), upper));
396 }
397 if add_upper {
398 let lower = other.upper().increment();
399 let range = Self::create(lower, self.upper());
400 if ret.0.is_none() {
401 ret.0 = Some(range);
402 } else {
403 ret.1 = Some(range);
404 }
405 }
406 ret
407 }
408
409 /// Compute the symmetric difference the given range from this range. This
410 /// returns the union of the two ranges minus its intersection.

Callers

nothing calls this directly

Implementers 1

mod.rsregex/regex-syntax/src/hir/mod.rs

Calls 8

is_subsetMethod · 0.80
is_intersection_emptyMethod · 0.80
cloneMethod · 0.80
lowerMethod · 0.80
upperMethod · 0.80
decrementMethod · 0.80
incrementMethod · 0.80
is_noneMethod · 0.80

Tested by

no test coverage detected