public static string Take(this Subject subject, int count) { var result = subject.Text.Substring(subject.Index, count); subject.Advance(count); return(result); }
public static char Take(this Subject subject) { if (subject.EndOfString) { return(char.MinValue); } var result = subject.Char; subject.Advance(); return(result); }
public static int AdvanceWhile(this Subject subject, char c, long max = int.MaxValue) { var start = subject.Index; var index = start; max = Math.Min(start + max, subject.Text.Length); while (index < max && subject.Text[index] == c) { index += 1; } return(index > start?subject.Advance(index - start) : 0); }
public static int AdvanceWhileNot(this Subject subject, Func <char, bool> predicate, long max = int.MaxValue) { var start = subject.Index; var index = start; max = Math.Min(start + max, subject.Text.Length); while (index < max && !predicate(subject.Text[index])) { index += 1; } return(index > start?subject.Advance(index - start) : 0); }