bool evaluate(Func <Pattern, bool> scanFunc) { positionAlreadyUpdated = false; index = -1; length = 0; var value = RegionManager.Regions[variableName]; replacement = replacement?.Clone(); switch (value.Type) { case Value.ValueType.Pattern: var pattern = (Pattern)value; var anchored = State.Anchored; State.Anchored = true; pattern.OwnerNext = next; pattern.OwnerReplacement = pattern.Replacement?.Clone(); pattern.SubPattern = true; depth.Retain(); var inputLength = State.Input.Length; index = State.Position; length = 0; while (index < inputLength && !scanFunc(pattern)) { State.Position++; positionAlreadyUpdated = true; } depth.Reset(); State.Anchored = anchored; length = State.Position - index; return(State.Position < inputLength); } return(false); }
bool evaluate(Func <Element, bool> func, Func <Pattern, bool> scanFunc) { positionAlreadyUpdated = false; index = -1; length = 0; var value = RegionManager.Regions[variableName]; string text; StringElement element; bool result; replacement = replacement?.Clone(); switch (value.Type) { case Value.ValueType.Pattern: var pattern = (Pattern)value; var anchored = State.Anchored; State.Anchored = true; pattern.OwnerNext = next; pattern.OwnerReplacement = pattern.Replacement?.Clone(); pattern.SubPattern = true; depth.Retain($"Variable element recursion limit of {MAX_VAR_DEPTH} exceeded"); if (scanFunc(pattern)) { if (Not) { return(false); } index = pattern.Index; length = pattern.Length; positionAlreadyUpdated = true; State.Anchored = anchored; depth.Reset(); return(true); } if (Not) { positionAlreadyUpdated = true; State.Anchored = anchored; depth.Reset(); return(true); } depth.Reset(); State.Anchored = anchored; break; case Value.ValueType.Array: foreach (var item in (Array)value) { text = item.Value.Text; if (text.IsEmpty()) { continue; } element = new StringElement(text); result = func(element); if (!result) { continue; } index = element.Index; length = element.Length; return(true); } return(false); default: text = value.Text; if (text == null) { return(false); } element = new StringElement(text); result = func(element); if (result) { index = element.Index; length = element.Length; } return(result); } return(false); }