summaryrefslogtreecommitdiff
path: root/include/rtl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2023-07-21 14:20:57 +0200
committerStephan Bergmann <sbergman@redhat.com>2023-07-31 07:58:08 +0200
commit6fce450b8a66d7e98a4d39528f8591184277e9fa (patch)
treed2bde14c195b0288e7efc3f3e6db06888759855b /include/rtl
parent3564e11a41c8d3f06c8be387691d5997942e9738 (diff)
Introduce "..."_tstr as a companion to "..."_ostr/u"..."_ustr in template code
...like > *path = "/"; in > template<typename T> oslFileError getSystemPathFromFileUrl( > OUString const & url, T * path, bool resolveHome) in sal/osl/unx/file_url.cxx, where T is either OString or OUString. That can now be replaced with > *path = "/"_tstr; and for OString it will be a no-cost constexpr operation, while for OUString it will still construct the OUString instance at runtime (as did the original code for both OString and OUString). (This change required moving the definition of rtl::detail::OStringHolder around in include/rtl/string.hxx. For consistency, I similarly moved around the definition of rtl::detail::OUStringHolder in include/rtl/ustring.hxx, too.) Change-Id: I7fb3a81b438f98c609684f7e70b7a60068d32fdb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154748 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/rtl')
-rw-r--r--include/rtl/string.hxx51
-rw-r--r--include/rtl/ustring.hxx37
2 files changed, 64 insertions, 24 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index aae291f46053..eae18bc30d0d 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -186,6 +186,18 @@ private:
rtl_String* pData;
};
+#if __cplusplus >= 202002L
+
+namespace detail {
+
+template<OStringLiteral L> struct OStringHolder {
+ static constexpr auto & literal = L;
+};
+
+}
+
+#endif
+
#endif
/* ======================================================================= */
@@ -384,6 +396,12 @@ public:
/// @endcond
#endif
+#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+ // For operator ""_tstr:
+ template<OStringLiteral L> constexpr OString(detail::OStringHolder<L> const & holder):
+ pData(const_cast<rtl_String *>(&holder.literal.str)) {}
+#endif
+
#if defined LIBO_INTERNAL_ONLY
explicit OString(std::string_view sv) {
if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
@@ -2275,18 +2293,6 @@ inline bool operator !=(StringConcatenation<char> const & lhs, OString const & r
#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
-#if __cplusplus >= 202002L
-
-namespace detail {
-
-template<OStringLiteral L> struct OStringHolder {
- static constexpr auto & literal = L;
-};
-
-}
-
-#endif
-
/**
@internal
*/
@@ -2409,6 +2415,27 @@ operator ""_ostr() {
::detail::OStringHolder<L>::literal;
}
+template<
+#if defined RTL_STRING_UNITTEST
+ rtlunittest::
+#endif
+ OStringLiteral L>
+constexpr
+#if defined RTL_STRING_UNITTEST
+rtlunittest
+#else
+rtl
+#endif
+::detail::OStringHolder<L> operator ""_tstr() {
+ return
+#if defined RTL_STRING_UNITTEST
+ rtlunittest
+#else
+ rtl
+#endif
+ ::detail::OStringHolder<L>();
+}
+
#endif
/// @cond INTERNAL
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 90b195754a17..c273c76ace6a 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -175,6 +175,18 @@ private:
rtl_uString* pData;
};
+#if __cplusplus >= 202002L
+
+namespace detail {
+
+template<OUStringLiteral L> struct OUStringHolder {
+ static constexpr auto & literal = L;
+};
+
+}
+
+#endif
+
/// @endcond
#endif
@@ -440,6 +452,19 @@ public:
/// @endcond
#endif
+#if defined LIBO_INTERNAL_ONLY && __cplusplus >= 202002L
+ // For operator ""_tstr:
+ template<OStringLiteral L> OUString(detail::OStringHolder<L> const & holder) {
+ pData = nullptr;
+ if (holder.literal.getLength() == 0) {
+ rtl_uString_new(&pData);
+ } else {
+ rtl_uString_newFromLiteral(
+ &pData, holder.literal.getStr(), holder.literal.getLength(), 0);
+ }
+ }
+#endif
+
/**
New string from an 8-Bit character buffer array.
@@ -3414,18 +3439,6 @@ inline bool operator !=(StringConcatenation<char16_t> const & lhs, OUString cons
#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
/// @cond INTERNAL
-#if __cplusplus >= 202002L
-
-namespace detail {
-
-template<OUStringLiteral L> struct OUStringHolder {
- static constexpr auto & literal = L;
-};
-
-}
-
-#endif
-
/**
@internal
*/