summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comphelper/source/misc/string.cxx86
-rw-r--r--dbaccess/source/core/misc/dsntypes.cxx7
-rw-r--r--dbaccess/source/ui/app/AppDetailPageHelper.cxx2
-rw-r--r--dbaccess/source/ui/querydesign/QueryDesignView.cxx2
-rw-r--r--editeng/source/outliner/outliner.cxx5
-rw-r--r--include/comphelper/string.hxx24
-rw-r--r--linguistic/source/dicimp.cxx4
-rw-r--r--sc/source/core/data/dputil.cxx2
-rw-r--r--sc/source/filter/html/htmlpars.cxx2
-rw-r--r--sfx2/source/dialog/dinfdlg.cxx4
-rw-r--r--starmath/source/cursor.cxx2
-rw-r--r--starmath/source/dialog.cxx2
-rw-r--r--sw/source/core/doc/docfld.cxx2
-rw-r--r--sw/source/core/inc/docfld.hxx2
-rw-r--r--sw/source/filter/html/swhtml.cxx2
-rw-r--r--vcl/source/treelist/imap2.cxx4
16 files changed, 116 insertions, 36 deletions
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx
index acdb6c88adcb..a11a305c5daf 100644
--- a/comphelper/source/misc/string.cxx
+++ b/comphelper/source/misc/string.cxx
@@ -61,16 +61,43 @@ namespace
return rIn.substr(i);
}
+ template <typename T, typename C> T tmpl_stripStartString(const T &rIn,
+ const C cRemove)
+ {
+ if (rIn.isEmpty())
+ return rIn;
+
+ sal_Int32 i = 0;
+
+ while (i < rIn.getLength())
+ {
+ if (rIn[i] != cRemove)
+ break;
+ ++i;
+ }
+
+ return rIn.copy(i);
+ }
}
-OString stripStart(std::string_view rIn, char c)
+OString stripStart(const OString& rIn, char c)
{
- return OString(tmpl_stripStart<std::string_view, char>(rIn, c));
+ return tmpl_stripStartString<OString, char>(rIn, c);
}
-OUString stripStart(std::u16string_view rIn, sal_Unicode c)
+std::string_view stripStart(std::string_view rIn, char c)
{
- return OUString(tmpl_stripStart<std::u16string_view, sal_Unicode>(rIn, c));
+ return tmpl_stripStart<std::string_view, char>(rIn, c);
+}
+
+OUString stripStart(const OUString& rIn, sal_Unicode c)
+{
+ return tmpl_stripStartString<OUString, sal_Unicode>(rIn, c);
+}
+
+std::u16string_view stripStart(std::u16string_view rIn, sal_Unicode c)
+{
+ return tmpl_stripStart<std::u16string_view, sal_Unicode>(rIn, c);
}
namespace
@@ -92,25 +119,64 @@ namespace
return rIn.substr(0, i);
}
+ template <typename T, typename C> T tmpl_stripEndString(const T &rIn,
+ const C cRemove)
+ {
+ if (rIn.isEmpty())
+ return rIn;
+
+ sal_Int32 i = rIn.getLength();
+
+ while (i > 0)
+ {
+ if (rIn[i-1] != cRemove)
+ break;
+ --i;
+ }
+
+ return rIn.copy(0, i);
+ }
+}
+
+OString stripEnd(const OString& rIn, char c)
+{
+ return tmpl_stripEndString<OString, char>(rIn, c);
}
-OString stripEnd(std::string_view rIn, char c)
+std::string_view stripEnd(std::string_view rIn, char c)
{
- return OString(tmpl_stripEnd<std::string_view, char>(rIn, c));
+ return tmpl_stripEnd<std::string_view, char>(rIn, c);
}
-OUString stripEnd(std::u16string_view rIn, sal_Unicode c)
+OUString stripEnd(const OUString& rIn, sal_Unicode c)
{
- return OUString(tmpl_stripEnd<std::u16string_view, sal_Unicode>(rIn, c));
+ return tmpl_stripEndString<OUString, sal_Unicode>(rIn, c);
}
-OString strip(std::string_view rIn, char c)
+std::u16string_view stripEnd(std::u16string_view rIn, sal_Unicode c)
+{
+ return tmpl_stripEnd<std::u16string_view, sal_Unicode>(rIn, c);
+}
+
+OString strip(const OString& rIn, char c)
+{
+ auto x = tmpl_stripStartString<OString, char>(rIn, c);
+ return stripEnd(x, c);
+}
+
+std::string_view strip(std::string_view rIn, char c)
{
auto x = tmpl_stripStart<std::string_view, char>(rIn, c);
return stripEnd(x, c);
}
-OUString strip(std::u16string_view rIn, sal_Unicode c)
+OUString strip(const OUString& rIn, sal_Unicode c)
+{
+ auto x = tmpl_stripStartString<OUString, sal_Unicode>(rIn, c);
+ return stripEnd(x, c);
+}
+
+std::u16string_view strip(std::u16string_view rIn, sal_Unicode c)
{
auto x = tmpl_stripStart<std::u16string_view, sal_Unicode>(rIn, c);
return stripEnd(x, c);
diff --git a/dbaccess/source/core/misc/dsntypes.cxx b/dbaccess/source/core/misc/dsntypes.cxx
index 25513b36c952..06eb5545f354 100644
--- a/dbaccess/source/core/misc/dsntypes.cxx
+++ b/dbaccess/source/core/misc/dsntypes.cxx
@@ -19,6 +19,7 @@
#include <dsntypes.hxx>
#include <unotools/confignode.hxx>
+#include <o3tl/safeint.hxx>
#include <o3tl/string_view.hxx>
#include <osl/diagnose.h>
#include <tools/wldcrd.hxx>
@@ -84,7 +85,7 @@ OUString ODsnTypeCollection::cutPrefix(std::u16string_view _sURL) const
OUString sOldPattern;
// on Windows or with gen rendering, the urls may begin with an ~
- const OUString& sCleanURL = comphelper::string::stripStart(_sURL, '~');
+ std::u16string_view sCleanURL = comphelper::string::stripStart(_sURL, '~');
for (auto const& dsnPrefix : m_aDsnPrefixes)
{
@@ -95,8 +96,8 @@ OUString ODsnTypeCollection::cutPrefix(std::u16string_view _sURL) const
// foo*
// that is, the very concept of "prefix" applies.
OUString prefix(comphelper::string::stripEnd(dsnPrefix, '*'));
- OSL_ENSURE(prefix.getLength() <= sCleanURL.getLength(), "How can A match B when A shorter than B?");
- sRet = sCleanURL.copy(prefix.getLength());
+ OSL_ENSURE(o3tl::make_unsigned(prefix.getLength()) <= sCleanURL.size(), "How can A match B when A shorter than B?");
+ sRet = sCleanURL.substr(prefix.getLength());
sOldPattern = dsnPrefix;
}
}
diff --git a/dbaccess/source/ui/app/AppDetailPageHelper.cxx b/dbaccess/source/ui/app/AppDetailPageHelper.cxx
index 9533ec087c14..3a25efb0597e 100644
--- a/dbaccess/source/ui/app/AppDetailPageHelper.cxx
+++ b/dbaccess/source/ui/app/AppDetailPageHelper.cxx
@@ -882,7 +882,7 @@ namespace
{
OUString stripTrailingDots(std::u16string_view rStr)
{
- return comphelper::string::stripEnd(rStr, '.');
+ return OUString(comphelper::string::stripEnd(rStr, '.'));
}
}
diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
index 42b0d3a7a817..15a482e91cb2 100644
--- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx
+++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
@@ -2172,7 +2172,7 @@ namespace
if ( SQL_ISRULE(pColumnRef,general_set_fct) )
{
aInfo->SetFunctionType(nFunctionType|FKT_AGGREGATE);
- aInfo->SetFunction(comphelper::string::stripEnd(o3tl::getToken(aColumns,0,'('), ' '));
+ aInfo->SetFunction(OUString(comphelper::string::stripEnd(o3tl::getToken(aColumns,0,'('), ' ')));
}
else
aInfo->SetFunctionType(nFunctionType|FKT_OTHER);
diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx
index 36d2f1ca6999..b885bbd310c2 100644
--- a/editeng/source/outliner/outliner.cxx
+++ b/editeng/source/outliner/outliner.cxx
@@ -47,6 +47,7 @@
#include <libxml/xmlwriter.h>
#include <sal/log.hxx>
#include <o3tl/safeint.hxx>
+#include <o3tl/string_view.hxx>
#include <osl/diagnose.h>
#include <memory>
@@ -523,8 +524,8 @@ bool Outliner::ImpConvertEdtToOut( sal_Int32 nPara )
}
sal_Int32 nPos = nHeadingNumberStart ? nHeadingNumberStart : nNumberingNumberStart;
- OUString aLevel = comphelper::string::stripStart(aName.subView(nPos), ' ');
- nTabs = aLevel.toInt32();
+ std::u16string_view aLevel = comphelper::string::stripStart(aName.subView(nPos), ' ');
+ nTabs = o3tl::toInt32(aLevel);
if( nTabs )
nTabs--; // Level 0 = "heading 1"
bConverted = true;
diff --git a/include/comphelper/string.hxx b/include/comphelper/string.hxx
index 82815c0e5bc6..4fe10b71b3f0 100644
--- a/include/comphelper/string.hxx
+++ b/include/comphelper/string.hxx
@@ -69,7 +69,9 @@ inline OUStringBuffer& remove(OUStringBuffer &rIn,
@return The resulting OString
*/
-COMPHELPER_DLLPUBLIC OString stripStart(std::string_view rIn,
+COMPHELPER_DLLPUBLIC OString stripStart(const OString& rIn,
+ char c);
+COMPHELPER_DLLPUBLIC std::string_view stripStart(std::string_view rIn,
char c);
/** Strips occurrences of a character from the start of the source string
@@ -79,7 +81,9 @@ COMPHELPER_DLLPUBLIC OString stripStart(std::string_view rIn,
@return The resulting OUString
*/
-COMPHELPER_DLLPUBLIC OUString stripStart(std::u16string_view rIn,
+COMPHELPER_DLLPUBLIC OUString stripStart(const OUString& rIn,
+ sal_Unicode c);
+COMPHELPER_DLLPUBLIC std::u16string_view stripStart(std::u16string_view rIn,
sal_Unicode c);
/** Strips occurrences of a character from the end of the source string
@@ -89,7 +93,9 @@ COMPHELPER_DLLPUBLIC OUString stripStart(std::u16string_view rIn,
@return The resulting OString
*/
-COMPHELPER_DLLPUBLIC OString stripEnd(std::string_view rIn,
+COMPHELPER_DLLPUBLIC OString stripEnd(const OString& rIn,
+ char c);
+COMPHELPER_DLLPUBLIC std::string_view stripEnd(std::string_view rIn,
char c);
/** Strips occurrences of a character from the end of the source string
@@ -99,7 +105,9 @@ COMPHELPER_DLLPUBLIC OString stripEnd(std::string_view rIn,
@return The resulting OUString
*/
-COMPHELPER_DLLPUBLIC OUString stripEnd(std::u16string_view rIn,
+COMPHELPER_DLLPUBLIC OUString stripEnd(const OUString& rIn,
+ sal_Unicode c);
+COMPHELPER_DLLPUBLIC std::u16string_view stripEnd(std::u16string_view rIn,
sal_Unicode c);
/** Strips occurrences of a character from the start and end of the source string
@@ -109,7 +117,9 @@ COMPHELPER_DLLPUBLIC OUString stripEnd(std::u16string_view rIn,
@return The resulting OString
*/
-COMPHELPER_DLLPUBLIC OString strip(std::string_view rIn,
+COMPHELPER_DLLPUBLIC OString strip(const OString& rIn,
+ char c);
+COMPHELPER_DLLPUBLIC std::string_view strip(std::string_view rIn,
char c);
/** Strips occurrences of a character from the start and end of the source string
@@ -119,7 +129,9 @@ COMPHELPER_DLLPUBLIC OString strip(std::string_view rIn,
@return The resulting OUString
*/
-COMPHELPER_DLLPUBLIC OUString strip(std::u16string_view rIn,
+COMPHELPER_DLLPUBLIC OUString strip(const OUString& rIn,
+ sal_Unicode c);
+COMPHELPER_DLLPUBLIC std::u16string_view strip(std::u16string_view rIn,
sal_Unicode c);
/** Returns number of tokens in an OUString
diff --git a/linguistic/source/dicimp.cxx b/linguistic/source/dicimp.cxx
index 627cb2dd505b..59e88fd009e5 100644
--- a/linguistic/source/dicimp.cxx
+++ b/linguistic/source/dicimp.cxx
@@ -99,8 +99,8 @@ static bool getTag(std::string_view rLine, std::string_view rTagName,
if (nPos == std::string_view::npos)
return false;
- rTagValue = comphelper::string::strip(rLine.substr(nPos + rTagName.size()),
- ' ');
+ rTagValue = OString(comphelper::string::strip(rLine.substr(nPos + rTagName.size()),
+ ' '));
return true;
}
diff --git a/sc/source/core/data/dputil.cxx b/sc/source/core/data/dputil.cxx
index ac1dcca65eeb..651d550935f9 100644
--- a/sc/source/core/data/dputil.cxx
+++ b/sc/source/core/data/dputil.cxx
@@ -65,7 +65,7 @@ bool ScDPUtil::isDuplicateDimension(std::u16string_view rName)
OUString ScDPUtil::getSourceDimensionName(std::u16string_view rName)
{
- return comphelper::string::stripEnd(rName, '*');
+ return OUString(comphelper::string::stripEnd(rName, '*'));
}
sal_uInt8 ScDPUtil::getDuplicateIndex(const OUString& rName)
diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx
index 0b04ccaafee5..0129cd9d1b3c 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -2934,7 +2934,7 @@ void ScHTMLQueryParser::FontOn( const HtmlImportInfo& rInfo )
while( nPos != -1 )
{
// font list separator: VCL = ';' HTML = ','
- OUString aFName = comphelper::string::strip(o3tl::getToken(rFace, 0, ',', nPos), ' ');
+ std::u16string_view aFName = comphelper::string::strip(o3tl::getToken(rFace, 0, ',', nPos), ' ');
aFontName = ScGlobal::addToken(aFontName, aFName, ';');
}
if ( !aFontName.isEmpty() )
diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx
index 41283d26d31f..0ac32e343d09 100644
--- a/sfx2/source/dialog/dinfdlg.cxx
+++ b/sfx2/source/dialog/dinfdlg.cxx
@@ -157,8 +157,8 @@ OUString ConvertDateTime_Impl( std::u16string_view rName,
OUString aStr = rWrapper.getDate( aD )
+ aDelim
+ rWrapper.getTime( aT );
- OUString aAuthor = comphelper::string::stripStart(rName, ' ');
- if (!aAuthor.isEmpty())
+ std::u16string_view aAuthor = comphelper::string::stripStart(rName, ' ');
+ if (!aAuthor.empty())
{
aStr += aDelim + aAuthor;
}
diff --git a/starmath/source/cursor.cxx b/starmath/source/cursor.cxx
index e2dbdc44bfe8..52621d360c80 100644
--- a/starmath/source/cursor.cxx
+++ b/starmath/source/cursor.cxx
@@ -986,7 +986,7 @@ void SmCursor::InsertSpecial(std::u16string_view _aString)
BeginEdit();
Delete();
- OUString aString = comphelper::string::strip(_aString, ' ');
+ OUString aString( comphelper::string::strip(_aString, ' ') );
//Create instance of special node
SmToken token;
diff --git a/starmath/source/dialog.cxx b/starmath/source/dialog.cxx
index b3dc324a0d5f..043739cf5c0d 100644
--- a/starmath/source/dialog.cxx
+++ b/starmath/source/dialog.cxx
@@ -1821,7 +1821,7 @@ bool SmSymDefineDialog::SelectSymbolSet(weld::ComboBox& rComboBox,
assert((&rComboBox == m_xOldSymbolSets.get() || &rComboBox == m_xSymbolSets.get()) && "Sm : wrong ComboBox");
// trim SymbolName (no leading and trailing blanks)
- OUString aNormName = comphelper::string::strip(rSymbolSetName, ' ');
+ OUString aNormName( comphelper::string::strip(rSymbolSetName, ' ') );
// and remove possible deviations within the input
rComboBox.set_entry_text(aNormName);
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index 9442f4973057..a1a7434a25b6 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -372,7 +372,7 @@ HashStr::HashStr( const OUString& rName, const OUString& rText,
}
/// Look up the Name, if it is present, return its String, otherwise return an empty String
-OUString LookString( SwHashTable<HashStr> const & rTable, std::u16string_view rName )
+OUString LookString( SwHashTable<HashStr> const & rTable, const OUString& rName )
{
HashStr* pFnd = rTable.Find( comphelper::string::strip(rName, ' ') );
if( pFnd )
diff --git a/sw/source/core/inc/docfld.hxx b/sw/source/core/inc/docfld.hxx
index 117ee0408e34..08fb08e33eca 100644
--- a/sw/source/core/inc/docfld.hxx
+++ b/sw/source/core/inc/docfld.hxx
@@ -134,7 +134,7 @@ struct SwCalcFieldType final : public SwHash
};
// search for the string that was saved under rName in the hash table
-OUString LookString( SwHashTable<HashStr> const & rTable, std::u16string_view rName );
+OUString LookString( SwHashTable<HashStr> const & rTable, const OUString& rName );
const int GETFLD_ALL = 3; // combine flags via OR
const int GETFLD_CALC = 1;
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 2c19733d66b3..80d466660d83 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -2058,7 +2058,7 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken )
' ' == aToken[ aToken.getLength()-3 ] )
{
std::u16string_view aComment( aToken.subView( 3, aToken.getLength()-5 ) );
- InsertComment(comphelper::string::strip(aComment, ' '));
+ InsertComment(OUString(comphelper::string::strip(aComment, ' ')));
}
else
{
diff --git a/vcl/source/treelist/imap2.cxx b/vcl/source/treelist/imap2.cxx
index ef78e86bb42d..fd308afe0608 100644
--- a/vcl/source/treelist/imap2.cxx
+++ b/vcl/source/treelist/imap2.cxx
@@ -243,7 +243,7 @@ void ImageMap::ImpReadCERN( SvStream& rIStm )
void ImageMap::ImpReadCERNLine( std::string_view rLine )
{
- OString aStr = comphelper::string::stripStart(rLine, ' ');
+ OString aStr( comphelper::string::stripStart(rLine, ' ') );
aStr = comphelper::string::stripStart(aStr, '\t');
aStr = aStr.replaceAll(";", "");
aStr = aStr.toAsciiLowerCase();
@@ -376,7 +376,7 @@ void ImageMap::ImpReadNCSA( SvStream& rIStm )
void ImageMap::ImpReadNCSALine( std::string_view rLine )
{
- OString aStr = comphelper::string::stripStart(rLine, ' ');
+ OString aStr( comphelper::string::stripStart(rLine, ' ') );
aStr = comphelper::string::stripStart(aStr, '\t');
aStr = aStr.replaceAll(";", "");
aStr = aStr.toAsciiLowerCase();