public IEnumerable <FindResult> EnumFind(string[] CmpWith, string[] Skip = null, bool Back = false, IdCharCheck IdCharCheck = new IdCharCheck(), IList <IResultSkippingHandler> Handlers = null) { if (!CanContain(CmpWith, Back)) { yield break; } var RSM = new ResultSkippingManager(Handlers, this, Back); while (RSM.Loop()) { var Res = SubstringEquals(RSM.Current, CmpWith, Skip, Back, IdCharCheck); if (Res.Position != -1) { yield return(Res); if (Back) { RSM.Current -= Res.String.Length - 1; } else { RSM.Current += Res.String.Length - 1; } } } }
public int WordEnd(bool WordStart = false, bool Back = false, Func <char, bool> Func = null, IList <IResultSkippingHandler> Handlers = null) { if (Length == 0) { return(-1); } var RSM = new ResultSkippingManager(Handlers, this, Back); var Exit = false; var Prev = -1; while (RSM.Loop()) { var Chr = RSM.CurrentChar; var Res = Func == null?Helper.IsIdChar(Chr) : Func(Chr); if (Prev != -1) { if (WordStart) { if (!Res) { Exit = true; } else if (Exit) { return(Prev); } } else { if (!Res) { return(Prev); } } } else if (!Res) { if (WordStart) { Exit = true; } else { return(-1); } } Prev = RSM.Current; } return(Back ? 0 : Length - 1); }
public int Find(char CmpWith, bool Back = false, IList <IResultSkippingHandler> Handlers = null) { var Found = false; if (Back) { for (var i = Index + Length - 1; i >= Index; i--) { if (String[i] == CmpWith) { if (Handlers == null) { return(i - Index); } Found = true; break; } } } else { for (var i = Index; i < Index + Length; i++) { if (String[i] == CmpWith) { if (Handlers == null) { return(i - Index); } Found = true; break; } } } if (Found) { var RSM = new ResultSkippingManager(Handlers, this, Back); while (RSM.Loop()) { if (RSM.CurrentChar == CmpWith) { return(RSM.Current); } } } return(-1); }
public IEnumerable <SplitRes> EnumSplit(string Separator, StringSplitOptions SplitOptions = StringSplitOptions.None, bool Trim = false, IList <IResultSkippingHandler> Handlers = null) { if (string.IsNullOrEmpty(Separator)) { throw new ArgumentException("Separator"); } var RSM = new ResultSkippingManager(Handlers, this); var SeparatorLen = Separator.Length; RSM.String.Length -= SeparatorLen - 1; var BeginOfLast = 0; var SubStr = new StringSlice(); while (RSM.Loop()) { var i = RSM.Current; if (SubstringEqualsS(i, Separator)) { if (SplitOptions != StringSplitOptions.RemoveEmptyEntries || i > BeginOfLast) { SubStr = Substring(BeginOfLast, i - BeginOfLast); if (Trim) { SubStr = SubStr.Trim(); } if (SubStr.Length > 0) { yield return(new SplitRes(SubStr, false)); } } yield return(new SplitRes(Substring(i, SeparatorLen), true)); BeginOfLast = i + SeparatorLen; i += SeparatorLen - 1; } } SubStr = Substring(BeginOfLast); if (Trim) { SubStr = SubStr.Trim(); } if (SubStr.Length > 0) { yield return(new SplitRes(SubStr, false)); } }
public IEnumerable <int> EnumFind(string CmpWith, string[] Skip = null, bool Back = false, IdCharCheck IdCharCheck = new IdCharCheck(), IList <IResultSkippingHandler> Handlers = null) { var RSM = new ResultSkippingManager(Handlers, this, Back); while (RSM.Loop()) { var Res = SubstringEquals(RSM.Current, CmpWith, Skip, Back, IdCharCheck); if (Res != -1) { yield return(Res); } } }
public IEnumerable <SplitRes> EnumSplit(char Separator, StringSplitOptions SplitOptions = StringSplitOptions.None, bool Trim = false, IList <IResultSkippingHandler> Handlers = null) { var RSM = new ResultSkippingManager(Handlers, this); var BeginOfLast = 0; var SubStr = new StringSlice(); while (RSM.Loop()) { if (RSM.CurrentChar == Separator) { var i = RSM.Current; if (SplitOptions != StringSplitOptions.RemoveEmptyEntries || i > BeginOfLast) { SubStr = Substring(BeginOfLast, i - BeginOfLast); if (Trim) { SubStr = SubStr.Trim(); } if (SubStr.Length > 0) { yield return(new SplitRes(SubStr, false)); } } yield return(new SplitRes(Substring(i, 1), true)); BeginOfLast = i + 1; } } SubStr = Substring(BeginOfLast); if (Trim) { SubStr = SubStr.Trim(); } if (SubStr.Length > 0) { yield return(new SplitRes(SubStr, false)); } }
public FindResult Find(string[] CmpWith, string[] Skip = null, bool Back = false, IdCharCheck IdCharCheck = new IdCharCheck(), IList <IResultSkippingHandler> Handlers = null) { if (!CanContain(CmpWith, Back)) { return(new FindResult(-1, -1, null)); } var RSM = new ResultSkippingManager(Handlers, this, Back); while (RSM.Loop()) { var Res = SubstringEquals(RSM.Current, CmpWith, Skip, Back, IdCharCheck); if (Res.Position != -1) { return(Res); } } return(new FindResult(-1, -1, null)); }
public int GetBracketPos(bool Back = false, IList <IResultSkippingHandler> Handlers = null) { if (String.Length < 2) { return(-1); } var RSM = new ResultSkippingManager(Handlers, this, Back); RSM.DoNotSkipBrackets = true; char BeginChar, EndChar; var Depth = 1; if (Back) { var Chr = String[Index + Length - 1]; if (Chr == ')') { BeginChar = ')'; EndChar = '('; } else if (Chr == ']') { BeginChar = ']'; EndChar = '['; } else if (Chr == '}') { BeginChar = '}'; EndChar = '{'; } else if (Chr == '>') { BeginChar = '>'; EndChar = '<'; } else { throw new ApplicationException(); } } else { var Chr = String[Index]; if (Chr == '(') { BeginChar = '('; EndChar = ')'; } else if (Chr == '[') { BeginChar = '['; EndChar = ']'; } else if (Chr == '{') { BeginChar = '{'; EndChar = '}'; } else if (Chr == '<') { BeginChar = '<'; EndChar = '>'; } else { throw new ApplicationException(); } } if (!RSM.Loop()) { return(-1); } while (RSM.Loop()) { var Chr = RSM.CurrentChar; if (Chr == BeginChar) { Depth++; } else if (Chr == EndChar) { Depth--; if (Depth == 0) { return(RSM.Current); } } } return(-1); }
public int TrimmableBracketCount(IList <IResultSkippingHandler> Handlers = null) { var RSM = new ResultSkippingManager(Handlers, this); RSM.DoNotSkipBrackets = true; var Left = 0; var Right = 0; var Depth = 0; var MinDepth = int.MaxValue; var EndLeft = false; while (RSM.Loop()) { var Chr = RSM.CurrentChar; if (Chr == ')') { Depth--; Right++; if (Left == 0) { return(0); } EndLeft = true; } else { if (EndLeft && MinDepth > Depth) { MinDepth = Depth; if (MinDepth == 0) { return(0); } } if (Chr == '(') { Depth++; Right = 0; if (!EndLeft) { Left++; } } else if (!char.IsWhiteSpace(Chr)) { Right = 0; if (Left == 0) { return(0); } EndLeft = true; } } } var LRMin = Left < Right ? Left : Right; return(LRMin < MinDepth ? LRMin : MinDepth); }