// --------------------------- ScanReverseNotEqual------------------------------- // scan reverse for the first location in string not equal to all of the // pattern characters. public static int ScanReverseNotEqual( string InString, int InBx, int InEx, int InIx, ScanPatterns InNotEqualPatterns) { int foundIx = InIx + 1; while (true) { foundIx -= 1; if (foundIx < InBx) { foundIx = -1; break; } int remLx = InEx - foundIx + 1; char ch1 = InString[foundIx]; // the current char is not equal any of the pattern lead chars. int patIx = Array.IndexOf <char>(InNotEqualPatterns.LeadChars, ch1); if (patIx == -1) { break; } // lead char matches. check the entire pattern string for equality. ScanPattern equalPat = null; ScanPattern pat = InNotEqualPatterns.ScanPatternsArray[patIx]; while (pat != null) { bool rv = Stringer.CompareSubstringEqual(InString, foundIx, InEx, pat.PatternValue); if (rv == true) { equalPat = pat; break; } pat = pat.NextSameLeadChar; } // none of the patterns fully match the substring at the current location. if (equalPat == null) { break; } } return(foundIx); }
// -------------------------------- ScanNotEqual ------------------------ public static ScanPatternResults ScanNotEqual( string InString, int InIx, int InEx, ScanPatterns InScanPatterns) { // step thru the string 1 char at a time. int stringIx = InIx; while (true) { if (stringIx > InEx) { stringIx = -1; break; } char ch1 = InString[stringIx]; // the current char is not equal any of the pattern lead chars. int patIx = Array.IndexOf <char>(InScanPatterns.LeadChars, ch1); if (patIx == -1) { break; } ScanPattern equalPat = null; ScanPattern pat = InScanPatterns.ScanPatternsArray[patIx]; while (pat != null) { bool rv = Stringer.CompareSubstringEqual(InString, stringIx, InEx, pat.PatternValue); if (rv == true) { if (equalPat == null) { equalPat = pat; } // Matching pattern already found, but this pattern also matches and it is // longer. Always return the longer pattern. else if (pat.PatternValue.Length > equalPat.PatternValue.Length) { equalPat = pat; } } pat = pat.NextSameLeadChar; } // check for the substring at the current location in string as not equal any // of the ScanNotEqual pattern strings. if (equalPat == null) { break; } // advance past the whitespace string. stringIx += equalPat.PatternValue.Length; } // return the scan results ScanPatternResults spr = null; if (stringIx == -1) { spr = new ScanPatternResults(-1); } else { spr = new ScanPatternResults(stringIx, InString[stringIx]); } spr.ScannedString = InString; spr.ScanStartIx = InIx; spr.ScanBoundsEx = InEx; return(spr); }