From b038b07bec23311c246fb71aac1d38431bc50fc4 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 8 Oct 2015 08:33:09 +0200 Subject: [PATCH 191/398] 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 (cherry picked from commit fce720b3e4691eb3b7deef1d005d76b23123a5cb) --- comphelper/source/misc/string.cxx | 11 +++++++++++ include/comphelper/string.hxx | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx index 98391741a13d..c6fa2fdde270 100644 --- a/comphelper/source/misc/string.cxx +++ b/comphelper/source/misc/string.cxx @@ -269,6 +269,17 @@ uno::Sequence< OUString > return kws; } +OString join(const OString& rSeparator, const std::vector& 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 b9680372c21b..8d2552266cf2 100644 --- a/include/comphelper/string.hxx +++ b/include/comphelper/string.hxx @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -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& rSequence); + /** Convert a decimal string to a number. The string must be base-10, no sign but can contain any -- 2.12.0