From 93f21fcbf4cccb837711200c5a79cb5271ae2b43 Mon Sep 17 00:00:00 2001 From: Dale McCoy <21223975+DaleStan@users.noreply.github.com> Date: Fri, 24 Apr 2020 18:55:58 -0400 Subject: [PATCH] Handle double quotes and spaces to fix parsing of lines with multiple equals signs. --- src/LibCK2/Parsing/Scanner.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/LibCK2/Parsing/Scanner.cs b/src/LibCK2/Parsing/Scanner.cs index ab2c8d6..e53d347 100644 --- a/src/LibCK2/Parsing/Scanner.cs +++ b/src/LibCK2/Parsing/Scanner.cs @@ -50,7 +50,7 @@ private string GetEncodedString(ReadOnlySequence buffer) public async IAsyncEnumerable<(string token, TokenTypes stoppedBy)> ReadTokensAsync() { - var stopBytes = SaveGame.SaveGameEncoding.GetBytes("\r\n\t{}=#"); + var stopBytes = SaveGame.SaveGameEncoding.GetBytes("\r\n\t\" {}=#"); while (true) { var result = await _reader.ReadAsync(); @@ -61,9 +61,20 @@ private string GetEncodedString(ReadOnlySequence buffer) if (!foundPos.HasValue) break; var pos = foundPos.Value; - var tokenBuffer = buf.Slice(0, pos); - byte stoppedBy = buf.Slice(pos, 1).First.Span[0]; + + if (stoppedBy == (byte)'"') + { + var quotePos = buf.Slice(1).PositionOf((byte)'"'); + if (!quotePos.HasValue) break; + foundPos = buf.Slice(buf.GetPosition(1, quotePos.Value)).PositionOfAny(stopBytes); + if (!foundPos.HasValue) break; + + pos = foundPos.Value; + stoppedBy = buf.Slice(pos, 1).First.Span[0]; + } + + var tokenBuffer = buf.Slice(0, pos); if (!tokenBuffer.IsEmpty || stoppedBy > 32) { TokenTypes type; @@ -76,6 +87,7 @@ private string GetEncodedString(ReadOnlySequence buffer) case (byte)'\r': case (byte)'\n': case (byte)'\t': + case (byte)' ': type = TokenTypes.Value; break; default: