summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comphelper/source/misc/string.cxx21
-rw-r--r--compilerplugins/clang/stringview.cxx3
-rw-r--r--compilerplugins/clang/stringviewparam.cxx4
-rw-r--r--compilerplugins/clang/stringviewvar.cxx2
-rw-r--r--compilerplugins/clang/test/stringviewparam.cxx15
-rw-r--r--i18npool/inc/cclass_unicode.hxx2
-rw-r--r--i18npool/source/breakiterator/breakiteratorImpl.cxx15
-rw-r--r--i18npool/source/characterclassification/cclass_unicode.cxx5
-rw-r--r--include/comphelper/string.hxx2
-rw-r--r--include/o3tl/string_view.hxx2
-rw-r--r--o3tl/qa/test-string_view.cxx8
-rw-r--r--sal/rtl/ustring.cxx5
-rw-r--r--vcl/source/gdi/impglyphitem.cxx7
13 files changed, 50 insertions, 41 deletions
diff --git a/comphelper/source/misc/string.cxx b/comphelper/source/misc/string.cxx
index 0fdd24c83d7e..d5653522a229 100644
--- a/comphelper/source/misc/string.cxx
+++ b/comphelper/source/misc/string.cxx
@@ -263,13 +263,12 @@ sal_Int32 getTokenCount(std::u16string_view rIn, sal_Unicode cTok)
return tmpl_getTokenCount<std::u16string_view, sal_Unicode>(rIn, cTok);
}
-static sal_uInt32 decimalStringToNumber(
- OUString const & str, sal_Int32 nStart, sal_Int32 nLength )
+sal_uInt32 decimalStringToNumber(std::u16string_view str)
{
sal_uInt32 result = 0;
- for( sal_Int32 i = nStart; i < nStart + nLength; )
+ for( sal_Int32 i = 0; i < static_cast<sal_Int32>(str.size()); )
{
- sal_uInt32 c = str.iterateCodePoints(&i);
+ sal_uInt32 c = o3tl::iterateCodePoints(str, &i);
sal_uInt32 value = 0;
if( c <= 0x0039) // ASCII decimal digits, most common
value = c - 0x0030;
@@ -360,12 +359,6 @@ static sal_uInt32 decimalStringToNumber(
return result;
}
-sal_uInt32 decimalStringToNumber(
- OUString const & str )
-{
- return decimalStringToNumber(str, 0, str.getLength());
-}
-
using namespace ::com::sun::star;
// convert between sequence of string and comma separated string
@@ -435,8 +428,8 @@ sal_Int32 compareNatural( const OUString & rLHS, const OUString & rRHS,
if (nStartsDigitLHS > 0 && nStartsDigitRHS > 0)
{
- sal_uInt32 nLHS = comphelper::string::decimalStringToNumber(rLHS, 0, nStartsDigitLHS);
- sal_uInt32 nRHS = comphelper::string::decimalStringToNumber(rRHS, 0, nStartsDigitRHS);
+ sal_uInt32 nLHS = comphelper::string::decimalStringToNumber(rLHS.subView(0, nStartsDigitLHS));
+ sal_uInt32 nRHS = comphelper::string::decimalStringToNumber(rRHS.subView(0, nStartsDigitRHS));
if (nLHS != nRHS)
return nLHS < nRHS ? -1 : 1;
@@ -484,8 +477,8 @@ sal_Int32 compareNatural( const OUString & rLHS, const OUString & rRHS,
//numbers outside of the normal 0-9 range, e.g. see GetLocalizedChar in
//vcl
- sal_uInt32 nLHS = comphelper::string::decimalStringToNumber(rLHS, nLHSFirstDigitPos, nLHSChunkLen);
- sal_uInt32 nRHS = comphelper::string::decimalStringToNumber(rRHS, nRHSFirstDigitPos, nRHSChunkLen);
+ sal_uInt32 nLHS = comphelper::string::decimalStringToNumber(rLHS.subView(nLHSFirstDigitPos, nLHSChunkLen));
+ sal_uInt32 nRHS = comphelper::string::decimalStringToNumber(rRHS.subView(nRHSFirstDigitPos, nRHSChunkLen));
if (nLHS != nRHS)
{
diff --git a/compilerplugins/clang/stringview.cxx b/compilerplugins/clang/stringview.cxx
index d59d1dc68555..9484f3ace957 100644
--- a/compilerplugins/clang/stringview.cxx
+++ b/compilerplugins/clang/stringview.cxx
@@ -362,7 +362,8 @@ bool StringView::VisitCXXMemberCallExpr(CXXMemberCallExpr const* expr)
|| dc.Function("equalsIgnoreAsciiCase") || dc.Function("compareToIgnoreAsciiCase")
|| dc.Function("matchIgnoreAsciiCase") || dc.Function("trim")
|| dc.Function("startsWith") || dc.Function("endsWith") || dc.Function("match")
- || dc.Function("isEmpty") || dc.Function("getLength"))
+ || dc.Function("isEmpty") || dc.Function("getLength")
+ || dc.Function("iterateCodePoints"))
{
handleSubExprThatCouldBeView(expr->getImplicitObjectArgument());
}
diff --git a/compilerplugins/clang/stringviewparam.cxx b/compilerplugins/clang/stringviewparam.cxx
index d16c306f6326..9687bd8bbe2c 100644
--- a/compilerplugins/clang/stringviewparam.cxx
+++ b/compilerplugins/clang/stringviewparam.cxx
@@ -140,8 +140,8 @@ DeclRefExpr const* relevantCXXMemberCallExpr(CXXMemberCallExpr const* expr)
if (!(n == "getLength" || n == "getStr" || n == "convertToString" || n == "replace"
|| n == "replaceAll" || n == "replaceAt" || n == "replaceFirst"
|| n == "toAsciiLowerCase" || n == "toAsciiUpperCase" || n == "toUtf8"
- || n == "iterateCodePoints" || n == "startsWithIgnoreAsciiCase" || n == "toUInt64"
- || n == "toFloat" || n == "toBoolean"))
+ || n == "startsWithIgnoreAsciiCase" || n == "toUInt64" || n == "toFloat"
+ || n == "toBoolean"))
{
good = true;
}
diff --git a/compilerplugins/clang/stringviewvar.cxx b/compilerplugins/clang/stringviewvar.cxx
index 06123531e03b..5acc09d3fe78 100644
--- a/compilerplugins/clang/stringviewvar.cxx
+++ b/compilerplugins/clang/stringviewvar.cxx
@@ -129,7 +129,7 @@ DeclRefExpr const* relevantCXXMemberCallExpr(CXXMemberCallExpr const* expr)
|| n == "indexOf" || n == "lastIndexOf" || n == "compareTo" || n == "match"
|| n == "trim" || n == "toInt32" || n == "toInt64" || n == "toDouble"
|| n == "equalsIgnoreAsciiCase" || n == "compareToIgnoreAsciiCase" || n == "getToken"
- || n == "copy")
+ || n == "copy" || n == "iterateCodePoints")
{
good = true;
}
diff --git a/compilerplugins/clang/test/stringviewparam.cxx b/compilerplugins/clang/test/stringviewparam.cxx
index 78176fa096e3..abb98797b1dc 100644
--- a/compilerplugins/clang/test/stringviewparam.cxx
+++ b/compilerplugins/clang/test/stringviewparam.cxx
@@ -95,4 +95,19 @@ void f11(const OUString& f11rString)
buf.append(f11rString);
}
+// expected-error-re@+1 {{replace function parameter of type 'const {{(rtl::)?}}OUString &' with 'std::u16string_view' [loplugin:stringviewparam]}}
+sal_uInt32 decimalStringToNumber(OUString const& str, sal_Int32 nStart, sal_Int32 nLength)
+{
+ sal_uInt32 result = 0;
+ for (sal_Int32 i = nStart; i < nStart + nLength;)
+ {
+ sal_uInt32 c = str.iterateCodePoints(&i);
+ sal_uInt32 value = 0;
+ if (c <= 0x0039)
+ value = c - 0x0030;
+ result = result * 10 + value;
+ }
+ return result;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/i18npool/inc/cclass_unicode.hxx b/i18npool/inc/cclass_unicode.hxx
index 03c03d5bbc97..3a5f28f124ab 100644
--- a/i18npool/inc/cclass_unicode.hxx
+++ b/i18npool/inc/cclass_unicode.hxx
@@ -178,7 +178,7 @@ private:
void setupInternational( const css::lang::Locale& rLocale );
/// Implementation of getCharacterType() for one single character
- static sal_Int32 getCharType( const OUString& Text, sal_Int32 *nPos, sal_Int32 increment);
+ static sal_Int32 getCharType( std::u16string_view Text, sal_Int32 *nPos, sal_Int32 increment);
};
diff --git a/i18npool/source/breakiterator/breakiteratorImpl.cxx b/i18npool/source/breakiterator/breakiteratorImpl.cxx
index 71d794e2c9d4..5402caa7a469 100644
--- a/i18npool/source/breakiterator/breakiteratorImpl.cxx
+++ b/i18npool/source/breakiterator/breakiteratorImpl.cxx
@@ -23,6 +23,7 @@
#include <cppuhelper/supportsservice.hxx>
#include <unicode/uchar.h>
#include <i18nutil/unicode.hxx>
+#include <o3tl/string_view.hxx>
#include <com/sun/star/i18n/CharType.hpp>
#include <com/sun/star/i18n/ScriptType.hpp>
@@ -72,7 +73,7 @@ sal_Int32 SAL_CALL BreakIteratorImpl::previousCharacters( const OUString& Text,
#define isZWSP(c) (ch == 0x200B)
-static sal_Int32 skipSpace(const OUString& Text, sal_Int32 nPos, sal_Int32 len, sal_Int16 rWordType, bool bDirection)
+static sal_Int32 skipSpace(std::u16string_view Text, sal_Int32 nPos, sal_Int32 len, sal_Int16 rWordType, bool bDirection)
{
sal_uInt32 ch=0;
sal_Int32 pos=nPos;
@@ -81,7 +82,7 @@ static sal_Int32 skipSpace(const OUString& Text, sal_Int32 nPos, sal_Int32 len,
if (bDirection)
while (nPos < len)
{
- ch = Text.iterateCodePoints(&pos);
+ ch = o3tl::iterateCodePoints(Text, &pos);
if (!u_isUWhiteSpace(ch) && !isZWSP(ch))
break;
nPos = pos;
@@ -89,7 +90,7 @@ static sal_Int32 skipSpace(const OUString& Text, sal_Int32 nPos, sal_Int32 len,
else
while (nPos > 0)
{
- ch = Text.iterateCodePoints(&pos, -1);
+ ch = o3tl::iterateCodePoints(Text, &pos, -1);
if (!u_isUWhiteSpace(ch) && !isZWSP(ch))
break;
nPos = pos;
@@ -99,7 +100,7 @@ static sal_Int32 skipSpace(const OUString& Text, sal_Int32 nPos, sal_Int32 len,
if (bDirection)
while (nPos < len)
{
- ch = Text.iterateCodePoints(&pos);
+ ch = o3tl::iterateCodePoints(Text, &pos);
if (!u_isWhitespace(ch) && !isZWSP(ch) && (ch == 0x002E || u_isalnum(ch)))
break;
nPos = pos;
@@ -107,7 +108,7 @@ static sal_Int32 skipSpace(const OUString& Text, sal_Int32 nPos, sal_Int32 len,
else
while (nPos > 0)
{
- ch = Text.iterateCodePoints(&pos, -1);
+ ch = o3tl::iterateCodePoints(Text, &pos, -1);
if (!u_isWhitespace(ch) && !isZWSP(ch) && (ch == 0x002E || u_isalnum(ch)))
break;
nPos = pos;
@@ -117,7 +118,7 @@ static sal_Int32 skipSpace(const OUString& Text, sal_Int32 nPos, sal_Int32 len,
if (bDirection)
while (nPos < len)
{
- ch = Text.iterateCodePoints(&pos);
+ ch = o3tl::iterateCodePoints(Text, &pos);
if (!u_isUWhiteSpace(ch) && !isZWSP(ch))
break;
nPos = pos;
@@ -125,7 +126,7 @@ static sal_Int32 skipSpace(const OUString& Text, sal_Int32 nPos, sal_Int32 len,
else
while (nPos > 0)
{
- ch = Text.iterateCodePoints(&pos, -1);
+ ch = o3tl::iterateCodePoints(Text, &pos, -1);
if (!u_isUWhiteSpace(ch) && !isZWSP(ch))
break;
nPos = pos;
diff --git a/i18npool/source/characterclassification/cclass_unicode.cxx b/i18npool/source/characterclassification/cclass_unicode.cxx
index f07e9f812951..e3c27e9bc0fa 100644
--- a/i18npool/source/characterclassification/cclass_unicode.cxx
+++ b/i18npool/source/characterclassification/cclass_unicode.cxx
@@ -27,6 +27,7 @@
#include <breakiteratorImpl.hxx>
#include <transliteration_body.hxx>
#include <rtl/ref.hxx>
+#include <o3tl/string_view.hxx>
#include <utility>
using namespace ::com::sun::star;
@@ -147,10 +148,10 @@ cclass_Unicode::getScript( const OUString& Text, sal_Int32 nPos ) {
sal_Int32
-cclass_Unicode::getCharType( const OUString& Text, sal_Int32* nPos, sal_Int32 increment) {
+cclass_Unicode::getCharType( std::u16string_view Text, sal_Int32* nPos, sal_Int32 increment) {
using namespace ::com::sun::star::i18n::KCharacterType;
- sal_uInt32 ch = Text.iterateCodePoints(nPos, increment);
+ sal_uInt32 ch = o3tl::iterateCodePoints(Text, nPos, increment);
switch ( u_charType(ch) ) {
// Upper
case U_UPPERCASE_LETTER :
diff --git a/include/comphelper/string.hxx b/include/comphelper/string.hxx
index 8144a7e95e28..2763ded2e9fd 100644
--- a/include/comphelper/string.hxx
+++ b/include/comphelper/string.hxx
@@ -300,7 +300,7 @@ COMPHELPER_DLLPUBLIC OString join(std::string_view rSeparator, const std::vector
@return The value of the string as an int32.
*/
COMPHELPER_DLLPUBLIC sal_uInt32 decimalStringToNumber(
- OUString const & str );
+ std::u16string_view str );
COMPHELPER_DLLPUBLIC std::vector<OUString>
split(std::u16string_view rString, const sal_Unicode cSeparator);
diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 5d03b2cfba87..07278be8e529 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -509,7 +509,7 @@ inline double toDouble(std::string_view str)
}
// Like OUString::iterateCodePoints, but for std::string_view:
-inline sal_uInt32 iterateCodePoints(std::u16string_view string, std::size_t* indexUtf16,
+inline sal_uInt32 iterateCodePoints(std::u16string_view string, sal_Int32* indexUtf16,
sal_Int32 incrementCodePoints = 1)
{
std::size_t n;
diff --git a/o3tl/qa/test-string_view.cxx b/o3tl/qa/test-string_view.cxx
index c658da16b5dc..bbe5cbf0eddc 100644
--- a/o3tl/qa/test-string_view.cxx
+++ b/o3tl/qa/test-string_view.cxx
@@ -736,15 +736,15 @@ private:
void testIterateCodePoints()
{
{
- std::size_t i = 1;
+ sal_Int32 i = 1;
auto const c = o3tl::iterateCodePoints(u"\U00010000", &i, 1);
- CPPUNIT_ASSERT_EQUAL(std::size_t(2), i);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), i);
CPPUNIT_ASSERT_EQUAL(sal_uInt32(0xDC00), c);
}
{
- std::size_t i = 2;
+ sal_Int32 i = 2;
auto const c = o3tl::iterateCodePoints(u"a\U00010000", &i, -1);
- CPPUNIT_ASSERT_EQUAL(std::size_t(1), i);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), i);
CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x10000), c);
}
}
diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx
index c863be00512b..2a730f8cb5fa 100644
--- a/sal/rtl/ustring.cxx
+++ b/sal/rtl/ustring.cxx
@@ -778,11 +778,8 @@ sal_uInt32 SAL_CALL rtl_uString_iterateCodePoints(
&& o3tl::cmp_less_equal(*indexUtf16, std::numeric_limits<std::size_t>::max()));
// using o3tl::cmp_less_equal nicely avoids potential
// -Wtautological-constant-out-of-range-compare
- std::size_t i = *indexUtf16;
auto const cp = o3tl::iterateCodePoints(
- std::u16string_view(string->buffer, string->length), &i, incrementCodePoints);
- assert(i <= o3tl::make_unsigned(std::numeric_limits<sal_Int32>::max()));
- *indexUtf16 = i;
+ std::u16string_view(string->buffer, string->length), indexUtf16, incrementCodePoints);
return cp;
}
diff --git a/vcl/source/gdi/impglyphitem.cxx b/vcl/source/gdi/impglyphitem.cxx
index 6a2c576e1f1a..fed2ee0f3fe7 100644
--- a/vcl/source/gdi/impglyphitem.cxx
+++ b/vcl/source/gdi/impglyphitem.cxx
@@ -26,6 +26,7 @@
#include <unotools/configmgr.hxx>
#include <TextLayoutCache.hxx>
#include <officecfg/Office/Common.hxx>
+#include <o3tl/string_view.hxx>
#include <unicode/ubidi.h>
#include <unicode/uchar.h>
@@ -238,7 +239,7 @@ SalLayoutGlyphsCache* SalLayoutGlyphsCache::self()
return cache.get();
}
-static UBiDiDirection getBiDiDirection(const OUString& text, sal_Int32 index, sal_Int32 len)
+static UBiDiDirection getBiDiDirection(std::u16string_view text, sal_Int32 index, sal_Int32 len)
{
// Return whether all character are LTR, RTL, neutral or whether it's mixed.
// This is sort of ubidi_getBaseDirection() and ubidi_getDirection(),
@@ -247,7 +248,7 @@ static UBiDiDirection getBiDiDirection(const OUString& text, sal_Int32 index, sa
UBiDiDirection direction = UBIDI_NEUTRAL;
while (index < end)
{
- switch (u_charDirection(text.iterateCodePoints(&index)))
+ switch (u_charDirection(o3tl::iterateCodePoints(text, &index)))
{
// Only characters with strong direction.
case U_LEFT_TO_RIGHT:
@@ -269,7 +270,7 @@ static UBiDiDirection getBiDiDirection(const OUString& text, sal_Int32 index, sa
}
static SalLayoutGlyphs makeGlyphsSubset(const SalLayoutGlyphs& source,
- const OutputDevice* outputDevice, const OUString& text,
+ const OutputDevice* outputDevice, std::u16string_view text,
sal_Int32 index, sal_Int32 len)
{
// tdf#149264: We need to check if the text is LTR, RTL or mixed. Apparently