diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/rtl/string.hxx | 12 | ||||
-rw-r--r-- | include/rtl/stringconcat.hxx | 42 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 12 |
3 files changed, 66 insertions, 0 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index 1f3120e7b4e5..cebaa114517d 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -2146,6 +2146,17 @@ public: #endif }; +#if defined LIBO_INTERNAL_ONLY +inline bool operator ==(OString const & lhs, OStringConcatenation const & rhs) +{ return lhs == std::string_view(rhs); } +inline bool operator !=(OString const & lhs, OStringConcatenation const & rhs) +{ return lhs != std::string_view(rhs); } +inline bool operator ==(OStringConcatenation const & lhs, OString const & rhs) +{ return std::string_view(lhs) == rhs; } +inline bool operator !=(OStringConcatenation const & lhs, OString const & rhs) +{ return std::string_view(lhs) != rhs; } +#endif + /* ======================================================================= */ #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" @@ -2249,6 +2260,7 @@ typedef rtlunittest::OString OString; #if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST using ::rtl::OString; using ::rtl::OStringChar; +using ::rtl::OStringConcatenation; using ::rtl::OStringHash; using ::rtl::OStringLiteral; #endif diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx index 554fdd3f4403..51605d0731e9 100644 --- a/include/rtl/stringconcat.hxx +++ b/include/rtl/stringconcat.hxx @@ -16,7 +16,9 @@ #include "rtl/string.h" #include "rtl/ustring.h" +#include <cassert> #include <cstddef> +#include <memory> #include <string> #include <string_view> #include <type_traits> @@ -353,6 +355,46 @@ int operator+( const StringConcatInvalid&, const T& ) } #endif +// Lightweight alternative to OString when a (temporary) object is needed to hold an OStringConcat +// result that can then be used as a std::string_view: +class OStringConcatenation { +public: + template<typename T1, typename T2> + explicit OStringConcatenation(OStringConcat<T1, T2> const & c): + length_(c.length()), + buffer_(new char[length_]) + { + auto const end = c.addData(buffer_.get()); + assert(end == buffer_.get() + length_); (void)end; + } + + operator std::string_view() const { return {buffer_.get(), length_}; } + +private: + std::size_t length_; + std::unique_ptr<char[]> buffer_; +}; + +// Lightweight alternative to OUString when a (temporary) object is needed to hold an +// OUStringConcat result that can then be used as a std::u16string_view: +class OUStringConcatenation { +public: + template<typename T1, typename T2> + explicit OUStringConcatenation(OUStringConcat<T1, T2> const & c): + length_(c.length()), + buffer_(new char16_t[length_]) + { + auto const end = c.addData(buffer_.get()); + assert(end == buffer_.get() + length_); (void)end; + } + + operator std::u16string_view() const { return {buffer_.get(), length_}; } + +private: + std::size_t length_; + std::unique_ptr<char16_t[]> buffer_; +}; + /** @internal diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index 96bb504f77a8..5fbf00d64a6d 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -3393,6 +3393,17 @@ void operator !=(OUString const &, std::nullptr_t) = delete; void operator !=(std::nullptr_t, OUString const &) = delete; #endif +#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST +inline bool operator ==(OUString const & lhs, OUStringConcatenation const & rhs) +{ return lhs == std::u16string_view(rhs); } +inline bool operator !=(OUString const & lhs, OUStringConcatenation const & rhs) +{ return lhs != std::u16string_view(rhs); } +inline bool operator ==(OUStringConcatenation const & lhs, OUString const & rhs) +{ return std::u16string_view(lhs) == rhs; } +inline bool operator !=(OUStringConcatenation const & lhs, OUString const & rhs) +{ return std::u16string_view(lhs) != rhs; } +#endif + #if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" /// @cond INTERNAL @@ -3560,6 +3571,7 @@ using ::rtl::OStringToOUString; using ::rtl::OUStringToOString; using ::rtl::OUStringLiteral; using ::rtl::OUStringChar; +using ::rtl::OUStringConcatenation; #endif /// @cond INTERNAL |