mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
Avoid creating new String object when comparing
This commit is contained in:
parent
0792eedd12
commit
6e3639de9e
@ -330,9 +330,10 @@ String &String::append(const String &s)
|
||||
|
||||
String String::upper() const
|
||||
{
|
||||
String s;
|
||||
static const int shift = 'A' - 'a';
|
||||
|
||||
static int shift = 'A' - 'a';
|
||||
String s;
|
||||
s.d->data.reserve(d->data.size());
|
||||
|
||||
for(wstring::const_iterator it = d->data.begin(); it != d->data.end(); ++it) {
|
||||
if(*it >= 'a' && *it <= 'z')
|
||||
@ -537,7 +538,24 @@ const TagLib::wchar &String::operator[](size_t 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 char *s) const
|
||||
{
|
||||
for(wstring::const_iterator it = d->data.begin(); it != d->data.end(); it++) {
|
||||
if(*it != static_cast<uchar>(*s))
|
||||
return false;
|
||||
|
||||
s++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool String::operator==(const wchar_t *s) const
|
||||
{
|
||||
return (d->data == s);
|
||||
}
|
||||
|
||||
bool String::operator!=(const String &s) const
|
||||
@ -700,7 +718,6 @@ void String::detach()
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void String::copyFromLatin1(const char *s, size_t length)
|
||||
{
|
||||
d->data.resize(length);
|
||||
|
@ -342,11 +342,23 @@ namespace TagLib {
|
||||
const wchar &operator[](size_t i) const;
|
||||
|
||||
/*!
|
||||
* Compares each character of the String with each character of \a s and
|
||||
* Compares each character of the String with each character in \a s and
|
||||
* returns true if the strings match.
|
||||
*/
|
||||
bool operator==(const String &s) const;
|
||||
|
||||
/*!
|
||||
* Compares each character of the String with each character in \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 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.
|
||||
|
@ -116,7 +116,7 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(a, String(d, String::UTF16));
|
||||
}
|
||||
|
||||
// this test is expected to print "TagLib: String::prepare() -
|
||||
// this test is expected to print "TagLib: String::copyFromUTF16() -
|
||||
// Invalid UTF16 string." on the console 3 times
|
||||
void testUTF16DecodeInvalidBOM()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user