diff options
-rw-r--r-- | compilerplugins/clang/implicitboolconversion.cxx | 21 | ||||
-rw-r--r-- | compilerplugins/clang/test/implicitboolconversion.cxx | 3 | ||||
-rw-r--r-- | include/rtl/uri.hxx | 41 | ||||
-rw-r--r-- | sal/osl/unx/file_url.cxx | 23 | ||||
-rw-r--r-- | sal/rtl/uri.cxx | 159 | ||||
-rw-r--r-- | vcl/source/treelist/transfer.cxx | 17 |
6 files changed, 91 insertions, 173 deletions
diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx index d0bdff190807..29b82d8eae25 100644 --- a/compilerplugins/clang/implicitboolconversion.cxx +++ b/compilerplugins/clang/implicitboolconversion.cxx @@ -179,16 +179,23 @@ bool isBoolExpr(Expr const * expr) { (void)op; TemplateDecl const * d = t->getTemplateName().getAsTemplateDecl(); - if (d == nullptr - || !loplugin::DeclCheck(d->getTemplatedDecl()).Class("Sequence") - .Namespace("uno").Namespace("star").Namespace("sun").Namespace("com") - .GlobalNamespace() - || t->getNumArgs() != 1 - || t->getArg(0).getKind() != TemplateArgument::Type) + if (d == nullptr) { + break; + } + auto const dc = loplugin::DeclCheck(d->getTemplatedDecl()); + if (dc.ClassOrStruct("array").StdNamespace() && t->getNumArgs() >= 2 + && t->getArg(0).getKind() == TemplateArgument::Type) { + ty = t->getArg(0).getAsType(); + } else if (dc.Class("Sequence").Namespace("uno").Namespace("star").Namespace("sun") + .Namespace("com").GlobalNamespace() + && t->getNumArgs() == 1 + && t->getArg(0).getKind() == TemplateArgument::Type) + { + ty = t->getArg(0).getAsType(); + } else { break; } - ty = t->getArg(0).getAsType(); } stack.pop(); if (stack.empty()) { diff --git a/compilerplugins/clang/test/implicitboolconversion.cxx b/compilerplugins/clang/test/implicitboolconversion.cxx index fa5a2b84b905..122ee363ae68 100644 --- a/compilerplugins/clang/test/implicitboolconversion.cxx +++ b/compilerplugins/clang/test/implicitboolconversion.cxx @@ -9,6 +9,7 @@ #include <sal/config.h> +#include <array> #include <atomic> #include <initializer_list> @@ -75,6 +76,8 @@ void f() h(w1.element); css::uno::Sequence<sal_Bool> s7(1); h(s7[0]); + std::array<sal_Bool, 1> s8; + s8[0] = false; } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/rtl/uri.hxx b/include/rtl/uri.hxx index 0ab1726dab99..1b2601e7d1d1 100644 --- a/include/rtl/uri.hxx +++ b/include/rtl/uri.hxx @@ -30,6 +30,14 @@ #include "rtl/ustring.hxx" #include "sal/types.h" +#if defined LIBO_INTERNAL_ONLY +#include <array> +#include <cassert> +#include <cstddef> +#include <string_view> +#include "config_global.h" +#endif + namespace rtl { /** A wrapper around the C functions from <rtl/uri.h>. @@ -131,6 +139,39 @@ inline rtl::OUString Uri::convertRelToAbs(rtl::OUString const & rBaseUriRef, return aResult; } +#if defined LIBO_INTERNAL_ONLY + +constexpr std::size_t UriCharClassSize = 128; + +// Create a char class (for use with rtl_uriEncode and rtl::Uri::encode), represented as a +// compile-time std::array, from an UTF-8 string literal. +// +// The given `unencoded` lists each ASCII character once that shall not be encoded. (It uses an +// UTF-8 string type to emphasize that its characters' values are always interpreted as ASCII +// values.) +#if HAVE_CPP_CONSTEVAL +consteval +#else +constexpr +#endif +auto createUriCharClass( +#if defined __cpp_lib_char8_t + std::u8string_view +#else + std::string_view +#endif + unencoded) +{ + std::array<sal_Bool, UriCharClassSize> a = {}; + for (auto c: unencoded) { + assert(!a[c]); // would presumably indicate a typo in the `unencoded` argument + a[c] = true; + } + return a; +} + +#endif + } #endif // INCLUDED_RTL_URI_HXX diff --git a/sal/osl/unx/file_url.cxx b/sal/osl/unx/file_url.cxx index a738010f867b..2e21684eba8f 100644 --- a/sal/osl/unx/file_url.cxx +++ b/sal/osl/unx/file_url.cxx @@ -79,23 +79,8 @@ namespace { // A slightly modified version of Pchar in rtl/source/uri.c, but without // encoding slashes: -const sal_Bool uriCharClass[128] = { - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, true, false, false, true, false, true, true, // !"#$%&' - true, true, true, true, true, true, true, true, // ()*+,-./ - true, true, true, true, true, true, true, true, // 01234567 - true, true, true, false, false, true, false, false, // 89:;<=>? - true, true, true, true, true, true, true, true, // @ABCDEFG - true, true, true, true, true, true, true, true, // HIJKLMNO - true, true, true, true, true, true, true, true, // PQRSTUVW - true, true, true, false, false, false, false, true, // XYZ[\]^_ - false, true, true, true, true, true, true, true, // `abcdefg - true, true, true, true, true, true, true, true, // hijklmno - true, true, true, true, true, true, true, true, // pqrstuvw - true, true, true, false, false, false, true, false}; // xyz{|}~ +constexpr auto uriCharClass = rtl::createUriCharClass( + u8"!$&'()*+,-./0123456789:=@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~"); } @@ -439,7 +424,7 @@ oslFileError SAL_CALL osl_getFileURLFromSystemPath( rtl_uString *ustrSystemPath, rtl_uString_assign( &pTmp, systemPath.pData ); /* file URLs must be URI encoded */ - rtl_uriEncode( pTmp, uriCharClass, rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8, pustrFileURL ); + rtl_uriEncode( pTmp, uriCharClass.data(), rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8, pustrFileURL ); rtl_uString_release( pTmp ); @@ -957,7 +942,7 @@ oslFileError osl::detail::convertPathnameToUrl(OString const & pathname, OUStrin ubuf.setLength(n); buf.append( rtl::Uri::encode( - ubuf.makeStringAndClear(), uriCharClass, rtl_UriEncodeIgnoreEscapes, + ubuf.makeStringAndClear(), uriCharClass.data(), rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8)); assert(converted <= convert); convert -= converted; diff --git a/sal/rtl/uri.cxx b/sal/rtl/uri.cxx index 0c5479563405..3414552615e6 100644 --- a/sal/rtl/uri.cxx +++ b/sal/rtl/uri.cxx @@ -22,6 +22,7 @@ #include <rtl/textenc.h> #include <rtl/textcvt.h> #include <rtl/uri.h> +#include <rtl/uri.hxx> #include <rtl/ustrbuf.h> #include <rtl/ustrbuf.hxx> #include <rtl/ustring.h> @@ -36,8 +37,6 @@ namespace { -std::size_t const nCharClassSize = 128; - sal_Unicode const cEscapePrefix = 0x25; // '%' int getHexWeight(sal_uInt32 nUtf32) @@ -53,7 +52,7 @@ int getHexWeight(sal_uInt32 nUtf32) bool isValid(sal_Bool const * pCharClass, sal_uInt32 nUtf32) { - return nUtf32 < nCharClassSize && pCharClass[nUtf32]; + return nUtf32 < rtl::UriCharClassSize && pCharClass[nUtf32]; } void writeUnicode(rtl_uString ** pBuffer, sal_Int32 * pCapacity, @@ -465,141 +464,35 @@ void appendPath( sal_Bool const * SAL_CALL rtl_getUriCharClass(rtl_UriCharClass eCharClass) SAL_THROW_EXTERN_C() { - static sal_Bool const aCharClass[][nCharClassSize] = { - {false, false, false, false, false, false, false, false,// None - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, // !"#$%&' - false, false, false, false, false, false, false, false, // ()*+,-./ - false, false, false, false, false, false, false, false, // 01234567 - false, false, false, false, false, false, false, false, // 89:;<=>? - false, false, false, false, false, false, false, false, // @ABCDEFG - false, false, false, false, false, false, false, false, // HIJKLMNO - false, false, false, false, false, false, false, false, // PQRSTUVW - false, false, false, false, false, false, false, false, // XYZ[\]^_ - false, false, false, false, false, false, false, false, // `abcdefg - false, false, false, false, false, false, false, false, // hijklmno - false, false, false, false, false, false, false, false, // pqrstuvw - false, false, false, false, false, false, false, false}, // xyz{|}~ - {false, false, false, false, false, false, false, false,// Uric - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, true, false, false, true, false, true, true, // !"#$%&' - true, true, true, true, true, true, true, true, // ()*+,-./ - true, true, true, true, true, true, true, true, // 01234567 - true, true, true, true, false, true, false, true, // 89:;<=>? - true, true, true, true, true, true, true, true, // @ABCDEFG - true, true, true, true, true, true, true, true, // HIJKLMNO - true, true, true, true, true, true, true, true, // PQRSTUVW - true, true, true, true, false, true, false, true, // XYZ[\]^_ - false, true, true, true, true, true, true, true, // `abcdefg - true, true, true, true, true, true, true, true, // hijklmno - true, true, true, true, true, true, true, true, // pqrstuvw - true, true, true, false, false, false, true, false}, // xyz{|}~ - {false, false, false, false, false, false, false, false,// UricNoSlash - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, true, false, false, true, false, true, true, // !"#$%&' - true, true, true, true, true, true, true, false, // ()*+,-./ - true, true, true, true, true, true, true, true, // 01234567 - true, true, true, true, false, true, false, true, // 89:;<=>? - true, true, true, true, true, true, true, true, // @ABCDEFG - true, true, true, true, true, true, true, true, // HIJKLMNO - true, true, true, true, true, true, true, true, // PQRSTUVW - true, true, true, false, false, false, false, true, // XYZ[\]^_ - false, true, true, true, true, true, true, true, // `abcdefg - true, true, true, true, true, true, true, true, // hijklmno - true, true, true, true, true, true, true, true, // pqrstuvw - true, true, true, false, false, false, true, false}, // xyz{|}~ - {false, false, false, false, false, false, false, false,// RelSegment - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, true, false, false, true, false, true, true, // !"#$%&' - true, true, true, true, true, true, true, false, // ()*+,-./ - true, true, true, true, true, true, true, true, // 01234567 - true, true, false, true, false, true, false, false, // 89:;<=>? - true, true, true, true, true, true, true, true, // @ABCDEFG - true, true, true, true, true, true, true, true, // HIJKLMNO - true, true, true, true, true, true, true, true, // PQRSTUVW - true, true, true, false, false, false, false, true, // XYZ[\]^_ - false, true, true, true, true, true, true, true, // `abcdefg - true, true, true, true, true, true, true, true, // hijklmno - true, true, true, true, true, true, true, true, // pqrstuvw - true, true, true, false, false, false, true, false}, // xyz{|}~ - {false, false, false, false, false, false, false, false,// RegName - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, true, false, false, true, false, true, true, // !"#$%&' - true, true, true, true, true, true, true, false, // ()*+,-./ - true, true, true, true, true, true, true, true, // 01234567 - true, true, true, true, false, true, false, false, // 89:;<=>? - true, true, true, true, true, true, true, true, // @ABCDEFG - true, true, true, true, true, true, true, true, // HIJKLMNO - true, true, true, true, true, true, true, true, // PQRSTUVW - true, true, true, false, false, false, false, true, // XYZ[\]^_ - false, true, true, true, true, true, true, true, // `abcdefg - true, true, true, true, true, true, true, true, // hijklmno - true, true, true, true, true, true, true, true, // pqrstuvw - true, true, true, false, false, false, true, false}, // xyz{|}~ - {false, false, false, false, false, false, false, false,// Userinfo - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, true, false, false, true, false, true, true, // !"#$%&' - true, true, true, true, true, true, true, false, // ()*+,-./ - true, true, true, true, true, true, true, true, // 01234567 - true, true, true, true, false, true, false, false, // 89:;<=>? - false, true, true, true, true, true, true, true, // @ABCDEFG - true, true, true, true, true, true, true, true, // HIJKLMNO - true, true, true, true, true, true, true, true, // PQRSTUVW - true, true, true, false, false, false, false, true, // XYZ[\]^_ - false, true, true, true, true, true, true, true, // `abcdefg - true, true, true, true, true, true, true, true, // hijklmno - true, true, true, true, true, true, true, true, // pqrstuvw - true, true, true, false, false, false, true, false}, // xyz{|}~ - {false, false, false, false, false, false, false, false,// Pchar - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, true, false, false, true, false, true, true, // !"#$%&' - true, true, true, true, true, true, true, false, // ()*+,-./ - true, true, true, true, true, true, true, true, // 01234567 - true, true, true, false, false, true, false, false, // 89:;<=>? - true, true, true, true, true, true, true, true, // @ABCDEFG - true, true, true, true, true, true, true, true, // HIJKLMNO - true, true, true, true, true, true, true, true, // PQRSTUVW - true, true, true, false, false, false, false, true, // XYZ[\]^_ - false, true, true, true, true, true, true, true, // `abcdefg - true, true, true, true, true, true, true, true, // hijklmno - true, true, true, true, true, true, true, true, // pqrstuvw - true, true, true, false, false, false, true, false}, // xyz{|}~ - {false, false, false, false, false, false, false, false,// UnoParamValue - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, false, false, false, false, false, false, false, - false, true, false, false, true, false, true, true, // !"#$%&' - true, true, true, true, false, true, true, true, // ()*+,-./ - true, true, true, true, true, true, true, true, // 01234567 - true, true, true, false, false, false, false, true, // 89:;<=>? - true, true, true, true, true, true, true, true, // @ABCDEFG - true, true, true, true, true, true, true, true, // HIJKLMNO - true, true, true, true, true, true, true, true, // PQRSTUVW - true, true, true, false, false, false, false, true, // XYZ[\]^_ - false, true, true, true, true, true, true, true, // `abcdefg - true, true, true, true, true, true, true, true, // hijklmno - true, true, true, true, true, true, true, true, // pqrstuvw - true, true, true, false, false, false, true, false}}; // xyz{|}~ + static constexpr std::array<sal_Bool, rtl::UriCharClassSize> aCharClass[] = { + rtl::createUriCharClass(u8""), // None + rtl::createUriCharClass( + u8"!$&'()*+,-./:;=?@[]_~" + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), // Uric + rtl::createUriCharClass( + u8"!$&'()*+,-.:;=?@_~" + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), // UricNoSlash + rtl::createUriCharClass( + u8"!$&'()*+,-.;=@_~" + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), // RelSegment + rtl::createUriCharClass( + u8"!$&'()*+,-.:;=@_~" + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), // RegName + rtl::createUriCharClass( + u8"!$&'()*+,-.:;=_~" + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), // Userinfo + rtl::createUriCharClass( + u8"!$&'()*+,-.:=@_~" + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), // Pchar + rtl::createUriCharClass( + u8"!$&'()*+-./:?@_~" + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")}; // UnoParamValue assert( (eCharClass >= 0 && (sal::static_int_cast< std::size_t >(eCharClass) < SAL_N_ELEMENTS(aCharClass)))); // bad eCharClass - return aCharClass[eCharClass]; + return aCharClass[eCharClass].data(); } void SAL_CALL rtl_uriEncode(rtl_uString * pText, sal_Bool const * pCharClass, diff --git a/vcl/source/treelist/transfer.cxx b/vcl/source/treelist/transfer.cxx index 23a865a0a3f0..73c3df80015d 100644 --- a/vcl/source/treelist/transfer.cxx +++ b/vcl/source/treelist/transfer.cxx @@ -132,23 +132,12 @@ static OUString ImplGetParameterString( const TransferableObjectDescriptor& rObj { // the display name might contain unacceptable characters, encode all of them // this seems to be the only parameter currently that might contain such characters - sal_Bool pToAccept[128]; - for (sal_Bool & rb : pToAccept) - rb = false; - - const char aQuotedParamChars[] = - "()<>@,;:/[]?=!#$&'*+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~. "; - - for ( sal_Int32 nInd = 0; nInd < RTL_CONSTASCII_LENGTH(aQuotedParamChars); ++nInd ) - { - sal_Unicode nChar = aQuotedParamChars[nInd]; - if ( nChar < 128 ) - pToAccept[nChar] = true; - } + static constexpr auto pToAccept = rtl::createUriCharClass( + u8"()<>@,;:/[]?=!#$&'*+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~. "); aParams += ";displayname=\"" + rtl::Uri::encode( - rObjDesc.maDisplayName, pToAccept, rtl_UriEncodeIgnoreEscapes, + rObjDesc.maDisplayName, pToAccept.data(), rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8) + "\""; } |