From 7fc2fe5c612f95b9624f49b5fdea2d3c8c94caf1 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Tue, 24 Nov 2020 15:03:27 +0100 Subject: jsdialog: fix arrays in JsonWriter output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I5638b1b02afcdd57b16b60d83d3d15da45866060 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107066 Tested-by: Jenkins Reviewed-by: Szymon Kłos --- tools/source/misc/json_writer.cxx | 49 ++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 14 deletions(-) (limited to 'tools') diff --git a/tools/source/misc/json_writer.cxx b/tools/source/misc/json_writer.cxx index 1ccee8569480..a0e0280b840e 100644 --- a/tools/source/misc/json_writer.cxx +++ b/tools/source/misc/json_writer.cxx @@ -120,21 +120,8 @@ void JsonWriter::endStruct() mbFirstFieldInNode = false; } -void JsonWriter::put(const char* pPropName, const OUString& rPropVal) +void JsonWriter::writeEscapedOUString(const OUString& rPropVal) { - auto nPropNameLength = strlen(pPropName); - auto nWorstCasePropValLength = rPropVal.getLength() * 2; - ensureSpace(nPropNameLength + nWorstCasePropValLength + 8); - - addCommaBeforeField(); - - *mPos = '"'; - ++mPos; - memcpy(mPos, pPropName, nPropNameLength); - mPos += nPropNameLength; - memcpy(mPos, "\": \"", 4); - mPos += 4; - // Convert from UTF-16 to UTF-8 and perform escaping for (int i = 0; i < rPropVal.getLength(); ++i) { @@ -175,6 +162,24 @@ void JsonWriter::put(const char* pPropName, const OUString& rPropVal) ++mPos; } } +} + +void JsonWriter::put(const char* pPropName, const OUString& rPropVal) +{ + auto nPropNameLength = strlen(pPropName); + auto nWorstCasePropValLength = rPropVal.getLength() * 2; + ensureSpace(nPropNameLength + nWorstCasePropValLength + 8); + + addCommaBeforeField(); + + *mPos = '"'; + ++mPos; + memcpy(mPos, pPropName, nPropNameLength); + mPos += nPropNameLength; + memcpy(mPos, "\": \"", 4); + mPos += 4; + + writeEscapedOUString(rPropVal); *mPos = '"'; ++mPos; @@ -332,6 +337,22 @@ void JsonWriter::put(const char* pPropName, bool nPropVal) mPos += strlen(pVal); } +void JsonWriter::putSimpleValue(const OUString& rPropVal) +{ + auto nWorstCasePropValLength = rPropVal.getLength() * 2; + ensureSpace(nWorstCasePropValLength + 4); + + addCommaBeforeField(); + + *mPos = '"'; + ++mPos; + + writeEscapedOUString(rPropVal); + + *mPos = '"'; + ++mPos; +} + void JsonWriter::putRaw(const rtl::OStringBuffer& rRawBuf) { ensureSpace(rRawBuf.getLength() + 2); -- cgit v1.2.3