diff --git a/compilerplugins/clang/stringview.cxx b/compilerplugins/clang/stringview.cxx index a3eb09faf97d..1be16fb89a4f 100644 --- a/compilerplugins/clang/stringview.cxx +++ b/compilerplugins/clang/stringview.cxx @@ -379,8 +379,8 @@ bool StringView::VisitCXXMemberCallExpr(CXXMemberCallExpr const* expr) if (dc.Function("toInt32") || dc.Function("toUInt32") || dc.Function("toInt64") || dc.Function("toDouble") || dc.Function("equalsAscii") || dc.Function("equalsIgnoreAsciiCase") || dc.Function("compareToIgnoreAsciiCase") - || dc.Function("trim") || dc.Function("startsWith") || dc.Function("endsWith") - || dc.Function("match")) + || dc.Function("matchIgnoreAsciiCase") || dc.Function("trim") + || dc.Function("startsWith") || dc.Function("endsWith") || dc.Function("match")) { handleSubExprThatCouldBeView(expr->getImplicitObjectArgument()); } diff --git a/compilerplugins/clang/stringviewparam.cxx b/compilerplugins/clang/stringviewparam.cxx index dae4b9b1925f..eed439d0adf3 100644 --- a/compilerplugins/clang/stringviewparam.cxx +++ b/compilerplugins/clang/stringviewparam.cxx @@ -141,7 +141,7 @@ DeclRefExpr const* relevantCXXMemberCallExpr(CXXMemberCallExpr const* expr) || n == "indexOf" || n == "lastIndexOf" || n == "compareTo" || n == "match" || n == "trim" || n == "toInt32" || n == "toUInt32" || n == "toInt64" || n == "toDouble" || n == "equalsIgnoreAsciiCase" || n == "compareToIgnoreAsciiCase" || n == "getToken" - || n == "copy" || n == "equalsAscii") + || n == "copy" || n == "equalsAscii" || n == "matchIgnoreAsciiCase") { good = true; } diff --git a/desktop/source/deployment/registry/package/dp_package.cxx b/desktop/source/deployment/registry/package/dp_package.cxx index 2fc698467931..04ef763b070c 100644 --- a/desktop/source/deployment/registry/package/dp_package.cxx +++ b/desktop/source/deployment/registry/package/dp_package.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -1265,12 +1266,12 @@ Sequence< Reference > BackendImpl::PackageImpl::getBundle( return *pBundle; } -bool isBundle_( OUString const & mediaType ) +bool isBundle_( std::u16string_view mediaType ) { // xxx todo: additional parsing? - return !mediaType.isEmpty() && - (mediaType.matchIgnoreAsciiCase( "application/vnd.sun.star.package-bundle") || - mediaType.matchIgnoreAsciiCase( "application/vnd.sun.star.legacy-package-bundle")); + return !mediaType.empty() && + (o3tl::matchIgnoreAsciiCase( mediaType, u"application/vnd.sun.star.package-bundle") || + o3tl::matchIgnoreAsciiCase( mediaType, u"application/vnd.sun.star.legacy-package-bundle")); } diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx index 0935844349e2..026dc5e167ae 100644 --- a/include/o3tl/string_view.hxx +++ b/include/o3tl/string_view.hxx @@ -54,6 +54,15 @@ inline int compareToIgnoreAsciiCase(std::u16string_view s1, std::u16string_view return rtl_ustr_compareIgnoreAsciiCase_WithLength(s1.data(), s1.size(), s2.data(), s2.size()); }; +// Like OUString::matchIgnoreAsciiCase, but for two std::u16string_view: +inline bool matchIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2, + sal_Int32 fromIndex = 0) +{ + return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( + s1.data() + fromIndex, s1.size() - fromIndex, s2.data(), s2.size(), s2.size()) + == 0; +} + // Similar to O[U]String::getToken, returning the first token of a std::[u16]string_view starting // at a given position. // diff --git a/sal/rtl/bootstrap.cxx b/sal/rtl/bootstrap.cxx index a0de8b92102b..68e219406cc4 100644 --- a/sal/rtl/bootstrap.cxx +++ b/sal/rtl/bootstrap.cxx @@ -63,11 +63,11 @@ namespace struct Bootstrap_Impl; -char const VND_SUN_STAR_PATHNAME[] = "vnd.sun.star.pathname:"; +constexpr std::u16string_view VND_SUN_STAR_PATHNAME = u"vnd.sun.star.pathname:"; -bool isPathnameUrl(OUString const & url) +bool isPathnameUrl(std::u16string_view url) { - return url.matchIgnoreAsciiCase(VND_SUN_STAR_PATHNAME); + return o3tl::matchIgnoreAsciiCase(url, VND_SUN_STAR_PATHNAME); } bool resolvePathnameUrl(OUString * url) @@ -75,7 +75,7 @@ bool resolvePathnameUrl(OUString * url) OSL_ASSERT(url); if (!isPathnameUrl(*url) || (osl::FileBase::getFileURLFromSystemPath( - url->copy(RTL_CONSTASCII_LENGTH(VND_SUN_STAR_PATHNAME)), *url) == + url->copy(VND_SUN_STAR_PATHNAME.size()), *url) == osl::FileBase::E_None)) { return true; diff --git a/svgio/inc/svgtools.hxx b/svgio/inc/svgtools.hxx index 550c33d88fac..6ef52ae5bf6c 100644 --- a/svgio/inc/svgtools.hxx +++ b/svgio/inc/svgtools.hxx @@ -104,7 +104,7 @@ namespace svgio::svgreader bool readNumber(std::u16string_view rCandidate, sal_Int32& nPos, double& fNum, const sal_Int32 nLen); SvgUnit readUnit(std::u16string_view rCandidate, sal_Int32& nPos, const sal_Int32 nLen); bool readNumberAndUnit(std::u16string_view rCandidate, sal_Int32& nPos, SvgNumber& aNum, const sal_Int32 nLen); - bool readAngle(const OUString& rCandidate, sal_Int32& nPos, double& fAngle, const sal_Int32 nLen); + bool readAngle(std::u16string_view rCandidate, sal_Int32& nPos, double& fAngle, const sal_Int32 nLen); sal_Int32 read_hex(sal_Unicode aChar); bool match_colorKeyword(basegfx::BColor& rColor, const OUString& rName, bool bCaseIndependent); bool read_color(const OUString& rCandidate, basegfx::BColor& rColor, bool bCaseIndependent, SvgNumber& rOpacity); diff --git a/svgio/source/svgreader/svgtools.cxx b/svgio/source/svgreader/svgtools.cxx index c6af0694fc83..9ba7f1d47952 100644 --- a/svgio/source/svgreader/svgtools.cxx +++ b/svgio/source/svgreader/svgtools.cxx @@ -402,7 +402,7 @@ namespace svgio::svgreader return false; } - bool readAngle(const OUString& rCandidate, sal_Int32& nPos, double& fAngle, const sal_Int32 nLen) + bool readAngle(std::u16string_view rCandidate, sal_Int32& nPos, double& fAngle, const sal_Int32 nLen) { if(readNumber(rCandidate, nPos, fAngle, nLen)) { @@ -418,18 +418,18 @@ namespace svgio::svgreader if(nPos < nLen) { const sal_Unicode aChar(rCandidate[nPos]); - static const char aStrGrad[] = "grad"; - static const char aStrRad[] = "rad"; + static constexpr std::u16string_view aStrGrad = u"grad"; + static constexpr std::u16string_view aStrRad = u"rad"; switch(aChar) { case u'g' : case u'G' : { - if(rCandidate.matchIgnoreAsciiCase(aStrGrad, nPos)) + if(o3tl::matchIgnoreAsciiCase(rCandidate, aStrGrad, nPos)) { // angle in grad - nPos += strlen(aStrGrad); + nPos += aStrGrad.size(); aType = DegreeType::grad; } break; @@ -437,10 +437,10 @@ namespace svgio::svgreader case u'r' : case u'R' : { - if(rCandidate.matchIgnoreAsciiCase(aStrRad, nPos)) + if(o3tl::matchIgnoreAsciiCase(rCandidate, aStrRad, nPos)) { // angle in radians - nPos += strlen(aStrRad); + nPos += aStrRad.size(); aType = DegreeType::rad; } break; diff --git a/sw/source/filter/inc/msfilter.hxx b/sw/source/filter/inc/msfilter.hxx index 39d6e4d5bf99..0ca05c0ac9f9 100644 --- a/sw/source/filter/inc/msfilter.hxx +++ b/sw/source/filter/inc/msfilter.hxx @@ -84,15 +84,15 @@ namespace sw sal_uLong MSDateTimeFormatToSwFormat(OUString& rParams, SvNumberFormatter *pFormatter, LanguageType &rLang, bool bHijri, LanguageType nDocLang); /*Used to identify if the previous token is AM time field*/ - bool IsPreviousAM(OUString const & rParams, sal_Int32 nPos); + bool IsPreviousAM(std::u16string_view rParams, sal_Int32 nPos); /*Used to identify if the next token is PM time field*/ - bool IsNextPM(OUString const & rParams, sal_Int32 nPos); + bool IsNextPM(std::u16string_view rParams, sal_Int32 nPos); /** Used by MSDateTimeFormatToSwFormat to identify AM time fields */ - bool IsNotAM(OUString const & rParams, sal_Int32 nPos); + bool IsNotAM(std::u16string_view rParams, sal_Int32 nPos); /** Another function used by MSDateTimeFormatToSwFormat diff --git a/sw/source/filter/ww8/writerwordglue.cxx b/sw/source/filter/ww8/writerwordglue.cxx index b2eb03e4a53a..e0a7fb3bb941 100644 --- a/sw/source/filter/ww8/writerwordglue.cxx +++ b/sw/source/filter/ww8/writerwordglue.cxx @@ -25,6 +25,7 @@ #include +#include #include #include #include @@ -1036,18 +1037,18 @@ namespace sw return nKey; } - bool IsPreviousAM(OUString const & rParams, sal_Int32 nPos) + bool IsPreviousAM(std::u16string_view rParams, sal_Int32 nPos) { - return nPos>=2 && rParams.matchIgnoreAsciiCase("am", nPos-2); + return nPos>=2 && o3tl::matchIgnoreAsciiCase(rParams, u"am", nPos-2); } - bool IsNextPM(OUString const & rParams, sal_Int32 nPos) + bool IsNextPM(std::u16string_view rParams, sal_Int32 nPos) { - return nPos+2=rParams.getLength() || (rParams[nPos]!='M' && rParams[nPos]!='m'); + return o3tl::make_unsigned(nPos)>=rParams.size() || (rParams[nPos]!='M' && rParams[nPos]!='m'); } void SwapQuotesInField(OUString &rFormat) diff --git a/writerfilter/source/dmapper/ConversionHelper.cxx b/writerfilter/source/dmapper/ConversionHelper.cxx index 357f4878c5b9..5c3b0831ff1f 100644 --- a/writerfilter/source/dmapper/ConversionHelper.cxx +++ b/writerfilter/source/dmapper/ConversionHelper.cxx @@ -296,13 +296,13 @@ bool lcl_IsNotAM(OUString const & rFmt, sal_Int32 nPos) ) ); } -bool IsPreviousAM(OUString const& rParams, sal_Int32 nPos) +bool IsPreviousAM(std::u16string_view rParams, sal_Int32 nPos) { - return nPos >= 2 && rParams.matchIgnoreAsciiCase("am", nPos - 2); + return nPos >= 2 && o3tl::matchIgnoreAsciiCase(rParams, u"am", nPos - 2); } -bool IsNextPM(OUString const& rParams, sal_Int32 nPos) +bool IsNextPM(std::u16string_view rParams, sal_Int32 nPos) { - return nPos + 2 < rParams.getLength() && rParams.matchIgnoreAsciiCase("pm", nPos + 1); + return o3tl::make_unsigned(nPos + 2) < rParams.size() && o3tl::matchIgnoreAsciiCase(rParams, u"pm", nPos + 1); } }