add o3tl::matchIgnoreAsciiCase

Change-Id: Iad8e1ed256d84808404bf20ed7a16b05b3db5818
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133753
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2022-05-02 16:36:43 +02:00
parent a56474374b
commit 8bf380f7d3
10 changed files with 43 additions and 32 deletions

View file

@ -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());
}

View file

@ -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;
}

View file

@ -32,6 +32,7 @@
#include <rtl/uri.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
#include <o3tl/string_view.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
@ -1265,12 +1266,12 @@ Sequence< Reference<deployment::XPackage> > 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"));
}

View file

@ -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.
//

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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

View file

@ -25,6 +25,7 @@
#include <algorithm>
#include <o3tl/string_view.hxx>
#include <rtl/tencinfo.h>
#include <sal/log.hxx>
#include <svl/numformat.hxx>
@ -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.matchIgnoreAsciiCase("pm", nPos+1);
return o3tl::make_unsigned(nPos+2)<rParams.size() && o3tl::matchIgnoreAsciiCase(rParams, u"pm", nPos+1);
}
bool IsNotAM(OUString const & rParams, sal_Int32 nPos)
bool IsNotAM(std::u16string_view rParams, sal_Int32 nPos)
{
++nPos;
return nPos>=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)

View file

@ -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);
}
}