Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/LibCK2/Parsing/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private string GetEncodedString(ReadOnlySequence<byte> 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();
Expand All @@ -61,9 +61,20 @@ private string GetEncodedString(ReadOnlySequence<byte> 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;
Expand All @@ -76,6 +87,7 @@ private string GetEncodedString(ReadOnlySequence<byte> buffer)
case (byte)'\r':
case (byte)'\n':
case (byte)'\t':
case (byte)' ':
type = TokenTypes.Value;
break;
default:
Expand Down