pub fn normalise(&mut self) {
        let mut normalised_elems = Vec::<RegexElem>::with_capacity(self.elems.len());

        // Insert a rogue bell to the end `self.elems` so that all runs of consecutive
        // wildcards/globs end in a bell
        self.elems.push(RegexElem::Bell(Bell::TREBLE));
        // Split the elements into chunks of 0 or more wildcards/globs, each of which finishes with
        // a bell.
        for slice in self
            .elems
            .split_inclusive(|e| matches!(e, RegexElem::Bell(_)))
        {
            // The slice should contain at least one element (the bell that matched the pattern)
            assert!(!slice.is_empty());
            let wildcards_pattern = &slice[..slice.len() - 1];
            let bell_elem = slice[slice.len() - 1];
            // Normalise the wildcard pattern, and push it.  To normalise it, we move all the 'x's
            // to the start of the pattern and then add a single glob (if the pattern contains any
            // globs).
            let num_wildcards = wildcards_pattern
                .iter()
                .filter(|e| matches!(e, RegexElem::Any))
                .count();
            normalised_elems.extend(std::iter::repeat(RegexElem::Any).take(num_wildcards));
            if wildcards_pattern.contains(&RegexElem::Glob) {
                normalised_elems.push(RegexElem::Glob);
            }
            // Push the bell that terminates this wildcard pattern
            normalised_elems.push(bell_elem);
        }

        // Overwrite this regex with the normalised element list
        self.elems = normalised_elems;
        // Pop the rogue bell off the end of the pattern (we added it before the loop to make the
        // code cleaner).
        assert_eq!(self.elems.pop(), Some(RegexElem::Bell(Bell::TREBLE)));
    }
/// Normalises wildcards and globs in a `Regex`.  This should only in combination with `unsafe`
/// - if only safe code is used, `self` will already be normalised.  This is the only operation
/// on `Regex`es which doesn't rely on the input being normalised.
Normalises wildcards and globs in a `Regex`.  This should only in combination with `unsafe`
if only safe code is used, `self` will already be normalised.  This is the only operation
on `Regex`es which doesn't rely on the input being normalised.
Normalises wildcards and globs in a ` Regex ` . This should only in combination with ` unsafe ` if only safe code is used ` self ` will already be normalised . This is the only operation on ` Regex ` es which doesn ' t rely on the input being normalised .
pub fn normalise(&mut self) {
        let mut normalised_elems = Vec::<RegexElem>::with_capacity(self.elems.len());
        // Insert a rogue bell to the end `self.elems` so that all runs of consecutive
        // wildcards/globs end in a bell
        self.elems.push(RegexElem::Bell(Bell::TREBLE));
        // Split the elements into chunks of 0 or more wildcards/globs, each of which finishes with
        // a bell.
        for slice in self
            .elems
            .split_inclusive(|e| matches!(e, RegexElem::Bell(_)))
        {
            // The slice should contain at least one element (the bell that matched the pattern)
            assert!(!slice.is_empty());
            let wildcards_pattern = &slice[..slice.len() - 1];
            let bell_elem = slice[slice.len() - 1];
            // Normalise the wildcard pattern, and push it.  To normalise it, we move all the 'x's
            // to the start of the pattern and then add a single glob (if the pattern contains any
            // globs).
            let num_wildcards = wildcards_pattern
                .iter()
                .filter(|e| matches!(e, RegexElem::Any))
                .count();
            normalised_elems.extend(std::iter::repeat(RegexElem::Any).take(num_wildcards));
            if wildcards_pattern.contains(&RegexElem::Glob) {
                normalised_elems.push(RegexElem::Glob);
            }
            // Push the bell that terminates this wildcard pattern
            normalised_elems.push(bell_elem);
        }
        // Overwrite this regex with the normalised element list
        self.elems = normalised_elems;
        // Pop the rogue bell off the end of the pattern (we added it before the loop to make the
        // code cleaner).
        assert_eq!(self.elems.pop(), Some(RegexElem::Bell(Bell::TREBLE)));
    }
pub fn normalise ( & mut self ) { let mut normalised_elems = Vec :: < RegexElem > :: with_capacity ( self . elems . len ( ) ) ; // Insert a rogue bell to the end `self.elems` so that all runs of consecutive // wildcards/globs end in a bell self . elems . push ( RegexElem :: Bell ( Bell :: TREBLE ) ) ; // Split the elements into chunks of 0 or more wildcards/globs, each of which finishes with // a bell. for slice in self . elems . split_inclusive ( | e | matches ! ( e RegexElem Bell ( ) ) ) { // The slice should contain at least one element (the bell that matched the pattern) assert ! ( slice is_empty ( ) ) ; let wildcards_pattern = & slice [ .. slice . len ( ) - 1 ] ; let bell_elem = slice [ slice . len ( ) - 1 ] ; // Normalise the wildcard pattern, and push it.  To normalise it, we move all the 'x's // to the start of the pattern and then add a single glob (if the pattern contains any // globs). let num_wildcards = wildcards_pattern . iter ( ) . filter ( | e | matches ! ( e RegexElem Any ) ) . count ( ) ; normalised_elems . extend ( std :: iter :: repeat ( RegexElem :: Any ) . take ( num_wildcards ) ) ; if wildcards_pattern . contains ( & RegexElem :: Glob ) { normalised_elems . push ( RegexElem :: Glob ) ; } // Push the bell that terminates this wildcard pattern normalised_elems . push ( bell_elem ) ; } // Overwrite this regex with the normalised element list self . elems = normalised_elems ; // Pop the rogue bell off the end of the pattern (we added it before the loop to make the // code cleaner). assert_eq ! ( self elems pop ( ) Some ( RegexElem Bell ( Bell TREBLE ) ) ) ; }
Normalises wildcards and globs in a `Regex`.
Normalises wildcards and globs in a ` Regex ` .
&mut self
&mut self