[Libreoffice-commits] core.git: 2 commits - comphelper/source editeng/source include/comphelper sc/source sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Wed Oct 7 23:38:23 PDT 2015
comphelper/source/misc/string.cxx | 11 +++++++++++
editeng/source/editeng/impedit.cxx | 9 ++++-----
include/comphelper/string.hxx | 4 ++++
sc/source/ui/view/gridwin.cxx | 13 ++++---------
sw/source/core/crsr/crsrsh.cxx | 16 +++++++++++-----
sw/source/core/crsr/viscrs.cxx | 20 +++++++-------------
sw/source/uibase/uiview/viewsrch.cxx | 12 ++++--------
7 files changed, 45 insertions(+), 40 deletions(-)
New commits:
commit 1cb13d87b5d887718f6d81a842444b7251dc64cf
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Thu Oct 8 08:37:12 2015 +0200
editeng, sw, sc: use comphelper::string::join()
Change-Id: I9b0a32271a965bc4089720ccb61b26b67ceab7b2
diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx
index ea488b9..83e30ff 100644
--- a/editeng/source/editeng/impedit.cxx
+++ b/editeng/source/editeng/impedit.cxx
@@ -46,6 +46,7 @@
#include <sot/exchange.hxx>
#include <sot/formats.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <comphelper/string.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -350,17 +351,15 @@ void ImpEditView::DrawSelection( EditSelection aTmpSel, vcl::Region* pRegion, Ou
libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_END, aEnd.toString().getStr());
}
- std::stringstream ss;
+ std::vector<OString> v;
for (size_t i = 0; i < aRectangles.size(); ++i)
{
Rectangle& rRectangle = aRectangles[i];
- if (i)
- ss << "; ";
if (bMm100ToTwip)
rRectangle = OutputDevice::LogicToLogic(rRectangle, MAP_100TH_MM, MAP_TWIP);
- ss << rRectangle.toString().getStr();
+ v.push_back(rRectangle.toString().getStr());
}
- sRectangle = ss.str().c_str();
+ sRectangle = comphelper::string::join("; ", v);
}
libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION, sRectangle.getStr());
}
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index aba40ff..395c4b5 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -134,6 +134,7 @@
#include <svx/sdr/overlay/overlaymanager.hxx>
#include <vcl/svapp.hxx>
#include <svx/sdr/overlay/overlayselection.hxx>
+#include <comphelper/string.hxx>
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
@@ -5895,9 +5896,8 @@ static void updateLibreOfficeKitSelection(ScViewData* pViewData, ScDrawLayer* pD
double nPPTY = pViewData->GetPPTY();
Rectangle aBoundingBox;
- std::stringstream ss;
+ std::vector<OString> aRectangles;
- bool bIsFirst = true;
for (auto aRectangle : rRectangles)
{
aRectangle.Right() += 1;
@@ -5905,14 +5905,9 @@ static void updateLibreOfficeKitSelection(ScViewData* pViewData, ScDrawLayer* pD
aBoundingBox.Union(aRectangle);
- if (bIsFirst)
- bIsFirst = false;
- else
- ss << "; ";
-
Rectangle aRect(aRectangle.Left() / nPPTX, aRectangle.Top() / nPPTY,
aRectangle.Right() / nPPTX, aRectangle.Bottom() / nPPTY);
- ss << aRect.toString().getStr();
+ aRectangles.push_back(aRect.toString());
}
// selection start handle
@@ -5926,7 +5921,7 @@ static void updateLibreOfficeKitSelection(ScViewData* pViewData, ScDrawLayer* pD
pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_END, aEnd.toString().getStr());
// the selection itself
- pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION, ss.str().c_str());
+ pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION, comphelper::string::join("; ", aRectangles).getStr());
}
void ScGridWindow::UpdateCursorOverlay()
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index ffd4a82..4ddf5eb 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -64,6 +64,7 @@
#include <IDocumentLayoutAccess.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <comphelper/lok.hxx>
+#include <comphelper/string.hxx>
using namespace com::sun::star;
using namespace util;
@@ -1204,14 +1205,19 @@ OUString SwCrsrShell::getPageRectangles()
{
CurrShell aCurr(this);
SwRootFrm* pLayout = GetLayout();
- std::stringstream ss;
+ std::vector<OString> v;
for (const SwFrm* pFrm = pLayout->GetLower(); pFrm; pFrm = pFrm->GetNext())
{
- if (pFrm != pLayout->GetLower())
- ss << "; ";
- ss << pFrm->Frm().Left() << ", " << pFrm->Frm().Top() << ", " << pFrm->Frm().Width() << ", " << pFrm->Frm().Height();
+ std::vector<OString> aRectangle
+ {
+ OString::number(pFrm->Frm().Left()),
+ OString::number(pFrm->Frm().Top()),
+ OString::number(pFrm->Frm().Width()),
+ OString::number(pFrm->Frm().Height())
+ };
+ v.push_back(comphelper::string::join(", ", aRectangle));
}
- return OUString::fromUtf8(ss.str().c_str());
+ return OUString::fromUtf8(comphelper::string::join("; ", v).getStr());
}
/// go to the next SSelection
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index 01a2da7..1379360 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -55,6 +55,7 @@
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <comphelper/lok.hxx>
+#include <comphelper/string.hxx>
#include <paintfrm.hxx>
// Here static members are defined. They will get changed on alteration of the
@@ -392,15 +393,13 @@ void SwSelPaintRects::Show(std::vector<OString>* pSelectionRectangles)
}
}
- std::stringstream ss;
+ std::vector<OString> aRect;
for (size_type i = 0; i < size(); ++i)
{
const SwRect& rRect = (*this)[i];
- if (i)
- ss << "; ";
- ss << rRect.SVRect().toString().getStr();
+ aRect.push_back(rRect.SVRect().toString());
}
- OString sRect = ss.str().c_str();
+ OString sRect = comphelper::string::join("; ", aRect);
if (!pSelectionRectangles)
{
if (comphelper::LibreOfficeKit::isViewCallback())
@@ -606,20 +605,15 @@ void SwShellCrsr::Show()
if (comphelper::LibreOfficeKit::isActive())
{
- std::stringstream ss;
- bool bFirst = true;
+ std::vector<OString> aRect;
for (size_t i = 0; i < aSelectionRectangles.size(); ++i)
{
const OString& rSelectionRectangle = aSelectionRectangles[i];
if (rSelectionRectangle.isEmpty())
continue;
- if (bFirst)
- bFirst = false;
- else
- ss << "; ";
- ss << rSelectionRectangle.getStr();
+ aRect.push_back(rSelectionRectangle);
}
- OString sRect = ss.str().c_str();
+ OString sRect = comphelper::string::join("; ", aRect);
if (comphelper::LibreOfficeKit::isViewCallback())
GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
else
diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx
index 3427fe4..9667fdc 100644
--- a/sw/source/uibase/uiview/viewsrch.cxx
+++ b/sw/source/uibase/uiview/viewsrch.cxx
@@ -60,6 +60,7 @@
#include <unocrsr.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <comphelper/lok.hxx>
+#include <comphelper/string.hxx>
#include <view.hrc>
#include <SwRewriter.hxx>
@@ -118,20 +119,15 @@ static void lcl_emitSearchResultCallbacks(sal_uInt16 nFound, SvxSearchItem* pSea
{
std::vector<OString> aSelectionRectangles;
pShellCrsr->SwSelPaintRects::Show(&aSelectionRectangles);
- std::stringstream ss;
- bool bFirst = true;
+ std::vector<OString> aRect;
for (size_t i = 0; i < aSelectionRectangles.size(); ++i)
{
const OString& rSelectionRectangle = aSelectionRectangles[i];
if (rSelectionRectangle.isEmpty())
continue;
- if (bFirst)
- bFirst = false;
- else
- ss << "; ";
- ss << rSelectionRectangle.getStr();
+ aRect.push_back(rSelectionRectangle);
}
- OString sRect = ss.str().c_str();
+ OString sRect = comphelper::string::join("; ", aRect);
aMatches.push_back(sRect);
}
}
commit fce720b3e4691eb3b7deef1d005d76b23123a5cb
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Thu Oct 8 08:33:09 2015 +0200
comphelper: add string::join()
If there is a need for it, this could be extended later to work with uno
sequences and/or OUStrings as well.
Change-Id: Id0af8b1755c8e4b668720563d10a052337e1b2c9
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx
index c563796..8384e73 100644
--- a/comphelper/source/misc/string.cxx
+++ b/comphelper/source/misc/string.cxx
@@ -270,6 +270,17 @@ uno::Sequence< OUString >
return kws;
}
+OString join(const OString& rSeparator, const std::vector<OString>& rSequence)
+{
+ OStringBuffer aBuffer;
+ for (size_t i = 0; i < rSequence.size(); ++i)
+ {
+ if (i != 0)
+ aBuffer.append(rSeparator);
+ aBuffer.append(rSequence[i]);
+ }
+ return aBuffer.makeStringAndClear();
+}
sal_Int32 compareNatural( const OUString & rLHS, const OUString & rRHS,
const uno::Reference< i18n::XCollator > &rCollator,
diff --git a/include/comphelper/string.hxx b/include/comphelper/string.hxx
index 0609e62..780d89e 100644
--- a/include/comphelper/string.hxx
+++ b/include/comphelper/string.hxx
@@ -23,6 +23,7 @@
#include <sal/config.h>
#include <cstddef>
+#include <vector>
#include <comphelper/comphelperdllapi.h>
#include <sal/types.h>
#include <rtl/strbuf.hxx>
@@ -310,6 +311,9 @@ COMPHELPER_DLLPUBLIC sal_Int32 indexOfAny(OUString const& rIn,
COMPHELPER_DLLPUBLIC OUString convertCommaSeparated(
::com::sun::star::uno::Sequence< OUString > const & i_rSeq);
+/// Return a string which is the concatenation of the strings in the sequence.
+COMPHELPER_DLLPUBLIC OString join(const OString& rSeparator, const std::vector<OString>& rSequence);
+
/** Convert a decimal string to a number.
The string must be base-10, no sign but can contain any
More information about the Libreoffice-commits
mailing list