public Highlights (Pattern[] patterns) : base() { string[] patternTexts = new string [patterns.Length]; for (int i = 0; i < patterns.Length; i ++) patternTexts [i] = patterns [i].pattern; BuildTrie (patternTexts); BuildFail(); this.patterns = patterns; }
protected int SpansTo (Pattern pattern, string buffer, int soffset) { bool found; for (int i=soffset; i < buffer.Length - pattern.spanto.Length; i++) { found = true; for (int j=0; j<pattern.spanto.Length; j++) { if ( pattern.spanto[j] != buffer[i+j] ) { found = false; break; } } if ( found ) { if ( pattern.signore == null ) return i + pattern.spanto.Length - 1; if ( pattern.signore[0] == pattern.spanto[0] ) { int k = i+1; for (int j=pattern.signore.Length - pattern.spanto.Length; j<pattern.signore.Length; j++) if ( k >= buffer.Length || buffer[k++] != pattern.signore[j] ) return i + pattern.spanto.Length - 1; i = k-1; } else { int k = i; for (int j=pattern.signore.Length - 1; j>=0; j--) if ( k < 0 || buffer[k--] != pattern.signore[j] ) return i + pattern.spanto.Length - 1; } } } return -1; }
public Token (Pattern pattern, int sidx, int eidx) { this.sindex = sidx - pattern.pattern.Length + 1; this.eindex = eidx + 1; this.style = pattern.style; }