Fix TagValue::operator== if 0 byte contained
This commit is contained in:
parent
ff1eaadc88
commit
1d098c1f50
22
tagvalue.cpp
22
tagvalue.cpp
|
@ -117,11 +117,19 @@ bool TagValue::operator==(const TagValue &other) const
|
|||
if (m_type == other.m_type) {
|
||||
switch (m_type) {
|
||||
case TagDataType::Text:
|
||||
if (m_size != other.m_size && m_encoding != other.m_encoding) {
|
||||
if (m_size != other.m_size || m_encoding != other.m_encoding) {
|
||||
// don't consider differently encoded text values equal
|
||||
return false;
|
||||
}
|
||||
return strncmp(m_ptr.get(), other.m_ptr.get(), m_size) == 0;
|
||||
if (!m_size) {
|
||||
return true;
|
||||
}
|
||||
for (auto i1 = m_ptr.get(), i2 = other.m_ptr.get(), end = m_ptr.get() + m_size; i1 != end; ++i1, ++i2) {
|
||||
if (*i1 != *i2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
case TagDataType::PositionInSet:
|
||||
return toPositionInSet() == other.toPositionInSet();
|
||||
case TagDataType::Integer:
|
||||
|
@ -138,7 +146,15 @@ bool TagValue::operator==(const TagValue &other) const
|
|||
if (m_size != other.m_size) {
|
||||
return false;
|
||||
}
|
||||
return strncmp(m_ptr.get(), other.m_ptr.get(), m_size) == 0;
|
||||
if (!m_size) {
|
||||
return true;
|
||||
}
|
||||
for (auto i1 = m_ptr.get(), i2 = other.m_ptr.get(), end = m_ptr.get() + m_size; i1 != end; ++i1, ++i2) {
|
||||
if (*i1 != *i2) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -195,6 +195,14 @@ void TagValueTests::testEqualityOperator()
|
|||
CPPUNIT_ASSERT_MESSAGE("equality requires identical types or identical string representation"s, TagValue(0) != TagValue::empty());
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("types might differ"s, TagValue(15), TagValue(15));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("types might differ"s, TagValue("15", 2, TagTextEncoding::Latin1), TagValue(15));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("comparision of equal UTF-16 strings"s, TagValue("\x31\0\x32\0", 4, TagTextEncoding::Utf16LittleEndian),
|
||||
TagValue("\x31\0\x32\0", 4, TagTextEncoding::Utf16LittleEndian));
|
||||
CPPUNIT_ASSERT_MESSAGE("comparision of different UTF-16 strings"s,
|
||||
TagValue("\x31\0\x33\0", 4, TagTextEncoding::Utf16LittleEndian) != TagValue("\x31\0\x32\0", 4, TagTextEncoding::Utf16LittleEndian));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
||||
"comparision of equal binary data"s, TagValue("\x31\0\x32\0", 4, TagDataType::Binary), TagValue("\x31\0\x32\0", 4, TagDataType::Binary));
|
||||
CPPUNIT_ASSERT_MESSAGE("comparision of different binary data"s,
|
||||
TagValue("\x31\0\x33\0", 4, TagDataType::Binary) != TagValue("\x31\0\x32\0", 4, TagDataType::Binary));
|
||||
CPPUNIT_ASSERT_MESSAGE("encoding must be equal if relevant for types"s,
|
||||
TagValue("\0\x31\0\x35", 4, TagTextEncoding::Utf16BigEndian) != TagValue("15", 2, TagTextEncoding::Latin1));
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
||||
|
|
Loading…
Reference in New Issue