Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- namespace TableParser
- {
- public class FieldsParserTask
- {
- // При решении этой задаче постарайтесь избежать создания методов, длиннее 10 строк.
- // Ниже есть метод ReadField — это подсказка. Найдите класс Token и изучите его.
- // Подумайте как можно использовать ReadField и Token в этой задаче.
- public static List<string> ParseLine(string line)
- {
- int i = 0;
- List<string> fields = new List<string> { };
- while (i < line.Length)
- {
- Token token = ReadField(line, i);
- fields.Add(token.Value);
- i = token.GetIndexNextToToken();
- }
- }
- private static Token ReadField(string line, int startIndex)
- {
- bool insideBlock = (line[startIndex] == '\'' || line[startIndex] == '"');
- int startIndex_ = insideBlock ? startIndex + 1 : startIndex;
- if (insideBlock)
- {
- return ParseInsideBlock(line, startIndex_);
- }else
- {
- return ParseOutsideBlock(line, startIndex_);
- }
- }
- private static Token ParseOutsideBlock(string line, int startIndex)
- {
- return new Token(line, 0, line.Length);
- }
- private static Token ParseInsideBlock(string line, int startIndex)
- {
- return new Token(line, 0, line.Length);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement