Skip to content

Commit

Permalink
Fix literal string writer
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Jan 16, 2024
1 parent 7d54e99 commit 65be3c6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/BymlLibrary/Yaml/YamlEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public unsafe void EmitString(Span<byte> str)
return;
}

if (str.ContainsAny(SpecialChars)) {
if (str.ContainsAny(SpecialChars) && !str.Contains(NEWLINE_CHAR_UTF8)) {
Builder.Append('\'');
Builder.Append(str.ToManaged());
Builder.Append('\'');
Expand All @@ -119,15 +119,20 @@ public unsafe void EmitString(Span<byte> str)
}

Level++;
Builder.Append("|-\n");

int index = 0;
int length;

while ((index = str[index..].IndexOf(NEWLINE_CHAR_UTF8)) > -1) {
Builder.AppendLine("|-");
while ((length = str[index..].IndexOf(NEWLINE_CHAR_UTF8)) > -1) {
IndentLine();
Builder.Append(str[..index].ToManaged());
Builder.Append(NEWLINE_CHAR);
Builder.Append(str[index..].ToManaged()[..++length]);
index += length;
}

IndentLine();
Builder.Append(str[index..].ToManaged());

Level--;
}

Expand Down

0 comments on commit 65be3c6

Please sign in to comment.