Improve coding style in TagValue
This commit is contained in:
parent
fd1864c3df
commit
09c1c6a232
34
tagvalue.cpp
34
tagvalue.cpp
|
@ -106,10 +106,13 @@ TagValue &TagValue::operator=(const TagValue &other)
|
||||||
*/
|
*/
|
||||||
bool TagValue::operator==(const TagValue &other) const
|
bool TagValue::operator==(const TagValue &other) const
|
||||||
{
|
{
|
||||||
|
// check whether meta-data is equal
|
||||||
if (m_desc != other.m_desc || (!m_desc.empty() && m_descEncoding != other.m_descEncoding) || m_mimeType != other.m_mimeType
|
if (m_desc != other.m_desc || (!m_desc.empty() && m_descEncoding != other.m_descEncoding) || m_mimeType != other.m_mimeType
|
||||||
|| m_language != other.m_language || m_labeledAsReadonly != other.m_labeledAsReadonly) {
|
|| m_language != other.m_language || m_labeledAsReadonly != other.m_labeledAsReadonly) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check for equality if both types are identical
|
||||||
if (m_type == other.m_type) {
|
if (m_type == other.m_type) {
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case TagDataType::Text:
|
case TagDataType::Text:
|
||||||
|
@ -135,18 +138,15 @@ bool TagValue::operator==(const TagValue &other) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return strncmp(m_ptr.get(), other.m_ptr.get(), m_size) == 0;
|
return strncmp(m_ptr.get(), other.m_ptr.get(), m_size) == 0;
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// different types
|
|
||||||
try {
|
|
||||||
// try to convert both values to string
|
|
||||||
// if the string representations are equal, both values can also be considered equal
|
|
||||||
return toString() == other.toString(m_encoding);
|
|
||||||
} catch (const ConversionException &) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for equality if types are different by comparing the string representation
|
||||||
|
try {
|
||||||
|
return toString() == other.toString(m_encoding);
|
||||||
|
} catch (const ConversionException &) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +216,6 @@ int TagValue::toStandardGenreIndex() const
|
||||||
int index = 0;
|
int index = 0;
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case TagDataType::Text: {
|
case TagDataType::Text: {
|
||||||
const string s(toString());
|
|
||||||
try {
|
try {
|
||||||
index = toInteger();
|
index = toInteger();
|
||||||
} catch (const ConversionException &) {
|
} catch (const ConversionException &) {
|
||||||
|
@ -239,10 +238,10 @@ int TagValue::toStandardGenreIndex() const
|
||||||
default:
|
default:
|
||||||
throw ConversionException(argsToString("Can not convert ", tagDataTypeString(m_type), " to genre index."));
|
throw ConversionException(argsToString("Can not convert ", tagDataTypeString(m_type), " to genre index."));
|
||||||
}
|
}
|
||||||
if (Id3Genres::isIndexSupported(index)) {
|
if (!Id3Genres::isIndexSupported(index)) {
|
||||||
return index;
|
throw ConversionException("The assigned number is not a valid standard genre index.");
|
||||||
}
|
}
|
||||||
throw ConversionException("The assigned number is not a valid standard genre index.");
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -548,12 +547,11 @@ void TagValue::toWString(std::u16string &result, TagTextEncoding encoding) const
|
||||||
regularStrRes = toPositionInSet().toString();
|
regularStrRes = toPositionInSet().toString();
|
||||||
break;
|
break;
|
||||||
case TagDataType::StandardGenreIndex:
|
case TagDataType::StandardGenreIndex:
|
||||||
if (const char *genreName = Id3Genres::stringFromIndex(toInteger())) {
|
if (const char *const genreName = Id3Genres::stringFromIndex(toInteger())) {
|
||||||
regularStrRes.assign(genreName);
|
regularStrRes.assign(genreName);
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
throw ConversionException("No string representation for the assigned standard genre index available.");
|
|
||||||
}
|
}
|
||||||
|
throw ConversionException("No string representation for the assigned standard genre index available.");
|
||||||
case TagDataType::TimeSpan:
|
case TagDataType::TimeSpan:
|
||||||
regularStrRes = toTimeSpan().toString();
|
regularStrRes = toTimeSpan().toString();
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue