include/tools/json_writer.hxx | 3 ++ tools/source/misc/json_writer.cxx | 49 +++++++++++++++++++++++++++----------- vcl/source/control/combobox.cxx | 18 +++++++------ vcl/source/control/listbox.cxx | 10 +++---- vcl/source/window/toolbox2.cxx | 4 +-- vcl/source/window/window.cxx | 4 +-- 6 files changed, 56 insertions(+), 32 deletions(-)
New commits: commit 7fc2fe5c612f95b9624f49b5fdea2d3c8c94caf1 Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Tue Nov 24 15:03:27 2020 +0100 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Thu Dec 3 08:45:24 2020 +0100 jsdialog: fix arrays in JsonWriter output Change-Id: I5638b1b02afcdd57b16b60d83d3d15da45866060 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107066 Tested-by: Jenkins Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> diff --git a/include/tools/json_writer.hxx b/include/tools/json_writer.hxx index 10e1a3a7aafc..440fedccf45e 100644 --- a/include/tools/json_writer.hxx +++ b/include/tools/json_writer.hxx @@ -64,6 +64,8 @@ public: void put(const char* pPropName, bool); void put(const char* pPropName, double); + void putSimpleValue(const OUString& rPropValue); + /// This assumes that this data belongs at this point in the stream, and is valid, and properly encoded void putRaw(const rtl::OStringBuffer&); @@ -82,6 +84,7 @@ private: void endStruct(); void addCommaBeforeField(); void reallocBuffer(int noMoreBytesRequired); + void writeEscapedOUString(const OUString& rPropVal); // this part inline to speed up the fast path inline void ensureSpace(int noMoreBytesRequired) 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); diff --git a/vcl/source/control/combobox.cxx b/vcl/source/control/combobox.cxx index 666feb9e3216..89bf43b075f7 100644 --- a/vcl/source/control/combobox.cxx +++ b/vcl/source/control/combobox.cxx @@ -1544,18 +1544,20 @@ void ComboBox::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { Control::DumpAsPropertyTree(rJsonWriter); - auto entriesNode = rJsonWriter.startNode("entries"); - for (int i = 0; i < GetEntryCount(); ++i) { - auto entryNode = rJsonWriter.startNode(""); - rJsonWriter.put("", GetEntry(i)); + auto entriesNode = rJsonWriter.startArray("entries"); + for (int i = 0; i < GetEntryCount(); ++i) + { + rJsonWriter.putSimpleValue(GetEntry(i)); + } } - auto selectedNode = rJsonWriter.startNode("selectedEntries"); - for (int i = 0; i < GetSelectedEntryCount(); ++i) { - auto entryNode = rJsonWriter.startNode(""); - rJsonWriter.put("", GetSelectedEntryPos(i)); + auto selectedNode = rJsonWriter.startArray("selectedEntries"); + for (int i = 0; i < GetSelectedEntryCount(); ++i) + { + rJsonWriter.putSimpleValue(OUString::number(GetSelectedEntryPos(i))); + } } rJsonWriter.put("selectedCount", GetSelectedEntryCount()); diff --git a/vcl/source/control/listbox.cxx b/vcl/source/control/listbox.cxx index 4782807892fc..fccaf1227920 100644 --- a/vcl/source/control/listbox.cxx +++ b/vcl/source/control/listbox.cxx @@ -1400,22 +1400,20 @@ void ListBox::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) Control::DumpAsPropertyTree(rJsonWriter); { - auto entriesNode = rJsonWriter.startNode("entries"); + auto entriesNode = rJsonWriter.startArray("entries"); for (int i = 0; i < GetEntryCount(); ++i) { - auto entryNode = rJsonWriter.startNode(""); - rJsonWriter.put("", GetEntry(i)); + rJsonWriter.putSimpleValue(GetEntry(i)); } } rJsonWriter.put("selectedCount", GetSelectedEntryCount()); { - auto entriesNode = rJsonWriter.startNode("selectedEntries"); + auto entriesNode = rJsonWriter.startArray("selectedEntries"); for (int i = 0; i < GetSelectedEntryCount(); ++i) { - auto entryNode = rJsonWriter.startNode(""); - rJsonWriter.put("", GetSelectedEntryPos(i)); + rJsonWriter.putSimpleValue(OUString::number(GetSelectedEntryPos(i))); } } } diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx index 047ca8c37621..360fa312640d 100644 --- a/vcl/source/window/toolbox2.cxx +++ b/vcl/source/window/toolbox2.cxx @@ -1731,13 +1731,13 @@ void ToolBox::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) { DockingWindow::DumpAsPropertyTree(rJsonWriter); - auto childrenNode = rJsonWriter.startNode("children"); + auto childrenNode = rJsonWriter.startArray("children"); for (ToolBox::ImplToolItems::size_type i = 0; i < GetItemCount(); ++i) { ToolBoxItemType type = GetItemType(i); if (type == ToolBoxItemType::BUTTON) { - auto childNode = rJsonWriter.startNode(""); + auto childNode = rJsonWriter.startStruct(); int nId = GetItemId(i); if (!IsItemVisible(nId)) continue; diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index 1fe5940c028f..3ab8fad61652 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -3336,11 +3336,11 @@ void Window::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) if (vcl::Window* pChild = mpWindowImpl->mpFirstChild) { - auto childrenNode = rJsonWriter.startNode("children"); + auto childrenNode = rJsonWriter.startArray("children"); while (pChild) { if (pChild->IsVisible()) { - auto childNode = rJsonWriter.startNode(""); + auto childNode = rJsonWriter.startStruct(); pChild->DumpAsPropertyTree(rJsonWriter); sal_Int32 nLeft = pChild->get_grid_left_attach(); sal_Int32 nTop = pChild->get_grid_top_attach(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits