diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-09-10 10:52:57 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-09-17 15:05:11 +0200 |
commit | caa211b62048ac5037b3fd4320f3eb4dea7b639d (patch) | |
tree | cf1768b435ed71363e34b56682435628545a7293 /sal/rtl/uri.cxx | |
parent | b9ce783a4b8ea967281ed583842ee3d931d78ac7 (diff) |
Better handling of non--UTF-8 filesystem pathnames in sal/osl/unx/
The idea is to internally in sal/osl/unx/ use OString instead of OUString to
represent pathnames, so that the OString carries the actual bytes that make up
the pathname. At the boundary of translating between pathname OStrings and file
URL OUStrings, translate sequences of bytes that are valid according to
osl_getThreadTextEncoding() into UTF-8 and translate other bytes into individual
(percent-encoded) bytes in the file URL.
This change required duplicating some of the internal functionality in
sal/osl/unx/ for both OString and OUString, and to make part of sal/rtl/uri.cxx
accessible from sal/osl/unx/ via new sal/inc/uri_internal.hxx.
Change-Id: Id1ebaebe9e7f2d21f350f6b1a07849edee54331f
Reviewed-on: https://gerrit.libreoffice.org/78798
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal/rtl/uri.cxx')
-rw-r--r-- | sal/rtl/uri.cxx | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/sal/rtl/uri.cxx b/sal/rtl/uri.cxx index 07634c628de6..0504650b80fe 100644 --- a/sal/rtl/uri.cxx +++ b/sal/rtl/uri.cxx @@ -29,6 +29,8 @@ #include <sal/types.h> #include <sal/macros.h> +#include <uri_internal.hxx> + #include <algorithm> #include <cstddef> @@ -60,12 +62,9 @@ void writeUnicode(rtl_uString ** pBuffer, sal_Int32 * pCapacity, rtl_uStringbuffer_insert(pBuffer, pCapacity, (*pBuffer)->length, &cChar, 1); } -enum EscapeType -{ - EscapeNo, - EscapeChar, - EscapeOctet -}; +} + +namespace rtl::uri::detail { /** Read any of the following: @@ -214,6 +213,10 @@ sal_uInt32 readUcs4(sal_Unicode const ** pBegin, sal_Unicode const * pEnd, rtl::combineSurrogates(nChar, *(*pBegin)++) : nChar; } +} + +namespace { + void writeUcs4(rtl_uString ** pBuffer, sal_Int32 * pCapacity, sal_uInt32 nUtf32) { assert(rtl::isUnicodeCodePoint(nUtf32)); @@ -640,8 +643,8 @@ void SAL_CALL rtl_uriEncode(rtl_uString * pText, sal_Bool const * pCharClass, while (p < pEnd) { - EscapeType eType; - sal_uInt32 nUtf32 = readUcs4( + rtl::uri::detail::EscapeType eType; + sal_uInt32 nUtf32 = rtl::uri::detail::readUcs4( &p, pEnd, (eMechanism == rtl_UriEncodeKeepEscapes || eMechanism == rtl_UriEncodeCheckEscapes @@ -650,7 +653,7 @@ void SAL_CALL rtl_uriEncode(rtl_uString * pText, sal_Bool const * pCharClass, switch (eType) { - case EscapeNo: + case rtl::uri::detail::EscapeNo: if (isValid(pCharClass, nUtf32)) // implies nUtf32 <= 0x7F { writeUnicode(pResult, &nCapacity, @@ -666,7 +669,7 @@ void SAL_CALL rtl_uriEncode(rtl_uString * pText, sal_Bool const * pCharClass, } break; - case EscapeChar: + case rtl::uri::detail::EscapeChar: if (eMechanism == rtl_UriEncodeCheckEscapes && isValid(pCharClass, nUtf32)) // implies nUtf32 <= 0x7F { @@ -683,7 +686,7 @@ void SAL_CALL rtl_uriEncode(rtl_uString * pText, sal_Bool const * pCharClass, } break; - case EscapeOctet: + case rtl::uri::detail::EscapeOctet: writeEscapeOctet(pResult, &nCapacity, nUtf32); break; } @@ -714,11 +717,11 @@ void SAL_CALL rtl_uriDecode(rtl_uString * pText, while (p < pEnd) { - EscapeType eType; - sal_uInt32 nUtf32 = readUcs4(&p, pEnd, true, eCharset, &eType); + rtl::uri::detail::EscapeType eType; + sal_uInt32 nUtf32 = rtl::uri::detail::readUcs4(&p, pEnd, true, eCharset, &eType); switch (eType) { - case EscapeChar: + case rtl::uri::detail::EscapeChar: if (nUtf32 <= 0x7F && eMechanism == rtl_UriDecodeToIuri) { writeEscapeOctet(pResult, &nCapacity, nUtf32); @@ -726,11 +729,11 @@ void SAL_CALL rtl_uriDecode(rtl_uString * pText, } [[fallthrough]]; - case EscapeNo: + case rtl::uri::detail::EscapeNo: writeUcs4(pResult, &nCapacity, nUtf32); break; - case EscapeOctet: + case rtl::uri::detail::EscapeOctet: if (eMechanism == rtl_UriDecodeStrict) { rtl_uString_new(pResult); |