Fix stringified value and key writing for quotes

This commit is contained in:
zontreck 2024-07-02 20:27:41 -07:00
parent 8077bbfa1f
commit 3e7bae969e
3 changed files with 21 additions and 3 deletions

View file

@ -227,7 +227,7 @@ abstract class Tag {
if (getKey() == "") {
return false;
} else {
String letters = "abcdefghijklmnopqrstuvwxyz";
String letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < getKey().length; i++) {
String digit = getKey().substring(i, i + 1);
if (letters.indexOf(digit) == -1) {
@ -238,6 +238,21 @@ abstract class Tag {
}
}
bool shouldQuote(String value) {
if (value == "") {
return false;
} else {
String letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < value.length; i++) {
String digit = value.substring(i, i + 1);
if (letters.indexOf(digit) == -1) {
return true;
}
}
return false;
}
}
void writeStringifiedValue(StringBuilder builder, int indent, bool isList);
void readStringifiedValue(StringReader reader);

View file

@ -36,7 +36,10 @@ class StringTag extends Tag {
@override
void writeStringifiedValue(StringBuilder builder, int indent, bool isList) {
builder.append("${isList ? "".padLeft(indent, '\t') : ""}\"${value}\"");
if (shouldQuote(value))
builder.append("${isList ? "".padLeft(indent, '\t') : ""}\"${value}\"");
else
builder.append("${isList ? "".padLeft(indent, '\t') : ""}${value}");
}
@override

View file

@ -1,6 +1,6 @@
name: libac_dart
description: "Aria's Creations code library"
version: 1.0.35
version: 1.0.36
homepage: "https://zontreck.com"