Added some operators to compare String to string literals.

This commit is contained in:
Tsuda Kageyu
2014-08-12 22:54:54 +09:00
parent d34c922c75
commit 9bb0eb7ee9
3 changed files with 63 additions and 4 deletions

View File

@ -607,12 +607,39 @@ const TagLib::wchar &String::operator[](int i) const
bool String::operator==(const String &s) const
{
return d == s.d || d->data == s.d->data;
return (d == s.d || d->data == s.d->data);
}
bool String::operator!=(const String &s) const
{
return !operator==(s);
return !(*this == s);
}
bool String::operator==(const char *s) const
{
const wchar_t *p = toCWString();
while(*p != L'\0' || *s != '\0')
{
if(*p++ != static_cast<uchar>(*s++))
return false;
}
return true;
}
bool String::operator!=(const char *s) const
{
return !(*this == s);
}
bool String::operator==(const wchar_t *s) const
{
return (::wcscmp(toCWString(), s) == 0);
}
bool String::operator!=(const wchar_t *s) const
{
return !(*this == s);
}
String &String::operator+=(const String &s)

View File

@ -397,6 +397,30 @@ namespace TagLib {
*/
bool operator!=(const String &s) const;
/*!
* Compares each character of the String with each character of \a s and
* returns true if the strings match.
*/
bool operator==(const char *s) const;
/*!
* Compares each character of the String with each character of \a s and
* returns false if the strings match.
*/
bool operator!=(const char *s) const;
/*!
* Compares each character of the String with each character of \a s and
* returns true if the strings match.
*/
bool operator==(const wchar_t *s) const;
/*!
* Compares each character of the String with each character of \a s and
* returns false if the strings match.
*/
bool operator!=(const wchar_t *s) const;
/*!
* Appends \a s to the end of the String.
*/