diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-10-11 10:23:28 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-10-11 12:46:01 +0200 |
commit | 3d236177be255b2027a997bfc12fe0833ca9a2f7 (patch) | |
tree | d67582e355bccb43cf133c1857f5dd6136be2f35 /include | |
parent | 6c65c62c26a8aa4d04466545f8f04ec86b797012 (diff) |
Deduplicate O(U)StringConcatenation
And use an overloaded helper function with a better (?) unified name
to show that the result is not an O(U)String.
Change-Id: I8956338b05d02bf46a6185828130ea8ef145d46b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141203
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/rtl/string.hxx | 10 | ||||
-rw-r--r-- | include/rtl/stringconcat.hxx | 42 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 10 |
3 files changed, 26 insertions, 36 deletions
diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index 9ae30586e549..0e0c3c75d5a9 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -2169,13 +2169,13 @@ public: }; #if defined LIBO_INTERNAL_ONLY -inline bool operator ==(OString const & lhs, OStringConcatenation const & rhs) +inline bool operator ==(OString const & lhs, StringConcatenation<char> const & rhs) { return lhs == std::string_view(rhs); } -inline bool operator !=(OString const & lhs, OStringConcatenation const & rhs) +inline bool operator !=(OString const & lhs, StringConcatenation<char> const & rhs) { return lhs != std::string_view(rhs); } -inline bool operator ==(OStringConcatenation const & lhs, OString const & rhs) +inline bool operator ==(StringConcatenation<char> const & lhs, OString const & rhs) { return std::string_view(lhs) == rhs; } -inline bool operator !=(OStringConcatenation const & lhs, OString const & rhs) +inline bool operator !=(StringConcatenation<char> const & lhs, OString const & rhs) { return std::string_view(lhs) != rhs; } #endif @@ -2282,7 +2282,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::Concat2View; using ::rtl::OStringHash; using ::rtl::OStringLiteral; #endif diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx index 51605d0731e9..c2862c5c49ad 100644 --- a/include/rtl/stringconcat.hxx +++ b/include/rtl/stringconcat.hxx @@ -355,45 +355,35 @@ 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 { +// Lightweight alternative to O(U)String when a (temporary) object is needed to hold +// an O(U)StringConcat result that can then be used as a std::(u16)string_view: +template <typename C> class StringConcatenation { public: - template<typename T1, typename T2> - explicit OStringConcatenation(OStringConcat<T1, T2> const & c): + template <class Concat> + explicit StringConcatenation(Concat const& c): length_(c.length()), - buffer_(new char[length_]) + buffer_(new C[length_]) { auto const end = c.addData(buffer_.get()); assert(end == buffer_.get() + length_); (void)end; } - operator std::string_view() const { return {buffer_.get(), length_}; } + operator std::basic_string_view<C>() const { return {buffer_.get(), length_}; } private: std::size_t length_; - std::unique_ptr<char[]> buffer_; + std::unique_ptr<C[]> 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_}; } +template <typename T1, typename T2> auto Concat2View(OStringConcat<T1, T2> const& c) +{ + return StringConcatenation<char>(c); +} -private: - std::size_t length_; - std::unique_ptr<char16_t[]> buffer_; -}; +template <typename T1, typename T2> auto Concat2View(OUStringConcat<T1, T2> const& c) +{ + return StringConcatenation<char16_t>(c); +} /** @internal diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index c9067905a0a0..cddba5dfadd5 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -3347,13 +3347,13 @@ 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) +inline bool operator ==(OUString const & lhs, StringConcatenation<char16_t> const & rhs) { return lhs == std::u16string_view(rhs); } -inline bool operator !=(OUString const & lhs, OUStringConcatenation const & rhs) +inline bool operator !=(OUString const & lhs, StringConcatenation<char16_t> const & rhs) { return lhs != std::u16string_view(rhs); } -inline bool operator ==(OUStringConcatenation const & lhs, OUString const & rhs) +inline bool operator ==(StringConcatenation<char16_t> const & lhs, OUString const & rhs) { return std::u16string_view(lhs) == rhs; } -inline bool operator !=(OUStringConcatenation const & lhs, OUString const & rhs) +inline bool operator !=(StringConcatenation<char16_t> const & lhs, OUString const & rhs) { return std::u16string_view(lhs) != rhs; } #endif @@ -3525,7 +3525,7 @@ using ::rtl::OStringToOUString; using ::rtl::OUStringToOString; using ::rtl::OUStringLiteral; using ::rtl::OUStringChar; -using ::rtl::OUStringConcatenation; +using ::rtl::Concat2View; #endif /// @cond INTERNAL |