summaryrefslogtreecommitdiff
path: root/tools/source
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-02-23 12:00:49 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-02-23 16:50:33 +0100
commit4603aa28888ed7e3ed4fe0163b9296065067b03e (patch)
tree645ecf3c055ea0c9e048961e6d00db9ef51ca94d /tools/source
parent822b221b3d32b3526e6cc61021ad250902342bbf (diff)
use more string_view in tools::JsonWriter
Change-Id: Ia3ac54a1164b99a806298a47115ea3bc570f3b0c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163810 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'tools/source')
-rw-r--r--tools/source/misc/json_writer.cxx17
1 files changed, 9 insertions, 8 deletions
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();