// Checks whether there is an argument separator (e.g. ',') before the end of the // function call. E.g. returns true for "a,b)" and "a(b,c),d)" and false for "b),c". public static bool SeparatorExists(ParsingScript script) { if (!script.StillValid()) { return(false); } int argumentList = 0; for (int i = script.Pointer; i < script.Size(); i++) { char ch = script.At(i); switch (ch) { case Constants.NEXT_ARG: return(true); case Constants.START_ARG: argumentList++; break; case Constants.END_STATEMENT: case Constants.END_GROUP: case Constants.END_ARG: if (--argumentList < 0) { return(false); } break; } } return(false); }
public static string GetToken(ParsingScript script, char [] to) { char curr = script.TryCurrent(); char prev = script.TryPrev(); if (!to.Contains(Constants.SPACE)) { // Skip a leading space unless we are inside of quotes while (curr == Constants.SPACE && prev != Constants.QUOTE) { script.Forward(); curr = script.TryCurrent(); prev = script.TryPrev(); } } // String in quotes bool inQuotes = curr == Constants.QUOTE; if (inQuotes) { int qend = script.Find(Constants.QUOTE, script.Pointer + 1); if (qend == -1) { throw new ArgumentException("Unmatched quotes in [" + script.FromPrev() + "]"); } string result = script.Substr(script.Pointer + 1, qend - script.Pointer - 1); script.Pointer = qend + 1; return(result); } script.MoveForwardIf(Constants.QUOTE); int end = script.FindFirstOf(to); end = end < 0 ? script.Size() : end; // Skip found characters that have a backslash before. while (end > 0 && end + 1 < script.Size() && script.String [end - 1] == '\\') { end = script.FindFirstOf(to, end + 1); } end = end < 0 ? script.Size() : end; if (script.At(end - 1) == Constants.QUOTE) { end--; } string var = script.Substr(script.Pointer, end - script.Pointer); // \"yes\" --> "yes" var = var.Replace("\\\"", "\""); script.Pointer = end; script.MoveForwardIf(Constants.QUOTE, Constants.SPACE); return(var); }