summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-05-20 12:54:07 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-05-20 19:54:57 +0200
commit6510cbc486867db25d1d772f4a3b0b7b9bb2fc08 (patch)
tree629597e0e801659b06edb181bda017cdd823e04b /include
parent443799ad8c0f5a2ae78ca03fb38618a2273682aa (diff)
elide temporary OUStringBuffer in INetURLObject
which requires a version of replaceAt for OUStringBuffer, which I'll put in comphelper::string:: for now Change-Id: I70b319b018e29a7dac26965dd92f6c4f9ea470ec Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134679 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include')
-rw-r--r--include/comphelper/string.hxx7
-rw-r--r--include/tools/urlobj.hxx64
2 files changed, 58 insertions, 13 deletions
diff --git a/include/comphelper/string.hxx b/include/comphelper/string.hxx
index 4fe10b71b3f0..86ca9c4d8ecb 100644
--- a/include/comphelper/string.hxx
+++ b/include/comphelper/string.hxx
@@ -231,6 +231,13 @@ inline OUStringBuffer& padToLength(
return detail::padToLength(rBuffer, nLength, cFill);
}
+/** Similar to OUString::replaceAt, but for an OUStringBuffer.
+
+ Replace n = count characters
+ from position index in this string with newStr.
+ */
+COMPHELPER_DLLPUBLIC void replaceAt(OUStringBuffer& rIn, sal_Int32 index, sal_Int32 count, std::u16string_view newStr );
+
/** Replace a token in a string
@param rIn OUString in which the token is to be replaced
@param nToken which nToken to replace
diff --git a/include/tools/urlobj.hxx b/include/tools/urlobj.hxx
index b99187a1caa3..6096e60df1b2 100644
--- a/include/tools/urlobj.hxx
+++ b/include/tools/urlobj.hxx
@@ -822,10 +822,33 @@ public:
@return The text, encoded according to the given mechanism and
charset ('forbidden' characters replaced by escape sequences).
*/
- static inline OUString encode(std::u16string_view rText, Part ePart,
- EncodeMechanism eMechanism,
- rtl_TextEncoding eCharset
- = RTL_TEXTENCODING_UTF8);
+ static void encode( OUStringBuffer& rOutputBuffer,
+ std::u16string_view rText, Part ePart,
+ EncodeMechanism eMechanism,
+ rtl_TextEncoding eCharset
+ = RTL_TEXTENCODING_UTF8);
+
+ /** Encode some text as part of a URI.
+
+ @param rText Some text (for its interpretation, see the general
+ discussion for set-methods).
+
+ @param ePart The part says which characters are 'forbidden' and must
+ be encoded (replaced by escape sequences). Characters outside the US-
+ ASCII range are always 'forbidden.'
+
+ @param eMechanism See the general discussion for set-methods.
+
+ @param eCharset See the general discussion for set-methods.
+
+ @return The text, encoded according to the given mechanism and
+ charset ('forbidden' characters replaced by escape sequences).
+ */
+ static OUString encode( std::u16string_view rText, Part ePart,
+ EncodeMechanism eMechanism,
+ rtl_TextEncoding eCharset
+ = RTL_TEXTENCODING_UTF8);
+
/** Decode some text.
@@ -1093,12 +1116,14 @@ private:
TOOLS_DLLPRIVATE static inline void appendEscape(
OUStringBuffer & rTheText, sal_uInt32 nOctet);
- static OUString encodeText(
+ static void encodeText(
+ OUStringBuffer& rOutputBuffer,
sal_Unicode const * pBegin, sal_Unicode const * pEnd,
Part ePart, EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
bool bKeepVisibleEscapes);
- static inline OUString encodeText(
+ static inline void encodeText(
+ OUStringBuffer& rOutputBuffer,
std::u16string_view rTheText, Part ePart,
EncodeMechanism eMechanism, rtl_TextEncoding eCharset,
bool bKeepVisibleEscapes);
@@ -1118,15 +1143,17 @@ private:
};
// static
-inline OUString INetURLObject::encodeText(std::u16string_view rTheText,
+inline void INetURLObject::encodeText( OUStringBuffer& rOutputBuffer,
+ std::u16string_view rTheText,
Part ePart,
EncodeMechanism eMechanism,
rtl_TextEncoding eCharset,
bool bKeepVisibleEscapes)
{
- return encodeText(rTheText.data(),
- rTheText.data() + rTheText.size(), ePart,
- eMechanism, eCharset, bKeepVisibleEscapes);
+ encodeText(rOutputBuffer,
+ rTheText.data(),
+ rTheText.data() + rTheText.size(), ePart,
+ eMechanism, eCharset, bKeepVisibleEscapes);
}
inline OUString INetURLObject::decode(SubString const & rSubString,
@@ -1284,11 +1311,22 @@ inline bool INetURLObject::SetMark(std::u16string_view rTheFragment,
}
// static
+inline void INetURLObject::encode(OUStringBuffer& rOutputBuffer,
+ std::u16string_view rText, Part ePart,
+ EncodeMechanism eMechanism,
+ rtl_TextEncoding eCharset)
+{
+ encodeText(rOutputBuffer, rText, ePart, eMechanism, eCharset, false);
+}
+
+// static
inline OUString INetURLObject::encode(std::u16string_view rText, Part ePart,
- EncodeMechanism eMechanism,
- rtl_TextEncoding eCharset)
+ EncodeMechanism eMechanism,
+ rtl_TextEncoding eCharset)
{
- return encodeText(rText, ePart, eMechanism, eCharset, false);
+ OUStringBuffer aBuf;
+ encodeText(aBuf, rText, ePart, eMechanism, eCharset, false);
+ return aBuf.makeStringAndClear();
}
// static