public StringParser(string sourceCode) { _chars = sourceCode.ToCharArray(); _pos = new TextPos { CharIndex = 0, LineNo = 1, ColNo = 1 }; }
public bool ThisWord(string[] wantedWordSet, ref int readIndex) { var priorPos = Pos; string wordRead = null; if (AnyWord(ref wordRead)) { for (int i = 0; i < wantedWordSet.Length; i++) if (wantedWordSet[i].Equals(wordRead, StringComparison.OrdinalIgnoreCase)) { readIndex = i; return true; } Pos = priorPos; } return false; }
public bool ThisText(string wantedText) { Skip(); var priorPos = Pos; var wantedChars = wantedText.ToCharArray(); for (int i = 0; i < wantedChars.Length; i++) if (!ThisChar(wantedChars[i])) { Pos = priorPos; return false; } return true; }
public bool ThisWord(string wantedWord, ref string wordRead) { var priorPos = Pos; if (AnyWord(ref wordRead)) { if (wordRead.Equals(wantedWord, StringComparison.OrdinalIgnoreCase)) return true; Pos = priorPos; } return false; }
public bool ThisChar(string wantedCharSet, ref char charRead) { var priorPos = Pos; if (AnyChar(ref charRead)) { if (wantedCharSet.IndexOf(charRead.ToString(), StringComparison.OrdinalIgnoreCase) != -1) return true; Pos = priorPos; } return false; }