Untitled
unknown
csharp
2 years ago
1.3 kB
10
Indexable
class QuotedFieldTask { public static Token ReadQuotedField(string line, int startIndex) { var builder = new StringBuilder(); var tokenStartIndex = startIndex; var quotes = 0; var isShielded = false; var numberOfShieldedSymbols = 0; for (var index = 0; index < line[startIndex..].Length; index++) { var character = line[startIndex..][index]; if (character == line[startIndex..][0] && !isShielded) { if (quotes == 0) { tokenStartIndex += index; quotes++; continue; } quotes++; if(quotes == 2) break; } isShielded = IsShielded(character); if(isShielded) { numberOfShieldedSymbols++; continue; } if (quotes > 0) builder.Append(character); } var length = quotes + builder.Length + numberOfShieldedSymbols; return new Token(builder.ToString(), tokenStartIndex, length); } private static bool IsShielded(char character) { return character.ToString() == @"\"; } }
Editor is loading...