diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/rtl/ustring.hxx | 86 | ||||
-rw-r--r-- | include/sal/types.h | 10 |
2 files changed, 95 insertions, 1 deletions
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index 78a6b60f1c17..ffc5d6fe0bd2 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -67,7 +67,8 @@ This class is not part of public API and is meant to be used only in LibreOffice struct SAL_WARN_UNUSED OUStringLiteral { template< int N > - explicit OUStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) { assert( strlen( str ) == N - 1 ); } + explicit SAL_CONSTEXPR OUStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str ) + { /* only C++14 constexpr: assert( strlen( str ) == N - 1 ); */ } int size; const char* data; }; @@ -1304,6 +1305,89 @@ public: return !string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ); } +#if defined LIBO_INTERNAL_ONLY + /// @cond INTERNAL + + /* Comparison between OUString and OUStringLiteral. + + @since LibreOffice 4.5 + */ + + friend bool operator ==(OUString const & lhs, OUStringLiteral const & rhs) { + return lhs.equalsAsciiL(rhs.data, rhs.size); + } + + friend bool operator !=(OUString const & lhs, OUStringLiteral const & rhs) { + return !lhs.equalsAsciiL(rhs.data, rhs.size); + } + + friend bool operator <(OUString const & lhs, OUStringLiteral const & rhs) { + return + (rtl_ustr_ascii_compare_WithLength( + lhs.pData->buffer, lhs.pData->length, rhs.data)) + < 0; + } + + friend bool operator <=(OUString const & lhs, OUStringLiteral const & rhs) { + return + (rtl_ustr_ascii_compare_WithLength( + lhs.pData->buffer, lhs.pData->length, rhs.data)) + <= 0; + } + + friend bool operator >(OUString const & lhs, OUStringLiteral const & rhs) { + return + (rtl_ustr_ascii_compare_WithLength( + lhs.pData->buffer, lhs.pData->length, rhs.data)) + > 0; + } + + friend bool operator >=(OUString const & lhs, OUStringLiteral const & rhs) { + return + (rtl_ustr_ascii_compare_WithLength( + lhs.pData->buffer, lhs.pData->length, rhs.data)) + >= 0; + } + + friend bool operator ==(OUStringLiteral const & lhs, OUString const & rhs) { + return rhs.equalsAsciiL(lhs.data, lhs.size); + } + + friend bool operator !=(OUStringLiteral const & lhs, OUString const & rhs) { + return !rhs.equalsAsciiL(lhs.data, lhs.size); + } + + friend bool operator <(OUStringLiteral const & lhs, OUString const & rhs) { + return + (rtl_ustr_ascii_compare_WithLength( + rhs.pData->buffer, rhs.pData->length, lhs.data)) + >= 0; + } + + friend bool operator <=(OUStringLiteral const & lhs, OUString const & rhs) { + return + (rtl_ustr_ascii_compare_WithLength( + rhs.pData->buffer, rhs.pData->length, lhs.data)) + > 0; + } + + friend bool operator >(OUStringLiteral const & lhs, OUString const & rhs) { + return + (rtl_ustr_ascii_compare_WithLength( + rhs.pData->buffer, rhs.pData->length, lhs.data)) + <= 0; + } + + friend bool operator >=(OUStringLiteral const & lhs, OUString const & rhs) { + return + (rtl_ustr_ascii_compare_WithLength( + rhs.pData->buffer, rhs.pData->length, lhs.data)) + < 0; + } + + /// @endcond +#endif + /** Returns a hashcode for this string. diff --git a/include/sal/types.h b/include/sal/types.h index 3d75f67ff920..8810695b2819 100644 --- a/include/sal/types.h +++ b/include/sal/types.h @@ -427,6 +427,16 @@ namespace css = ::com::sun::star; #define SAL_FINAL #endif +/** C++11 "constexpr" feature. + + @since LibreOffice 4.5 +*/ +#if HAVE_CXX11_CONSTEXPR +#define SAL_CONSTEXPR constexpr +#else +#define SAL_CONSTEXPR +#endif + #endif /* __cplusplus */ #ifdef __cplusplus |