Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using NUnit.Framework;
- namespace TableParser
- {
- [TestFixture]
- public class QuotedFieldTaskTests
- {
- [TestCase("''", 0, "", 2)]
- [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 character = line[startIndex];
- var len = 1;
- var value = "";
- var slash = false;
- for (var i = startIndex + 1; i <= line.Length; i++)
- {
- if (i == line.Length)
- {
- len = line.Length - startIndex;
- break;
- }
- if (line[i] == '\\' && !slash)
- {
- slash = true;
- len++;
- }
- else if (slash)
- {
- len++;
- value += line[i];
- slash = !slash;
- }
- else if (line[i] == character)
- {
- len++;
- break;
- }
- else
- {
- len++;
- value += line[i];
- }
- }
- return new Token(value, startIndex, len);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement