From 7317775052c612e74c87d074af0f02651e275bc0 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 9 Sep 2016 14:11:56 -0700 Subject: [PATCH] Add a MatchRange type alias. The regex library also uses (usize, usize) for ranges. The type alias is just to make it clearer what the tuple means. --- src/libfilecheck/checker.rs | 14 ++++++-------- src/libfilecheck/lib.rs | 3 +++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libfilecheck/checker.rs b/src/libfilecheck/checker.rs index 8abcbfdd3d..ea23f9e0d9 100644 --- a/src/libfilecheck/checker.rs +++ b/src/libfilecheck/checker.rs @@ -5,6 +5,7 @@ use regex::{Regex, Captures}; use std::collections::HashMap; use std::cmp::max; use std::fmt::{self, Display, Formatter}; +use MatchRange; // The different kinds of directives we support. enum Directive { @@ -259,19 +260,19 @@ impl<'a> State<'a> { } // Get the range in text to be matched by a `check:`. - fn check(&self) -> (usize, usize) { + fn check(&self) -> MatchRange { (self.max_match, self.text.len()) } // Get the range in text to be matched by a `sameln:`. - fn sameln(&self) -> (usize, usize) { + fn sameln(&self) -> MatchRange { let b = self.max_match; let e = self.bol(b); (b, e) } // Get the range in text to be matched by a `nextln:`. - fn nextln(&self) -> (usize, usize) { + fn nextln(&self) -> MatchRange { let b = self.bol(self.max_match); let e = self.bol(b); (b, e) @@ -290,16 +291,13 @@ impl<'a> State<'a> { } // Get the range in text to be matched by a `unordered:` directive. - fn unordered(&self, pat: &Pattern) -> (usize, usize) { + fn unordered(&self, pat: &Pattern) -> MatchRange { (self.unordered_begin(pat), self.text.len()) } // Search for `pat` in `range`, return the range matched. // After a positive match, update variable definitions, if any. - fn match_positive(&mut self, - pat: &Pattern, - range: (usize, usize)) - -> Result> { + fn match_positive(&mut self, pat: &Pattern, range: MatchRange) -> Result> { let rx = try!(pat.resolve(self)); let txt = &self.text[range.0..range.1]; let defs = pat.defs(); diff --git a/src/libfilecheck/lib.rs b/src/libfilecheck/lib.rs index 16d6d5028d..c38efe0890 100644 --- a/src/libfilecheck/lib.rs +++ b/src/libfilecheck/lib.rs @@ -244,3 +244,6 @@ mod error; mod variable; mod pattern; mod checker; + +/// The range of a match in the input text. +type MatchRange = (usize, usize);