From 5474152c7e25face28c9ea2a0038b9bb9e428c92 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 8 Jun 2025 17:22:22 -0400 Subject: [PATCH] Remove old C string handling from OrderedJson --- CHANGELOG.md | 1 + src/lib/orderedjson.cpp | 35 +---------------------------------- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb0b103f..05390264 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp - Fix duplicated maps writing the wrong name. - Fix small maps being difficult to see while resizing. - Fix expressions using the prefix '0X' as opposed to '0x' not being recognized has hex numbers. +- Fix certain characters not writing correctly to JSON files. ## [6.0.0] - 2025-05-26 ### Breaking Changes diff --git a/src/lib/orderedjson.cpp b/src/lib/orderedjson.cpp index d6ba4dbd..ed7e1d8a 100644 --- a/src/lib/orderedjson.cpp +++ b/src/lib/orderedjson.cpp @@ -77,40 +77,7 @@ static void dump(bool value, QString &out, int *indent) { static void dump(const QString &value, QString &out, int *indent, bool isKey = false) { if (!isKey && !out.endsWith(": ")) out += QString(*indent * 2, ' '); - out += '"'; - for (int i = 0; i < value.length(); i++) { - const char ch = value[i].unicode(); - if (ch == '\\') { - out += "\\\\"; - } else if (ch == '"') { - out += "\\\""; - } else if (ch == '\b') { - out += "\\b"; - } else if (ch == '\f') { - out += "\\f"; - } else if (ch == '\n') { - out += "\\n"; - } else if (ch == '\r') { - out += "\\r"; - } else if (ch == '\t') { - out += "\\t"; - } else if (static_cast(ch) <= 0x1f) { - char buf[8]; - snprintf(buf, sizeof buf, "\\u%04x", ch); - out += buf; - } else if (static_cast(ch) == 0xe2 && static_cast(value[i+1].unicode()) == 0x80 - && static_cast(value[i+2].unicode()) == 0xa8) { - out += "\\u2028"; - i += 2; - } else if (static_cast(ch) == 0xe2 && static_cast(value[i+1].unicode()) == 0x80 - && static_cast(value[i+2].unicode()) == 0xa9) { - out += "\\u2029"; - i += 2; - } else { - out += ch; - } - } - out += '"'; + out += QString("\"%1\"").arg(value.toUtf8()); } static void dump(const Json::array &values, QString &out, int *indent) {