diff options
-rw-r--r-- | include/tools/json_writer.hxx | 6 | ||||
-rw-r--r-- | tools/qa/cppunit/test_json_writer.cxx | 4 | ||||
-rw-r--r-- | tools/source/misc/json_writer.cxx | 17 |
3 files changed, 14 insertions, 13 deletions
diff --git a/include/tools/json_writer.hxx b/include/tools/json_writer.hxx index b885cb5e55a3..9efa358a5e60 100644 --- a/include/tools/json_writer.hxx +++ b/include/tools/json_writer.hxx @@ -48,7 +48,7 @@ public: [[nodiscard]] ScopedJsonWriterNode<']'> startArray(std::string_view nodeName); [[nodiscard]] ScopedJsonWriterNode<'}'> startStruct(); - void put(std::u16string_view pPropName, const OUString& rPropValue); + void put(std::u16string_view pPropName, std::u16string_view rPropValue); void put(std::string_view pPropName, const OUString& rPropValue); // Assumes utf-8 property value encoding @@ -69,7 +69,7 @@ public: } void put(std::string_view pPropName, bool); - void putSimpleValue(const OUString& rPropValue); + void putSimpleValue(std::u16string_view rPropValue); /// This assumes that this data belongs at this point in the stream, and is valid, and properly encoded void putRaw(std::string_view); @@ -84,7 +84,7 @@ public: private: void endNode(char closing); void addCommaBeforeField(); - void writeEscapedOUString(const OUString& rPropVal); + void writeEscapedOUString(std::u16string_view rPropVal); void closeDocument(); void ensureSpace(int noMoreBytesRequired); void ensureSpaceAndWriteNameColon(std::string_view name, int valSize); diff --git a/tools/qa/cppunit/test_json_writer.cxx b/tools/qa/cppunit/test_json_writer.cxx index 05f19515e1e4..7e2a7baab0e2 100644 --- a/tools/qa/cppunit/test_json_writer.cxx +++ b/tools/qa/cppunit/test_json_writer.cxx @@ -82,8 +82,8 @@ void JsonWriterTest::testArray() tools::JsonWriter aJson; { auto aArray = aJson.startArray("items"); - aJson.putSimpleValue("foo"); - aJson.putSimpleValue("bar"); + aJson.putSimpleValue(u"foo"); + aJson.putSimpleValue(u"bar"); } OString aResult(aJson.finishAndGetAsOString()); diff --git a/tools/source/misc/json_writer.cxx b/tools/source/misc/json_writer.cxx index ef651fe0d690..86021dfcc5ca 100644 --- a/tools/source/misc/json_writer.cxx +++ b/tools/source/misc/json_writer.cxx @@ -8,6 +8,7 @@ */ #include <tools/json_writer.hxx> +#include <o3tl/string_view.hxx> #include <stdio.h> #include <cstring> #include <rtl/math.hxx> @@ -130,16 +131,16 @@ static bool writeEscapedSequence(sal_uInt32 ch, char*& pos) } } -void JsonWriter::writeEscapedOUString(const OUString& rPropVal) +void JsonWriter::writeEscapedOUString(std::u16string_view rPropVal) { *mPos = '"'; ++mPos; // Convert from UTF-16 to UTF-8 and perform escaping sal_Int32 i = 0; - while (i < rPropVal.getLength()) + while (i < static_cast<sal_Int32>(rPropVal.size())) { - sal_uInt32 ch = rPropVal.iterateCodePoints(&i); + sal_uInt32 ch = o3tl::iterateCodePoints(rPropVal, &i); if (writeEscapedSequence(ch, mPos)) continue; if (ch <= 0x7F) @@ -182,17 +183,17 @@ void JsonWriter::writeEscapedOUString(const OUString& rPropVal) validate(); } -void JsonWriter::put(std::u16string_view pPropName, const OUString& rPropVal) +void JsonWriter::put(std::u16string_view pPropName, std::u16string_view rPropVal) { auto nPropNameLength = pPropName.length(); // But values can be any UTF-8, // if the string only contains of 0x2028, it will be expanded 6 times (see writeEscapedSequence) - auto nWorstCasePropValLength = rPropVal.getLength() * 6; + auto nWorstCasePropValLength = rPropVal.size() * 6; ensureSpace(nPropNameLength + nWorstCasePropValLength + 8); addCommaBeforeField(); - writeEscapedOUString(OUString(pPropName)); + writeEscapedOUString(pPropName); memcpy(mPos, ": ", 2); mPos += 2; @@ -252,9 +253,9 @@ void JsonWriter::put(std::string_view pPropName, bool nPropVal) putLiteral(pPropName, nPropVal ? std::string_view("true") : std::string_view("false")); } -void JsonWriter::putSimpleValue(const OUString& rPropVal) +void JsonWriter::putSimpleValue(std::u16string_view rPropVal) { - auto nWorstCasePropValLength = rPropVal.getLength() * 6; + auto nWorstCasePropValLength = rPropVal.size() * 6; ensureSpace(nWorstCasePropValLength + 4); addCommaBeforeField(); |