Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using NUnit.Framework;
- namespace TableParser
- {
- [TestFixture]
- public class QuotedFieldTaskTests
- {
- [TestCase("''", 0, "", 2)]
- [TestCase("'a'", 0, "a", 3)]
- [TestCase("'abc'", 0, "abc", 5)]
- [TestCase("'a\\\''", 0, "a\'", 5)]
- [TestCase("\'\'", 0, "", 2)]
- [TestCase("'a\"\"'", 0, "a\"\"", 5)]
- [TestCase("'b\"a'\"", 2, "a\'", 4)]
- //[TestCase("\'\'\'\'", 0, "", 5)]
- //[TestCase("\'a\'", 0, "a", 3)]
- public void Test(string line, int startIndex, string expectedValue, int expectedLength)
- {
- var actualToken = QuotedFieldTask.ReadQuotedField(line, startIndex);
- Assert.AreEqual(actualToken, new Token(expectedValue, startIndex, expectedLength));
- }
- // Добавьте свои тесты
- }
- class QuotedFieldTask
- {
- public static Token ReadQuotedField(string line, int startIndex)
- {
- var q = line[startIndex];
- var otherQ = q.ToString() == "\'" ? "\"" : "\'";
- var i = startIndex+1;
- while (line[i] != q || line.Length>1 && line[i] == q && line[i - 1].ToString() == "\\")
- {
- if (line[i] == q && line[i - 1].ToString() == "\\") i++;
- if (i == line.Length - 1) break;
- i++;
- }
- line = line.Substring(startIndex+1, i - startIndex-1);
- Console.WriteLine(line);
- var res = "";
- var j = 0;
- while (j < line.Length)
- {
- if (j == line.Length-1)
- {
- res+= line[line.Length-1];
- break;
- }
- if ((line[j].ToString() == "\\" || line[j].ToString() == otherQ))
- {
- j++;
- continue;
- }
- res += line[j];
- j++;
- }
- return new Token(res, startIndex, line.Length+2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement