diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-04-10 15:36:21 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-04-10 20:15:16 +0200 |
commit | b24a4d255d31233c48152e6e1ce992a693cdaeae (patch) | |
tree | e0ad8f574d3b1ddcad3d81ec3ac438777ca4846d /stoc | |
parent | 57f22d9b1a4e1cd161a35c8e4c390661db981d2c (diff) |
use more string_view
found by tweaking the loplugin:stringview and making it whitelist
getLength
Change-Id: Ic15d3703d1fb07658e99e1db1c89e2fa5bc70c19
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132771
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'stoc')
-rw-r--r-- | stoc/source/uriproc/UriReferenceFactory.cxx | 14 | ||||
-rw-r--r-- | stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx | 19 |
2 files changed, 17 insertions, 16 deletions
diff --git a/stoc/source/uriproc/UriReferenceFactory.cxx b/stoc/source/uriproc/UriReferenceFactory.cxx index bb96a55d88ed..254097c179fe 100644 --- a/stoc/source/uriproc/UriReferenceFactory.cxx +++ b/stoc/source/uriproc/UriReferenceFactory.cxx @@ -53,10 +53,10 @@ namespace { -bool equalIgnoreEscapeCase(OUString const & s1, OUString const & s2) { - if (s1.getLength() == s2.getLength()) { - for (sal_Int32 i = 0; i < s1.getLength();) { - if (s1[i] == '%' && s2[i] == '%' && s1.getLength() - i > 2 +bool equalIgnoreEscapeCase(std::u16string_view s1, std::u16string_view s2) { + if (s1.size() == s2.size()) { + for (size_t i = 0; i < s1.size();) { + if (s1[i] == '%' && s2[i] == '%' && s1.size() - i > 2 && rtl::isAsciiHexDigit(s1[i + 1]) && rtl::isAsciiHexDigit(s1[i + 2]) && rtl::isAsciiHexDigit(s2[i + 1]) @@ -77,9 +77,9 @@ bool equalIgnoreEscapeCase(OUString const & s1, OUString const & s2) { } } -sal_Int32 parseScheme(OUString const & uriReference) { - if (uriReference.getLength() >= 2 && rtl::isAsciiAlpha(uriReference[0])) { - for (sal_Int32 i = 0; i < uriReference.getLength(); ++i) { +sal_Int32 parseScheme(std::u16string_view uriReference) { + if (uriReference.size() >= 2 && rtl::isAsciiAlpha(uriReference[0])) { + for (size_t i = 0; i < uriReference.size(); ++i) { sal_Unicode c = uriReference[i]; if (c == ':') { return i; diff --git a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx index 59eadd9f2db2..ac37da853a83 100644 --- a/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx +++ b/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTscript.cxx @@ -33,6 +33,7 @@ #include <rtl/ustrbuf.hxx> #include <rtl/ustring.hxx> #include <sal/types.h> +#include <o3tl/safeint.hxx> #include <string_view> @@ -49,8 +50,8 @@ int getHexWeight(sal_Unicode c) { : -1; } -int parseEscaped(OUString const & part, sal_Int32 * index) { - if (part.getLength() - *index < 3 || part[*index] != '%') { +int parseEscaped(std::u16string_view part, sal_Int32 * index) { + if (part.size() - *index < 3 || part[*index] != '%') { return -1; } int n1 = getHexWeight(part[*index + 1]); @@ -63,10 +64,10 @@ int parseEscaped(OUString const & part, sal_Int32 * index) { } OUString parsePart( - OUString const & part, bool namePart, sal_Int32 * index) + std::u16string_view part, bool namePart, sal_Int32 * index) { OUStringBuffer buf(64); - while (*index < part.getLength()) { + while (o3tl::make_unsigned(*index) < part.size()) { sal_Unicode c = part[*index]; if (namePart ? c == '?' : c == '&' || c == '=') { break; @@ -150,25 +151,25 @@ OUString encodeNameOrParamFragment(OUString const & fragment) { RTL_TEXTENCODING_UTF8); } -bool parseSchemeSpecificPart(OUString const & part) { - sal_Int32 len = part.getLength(); +bool parseSchemeSpecificPart(std::u16string_view part) { + size_t len = part.size(); sal_Int32 i = 0; if (parsePart(part, true, &i).isEmpty() || part[0] == '/') { return false; } - if (i == len) { + if (o3tl::make_unsigned(i) == len) { return true; } for (;;) { ++i; // skip '?' or '&' - if (parsePart(part, false, &i).isEmpty() || i == len + if (parsePart(part, false, &i).isEmpty() || o3tl::make_unsigned(i) == len || part[i] != '=') { return false; } ++i; parsePart(part, false, &i); - if (i == len) { + if (o3tl::make_unsigned(i) == len) { return true; } if (part[i] != '&') { |