Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. using System.Collections.Generic;
  2.  
  3. namespace TableParser
  4. {
  5. public class FieldsParserTask
  6. {
  7. // При решении этой задаче постарайтесь избежать создания методов, длиннее 10 строк.
  8. // Ниже есть метод ReadField — это подсказка. Найдите класс Token и изучите его.
  9. // Подумайте как можно использовать ReadField и Token в этой задаче.
  10. public static List<string> ParseLine(string line)
  11. {
  12. int i = 0;
  13. List<string> fields = new List<string> { };
  14. while (i < line.Length)
  15. {
  16. Token token = ReadField(line, i);
  17. fields.Add(token.Value);
  18. i = token.GetIndexNextToToken();
  19. }
  20. }
  21.  
  22.  
  23. private static Token ReadField(string line, int startIndex)
  24. {
  25. bool insideBlock = (line[startIndex] == '\'' || line[startIndex] == '"');
  26. int startIndex_ = insideBlock ? startIndex + 1 : startIndex;
  27. if (insideBlock)
  28. {
  29. return ParseInsideBlock(line, startIndex_);
  30. }else
  31. {
  32. return ParseOutsideBlock(line, startIndex_);
  33. }
  34. }
  35.  
  36. private static Token ParseOutsideBlock(string line, int startIndex)
  37. {
  38. return new Token(line, 0, line.Length);
  39. }
  40.  
  41. private static Token ParseInsideBlock(string line, int startIndex)
  42. {
  43. return new Token(line, 0, line.Length);
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement