/// <summary> /// Parse supplied text using default settings. /// </summary> /// <param name="line"></param> /// <returns></returns> public static List <List <string> > ParseTable(string line) { LexListSettings settings = new LexListSettings(); settings.MultipleRecordsUsingNewLine = true; return(Parse(line, settings)); }
/// <summary> /// Parse a non-quoted item e.g. 123 as opposed to "123" /// </summary> private void ParseNonQuotedItem(LexListSettings settings) { // Read non-quoted text until the separator char is hit. string item = ReadNonQuotedToken(_separatorMap, true); if (settings.TrimWhiteSpace) { item = item.Trim(); } // Store the current list item. _tokenList.Add(item); }
/// <summary> /// Check for and handle new line. /// </summary> /// <returns></returns> public bool CheckAndHandleNewLine(LexListSettings settings) { if (_reader.IsEol()) { _reader.ConsumeNewLine(); // Check if newline means start of new record. if (settings.MultipleRecordsUsingNewLine) { _lines.Add(_tokenList); _tokenList = new List <string>(); } return(true); } return(false); }
/// <summary> /// Parse a quoted item. e.g. "batman" /// </summary> /// <param name="settings"></param> private void ParseQuotedItem(LexListSettings settings) { string quote = _reader.CurrentChar; string item = ReadQuotedToken(); if (settings.TrimWhiteSpace) { item = item.Trim(); } // Store the current list item. _tokenList.Add(item); // Check that closing quote is present. if (Expect(quote)) { _reader.ReadChar(); } }
/// <summary> /// Create with supplied settings. /// </summary> /// <param name="settings"></param> public LexList(LexListSettings settings) { Init(settings); }
/// <summary> /// Parse supplied text using supplied settings. /// </summary> /// <param name="line"></param> /// <param name="settings"></param> /// <returns></returns> public static List <List <string> > Parse(string text, LexListSettings settings) { LexList lex = new LexList(settings); return(lex.ParseLines(text)); }
/// <summary> /// Parse supplied text using supplied settings. /// </summary> /// <param name="line"></param> /// <param name="settings"></param> /// <returns></returns> public static List<List<string>> Parse(string text, LexListSettings settings) { LexList lex = new LexList(settings); return lex.ParseLines(text); }
/// <summary> /// Parse /// </summary> /// <param name="line"></param> /// <returns></returns> public List <List <string> > ParseLines(string text) { // First cut of lex parser. // This needs to be handled differently and should allow whitespace to // be a separator. LexListSettings settings = _settings as LexListSettings; Reset(text); // Move to first char. _reader.ReadChar(); // Get rid of initial whitespace. _reader.ConsumeWhiteSpace(); while (!_reader.IsEnd()) { if (_reader.IsWhiteSpace()) { _reader.ConsumeWhiteSpace(); // Continue check. // The consuming of white space always leaves // the reader at the beginning of a non-whitespace char. continue; } // Check for quotes. else if (_reader.CurrentChar == "'" || _reader.CurrentChar == "\"") { ParseQuotedItem(settings); } else { ParseNonQuotedItem(settings); } // Check for and consume whitespace. CheckAndConsumeWhiteSpace(); // Check for comma and consume it. CheckAndHandleComma(); // Consume whitespace CheckAndConsumeWhiteSpace(); // Handle new lines and whether to store // next line as another record. if (!CheckAndHandleNewLine(settings)) { // Now read next char _reader.ReadChar(); } } // Handle errors. CheckAndThrowErrors(); // Token list always gets reset in the beginning of this method. if (_tokenList.Count > 0) { _lines.Add(_tokenList); } return(_lines); }
/// <summary> /// Create with supplied settings. /// </summary> /// <param name="settings"></param> public LexList(LexListSettings settings) { Init(settings); }
/// <summary> /// Parse a quoted item. e.g. "batman" /// </summary> /// <param name="settings"></param> private void ParseQuotedItem(LexListSettings settings) { string quote = _reader.CurrentChar; string item = ReadQuotedToken(); if (settings.TrimWhiteSpace) item = item.Trim(); // Store the current list item. _tokenList.Add(item); // Check that closing quote is present. if (Expect(quote)) _reader.ReadChar(); }
/// <summary> /// Parse a non-quoted item e.g. 123 as opposed to "123" /// </summary> private void ParseNonQuotedItem(LexListSettings settings) { // Read non-quoted text until the separator char is hit. string item = ReadNonQuotedToken(_separatorMap, true); if (settings.TrimWhiteSpace) item = item.Trim(); // Store the current list item. _tokenList.Add(item); }
/// <summary> /// Check for and handle new line. /// </summary> /// <returns></returns> public bool CheckAndHandleNewLine(LexListSettings settings) { if (_reader.IsEol()) { _reader.ConsumeNewLine(); // Check if newline means start of new record. if (settings.MultipleRecordsUsingNewLine) { _lines.Add(_tokenList); _tokenList = new List<string>(); } return true; } return false; }
/// <summary> /// Parse supplied text using default settings. /// </summary> /// <param name="line"></param> /// <returns></returns> public static List<List<string>> ParseTable(string line) { LexListSettings settings = new LexListSettings(); settings.MultipleRecordsUsingNewLine = true; return Parse(line, settings); }