public ParseResult(ParseFailureReason failureReason) { FailureReason = failureReason; }
bool ParseNextInput(string inputLine, int startIndex, out int endIndex, out string parsedInput, out ParseFailureReason parseFailureReason) { bool parseSuccess = true; parseFailureReason = ParseFailureReason.None; // Skip leading whitespace SkipWhiteSpace(inputLine, startIndex, out startIndex); switch (inputLine[startIndex]) { // Parse a quoted string case '\"': FindEndofQuoteOrEOL(inputLine, startIndex, out endIndex); parsedInput = inputLine.Substring(startIndex, endIndex - startIndex); if (endIndex >= inputLine.Length) { break; } // Skip any whitespace. SkipWhiteSpace(inputLine, endIndex, out endIndex); // Quit when an EOL is found if (endIndex >= inputLine.Length) { break; } // If the next character isn't a comma, then we have a parse error. if (inputLine[endIndex] != ',') { parseFailureReason = ParseFailureReason.CharactersAfterQuote; parseSuccess = false; endIndex = inputLine.IndexOf(',', endIndex); if (endIndex == -1) { endIndex = inputLine.Length; } else { endIndex += 1; } } else { endIndex += 1; } break; // For a comma, return the default case ',': parsedInput = string.Empty; endIndex = startIndex + 1; break; default: endIndex = startIndex; /* Either a comma or a colon end the string. A colon ends an input because in * Microsoft BASIC GET/READ/INPUT share code and ':' is a statement separator. */ try { while (inputLine[endIndex] != ',' && inputLine[endIndex] != ':') { endIndex += 1; } } catch (IndexOutOfRangeException) { } parsedInput = inputLine.Substring(startIndex, endIndex - startIndex); if (endIndex < inputLine.Length) { // If a colon was found, set an error and return. if (inputLine[endIndex] == ':') { parseFailureReason = ParseFailureReason.Colon; parseSuccess = false; endIndex = inputLine.Length; } else { endIndex += 1; } } break; } return(parseSuccess); }