mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-04 13:05:31 +00:00
ICU-22843 UnicodeString::operator!=(string view)
This commit is contained in:
parent
1414e80f6c
commit
6645cc4935
2 changed files with 40 additions and 0 deletions
|
@ -364,6 +364,30 @@ public:
|
|||
*/
|
||||
inline bool operator!= (const UnicodeString& text) const;
|
||||
|
||||
#ifndef U_HIDE_DRAFT_API
|
||||
/**
|
||||
* Inequality operator. Performs only bitwise comparison with `text`
|
||||
* which is, or which is implicitly convertible to,
|
||||
* a std::u16string_view or (if U_SIZEOF_WCHAR_T==2) std::wstring_view.
|
||||
*
|
||||
* For performance, you can use std::u16string_view literals with compile-time
|
||||
* length determination:
|
||||
* \code
|
||||
* #include <string_view>
|
||||
* using namespace std::string_view_literals;
|
||||
* UnicodeString str = ...;
|
||||
* if (str != u"literal"sv) { ... }
|
||||
* \endcode
|
||||
* @param text The string view to compare to this string.
|
||||
* @return false if `text` contains the same characters as this one, true otherwise.
|
||||
* @draft ICU 76
|
||||
*/
|
||||
template<typename S, typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
|
||||
inline bool operator!=(const S &text) const {
|
||||
return !operator==(text);
|
||||
}
|
||||
#endif // U_HIDE_DRAFT_API
|
||||
|
||||
/**
|
||||
* Greater than operator. Performs only bitwise comparison.
|
||||
* @param text The UnicodeString to compare to this one.
|
||||
|
|
|
@ -2453,6 +2453,14 @@ void UnicodeStringTest::TestU16StringView() {
|
|||
assertFalse("any == string-str16", any == str16);
|
||||
assertTrue("any == string-any", any == u"any"s);
|
||||
|
||||
// operator!=
|
||||
assertTrue("any != pointer-p16", any != p16);
|
||||
assertFalse("any != pointer-any", any != u"any");
|
||||
assertTrue("any != string_view-sv16", any != sv16);
|
||||
assertFalse("any != string_view-any", any != u"any"sv);
|
||||
assertTrue("any != string-str16", any != str16);
|
||||
assertFalse("any != string-any", any != u"any"s);
|
||||
|
||||
// Assignment copies the string contents.
|
||||
UnicodeString x;
|
||||
x = p16;
|
||||
|
@ -2541,6 +2549,14 @@ void UnicodeStringTest::TestWStringView() {
|
|||
assertFalse("any == string-str16", any == str16);
|
||||
assertTrue("any == string-any", any == L"any"s);
|
||||
|
||||
// operator!=
|
||||
assertTrue("any != pointer-p16", any != p16);
|
||||
assertFalse("any != pointer-any", any != L"any");
|
||||
assertTrue("any != string_view-sv16", any != sv16);
|
||||
assertFalse("any != string_view-any", any != L"any"sv);
|
||||
assertTrue("any != string-str16", any != str16);
|
||||
assertFalse("any != string-any", any != L"any"s);
|
||||
|
||||
// Assignment copies the string contents.
|
||||
UnicodeString x;
|
||||
x = p16;
|
||||
|
|
Loading…
Add table
Reference in a new issue