Improve coding style
This commit is contained in:
parent
706c410edb
commit
ca0b8e4d8c
|
@ -193,8 +193,7 @@ void Id3v2Frame::parse(BinaryReader &reader, uint32 version, uint32 maximalSize,
|
|||
diag.emplace_back(DiagLevel::Critical, "The decompressed size is smaller than the compressed size.", context);
|
||||
throw InvalidDataException();
|
||||
}
|
||||
auto bufferCompressed = make_unique<char[]>(m_dataSize);
|
||||
;
|
||||
const auto bufferCompressed = make_unique<char[]>(m_dataSize);
|
||||
reader.read(bufferCompressed.get(), m_dataSize);
|
||||
buffer = make_unique<char[]>(decompressedSize);
|
||||
switch (
|
||||
|
@ -228,13 +227,11 @@ void Id3v2Frame::parse(BinaryReader &reader, uint32 version, uint32 maximalSize,
|
|||
|| (version < 3 && id() == Id3v2FrameIds::sTrackPosition)) {
|
||||
// the track number or the disk number frame
|
||||
try {
|
||||
PositionInSet position;
|
||||
if (characterSize(dataEncoding) > 1) {
|
||||
position = PositionInSet(parseWideString(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag));
|
||||
value().assignPosition(PositionInSet(parseWideString(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag)));
|
||||
} else {
|
||||
position = PositionInSet(parseString(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag));
|
||||
value().assignPosition(PositionInSet(parseString(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag)));
|
||||
}
|
||||
value().assignPosition(position);
|
||||
} catch (const ConversionException &) {
|
||||
diag.emplace_back(DiagLevel::Warning, "The value of track/disk position frame is not numeric and will be ignored.", context);
|
||||
}
|
||||
|
@ -261,10 +258,10 @@ void Id3v2Frame::parse(BinaryReader &reader, uint32 version, uint32 maximalSize,
|
|||
// genre/content type
|
||||
int genreIndex;
|
||||
if (characterSize(dataEncoding) > 1) {
|
||||
auto genreDenotation = parseWideString(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag);
|
||||
const auto genreDenotation = parseWideString(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag);
|
||||
genreIndex = parseGenreIndex(genreDenotation);
|
||||
} else {
|
||||
auto genreDenotation = parseString(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag);
|
||||
const auto genreDenotation = parseString(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag);
|
||||
genreIndex = parseGenreIndex(genreDenotation);
|
||||
}
|
||||
if (genreIndex != -1) {
|
||||
|
@ -273,12 +270,12 @@ void Id3v2Frame::parse(BinaryReader &reader, uint32 version, uint32 maximalSize,
|
|||
} else {
|
||||
// genre is specified as string
|
||||
// string might be null terminated
|
||||
auto substr = parseSubstring(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag);
|
||||
const auto substr = parseSubstring(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag);
|
||||
value().assignData(get<0>(substr), get<1>(substr), TagDataType::Text, dataEncoding);
|
||||
}
|
||||
} else {
|
||||
// any other text frame
|
||||
auto substr = parseSubstring(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag);
|
||||
const auto substr = parseSubstring(buffer.get() + 1, m_dataSize - 1, dataEncoding, false, diag);
|
||||
value().assignData(get<0>(substr), get<1>(substr), TagDataType::Text, dataEncoding);
|
||||
}
|
||||
|
||||
|
|
77
tagvalue.cpp
77
tagvalue.cpp
|
@ -147,7 +147,9 @@ void TagValue::clearMetadata()
|
|||
*/
|
||||
int32 TagValue::toInteger() const
|
||||
{
|
||||
if (!isEmpty()) {
|
||||
if (isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
switch (m_type) {
|
||||
case TagDataType::Text:
|
||||
switch (m_encoding) {
|
||||
|
@ -166,15 +168,12 @@ int32 TagValue::toInteger() const
|
|||
case TagDataType::StandardGenreIndex:
|
||||
if (m_size == sizeof(int32)) {
|
||||
return *reinterpret_cast<int32 *>(m_ptr.get());
|
||||
} else {
|
||||
throw ConversionException("Can not convert assigned data to integer because the data size is not appropriate.");
|
||||
}
|
||||
throw ConversionException("Can not convert assigned data to integer because the data size is not appropriate.");
|
||||
default:
|
||||
throw ConversionException("Can not convert binary data/picture/time span/date time to integer.");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the value of the current TagValue object to its equivalent
|
||||
|
@ -183,7 +182,9 @@ int32 TagValue::toInteger() const
|
|||
*/
|
||||
int TagValue::toStandardGenreIndex() const
|
||||
{
|
||||
if (!isEmpty()) {
|
||||
if (isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int index = 0;
|
||||
switch (m_type) {
|
||||
case TagDataType::Text: {
|
||||
|
@ -202,23 +203,19 @@ int TagValue::toStandardGenreIndex() const
|
|||
}
|
||||
case TagDataType::StandardGenreIndex:
|
||||
case TagDataType::Integer:
|
||||
if (m_size == sizeof(int32)) {
|
||||
index = static_cast<int>(*reinterpret_cast<int32 *>(m_ptr.get()));
|
||||
} else {
|
||||
if (m_size != sizeof(int32)) {
|
||||
throw ConversionException("The assigned data is of unappropriate size.");
|
||||
}
|
||||
index = static_cast<int>(*reinterpret_cast<int32 *>(m_ptr.get()));
|
||||
break;
|
||||
default:
|
||||
throw ConversionException("It is not possible to convert assigned data to a number because of its incompatible type.");
|
||||
}
|
||||
if (Id3Genres::isIndexSupported(index)) {
|
||||
return index;
|
||||
} else {
|
||||
}
|
||||
throw ConversionException("The assigned number is not a valid standard genre index.");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the value of the current TagValue object to its equivalent
|
||||
|
@ -227,7 +224,9 @@ int TagValue::toStandardGenreIndex() const
|
|||
*/
|
||||
PositionInSet TagValue::toPositionInSet() const
|
||||
{
|
||||
if (!isEmpty()) {
|
||||
if (isEmpty()) {
|
||||
return PositionInSet();
|
||||
}
|
||||
switch (m_type) {
|
||||
case TagDataType::Text:
|
||||
switch (m_encoding) {
|
||||
|
@ -255,8 +254,6 @@ PositionInSet TagValue::toPositionInSet() const
|
|||
throw ConversionException("Can not convert binary data/genre index/picture to \"position in set\".");
|
||||
}
|
||||
}
|
||||
return PositionInSet();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the value of the current TagValue object to its equivalent
|
||||
|
@ -265,7 +262,9 @@ PositionInSet TagValue::toPositionInSet() const
|
|||
*/
|
||||
TimeSpan TagValue::toTimeSpan() const
|
||||
{
|
||||
if (!isEmpty()) {
|
||||
if (isEmpty()) {
|
||||
return TimeSpan();
|
||||
}
|
||||
switch (m_type) {
|
||||
case TagDataType::Text:
|
||||
return TimeSpan::fromString(string(m_ptr.get(), m_size));
|
||||
|
@ -283,8 +282,6 @@ TimeSpan TagValue::toTimeSpan() const
|
|||
throw ConversionException("Can not convert binary data/genre index/position in set/picture to time span.");
|
||||
}
|
||||
}
|
||||
return TimeSpan();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the value of the current TagValue object to its equivalent
|
||||
|
@ -293,7 +290,9 @@ TimeSpan TagValue::toTimeSpan() const
|
|||
*/
|
||||
DateTime TagValue::toDateTime() const
|
||||
{
|
||||
if (!isEmpty()) {
|
||||
if (isEmpty()) {
|
||||
return DateTime();
|
||||
}
|
||||
switch (m_type) {
|
||||
case TagDataType::Text:
|
||||
return DateTime::fromString(string(m_ptr.get(), m_size));
|
||||
|
@ -310,8 +309,6 @@ DateTime TagValue::toDateTime() const
|
|||
throw ConversionException("Can not convert binary data/genre index/position in set/picture to date time.");
|
||||
}
|
||||
}
|
||||
return DateTime();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the encoding parameter (name of the character set and bytes per character) for the specified \a tagTextEncoding.
|
||||
|
@ -343,7 +340,9 @@ pair<const char *, float> encodingParameter(TagTextEncoding tagTextEncoding)
|
|||
*/
|
||||
void TagValue::convertDataEncoding(TagTextEncoding encoding)
|
||||
{
|
||||
if (m_encoding != encoding) {
|
||||
if (m_encoding == encoding) {
|
||||
return;
|
||||
}
|
||||
if (type() == TagDataType::Text) {
|
||||
StringData encodedData;
|
||||
switch (encoding) {
|
||||
|
@ -376,7 +375,6 @@ void TagValue::convertDataEncoding(TagTextEncoding encoding)
|
|||
}
|
||||
m_encoding = encoding;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Ensures the encoding of the currently assigned text value is supported by the specified \a tag.
|
||||
|
@ -400,7 +398,11 @@ void TagValue::convertDataEncodingForTag(const Tag *tag)
|
|||
*/
|
||||
void TagValue::toString(string &result, TagTextEncoding encoding) const
|
||||
{
|
||||
if (!isEmpty()) {
|
||||
if (isEmpty()) {
|
||||
result.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (m_type) {
|
||||
case TagDataType::Text:
|
||||
if (encoding == TagTextEncoding::Unspecified || dataEncoding() == TagTextEncoding::Unspecified || encoding == dataEncoding()) {
|
||||
|
@ -427,8 +429,8 @@ void TagValue::toString(string &result, TagTextEncoding encoding) const
|
|||
// otherwise, determine input and output parameter to use general covertString method
|
||||
const auto inputParameter = encodingParameter(dataEncoding());
|
||||
const auto outputParameter = encodingParameter(encoding);
|
||||
encodedData = convertString(
|
||||
inputParameter.first, outputParameter.first, m_ptr.get(), m_size, outputParameter.second / inputParameter.second);
|
||||
encodedData
|
||||
= convertString(inputParameter.first, outputParameter.first, m_ptr.get(), m_size, outputParameter.second / inputParameter.second);
|
||||
}
|
||||
}
|
||||
result.assign(encodedData.first.get(), encodedData.second);
|
||||
|
@ -461,9 +463,6 @@ void TagValue::toString(string &result, TagTextEncoding encoding) const
|
|||
: convertUtf8ToUtf16BE(result.data(), result.size());
|
||||
result.assign(encodedData.first.get(), encodedData.second);
|
||||
}
|
||||
} else {
|
||||
result.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -475,7 +474,11 @@ void TagValue::toString(string &result, TagTextEncoding encoding) const
|
|||
*/
|
||||
void TagValue::toWString(std::u16string &result, TagTextEncoding encoding) const
|
||||
{
|
||||
if (!isEmpty()) {
|
||||
if (isEmpty()) {
|
||||
result.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
string regularStrRes;
|
||||
switch (m_type) {
|
||||
case TagDataType::Text:
|
||||
|
@ -503,8 +506,8 @@ void TagValue::toWString(std::u16string &result, TagTextEncoding encoding) const
|
|||
// otherwise, determine input and output parameter to use general covertString method
|
||||
const auto inputParameter = encodingParameter(dataEncoding());
|
||||
const auto outputParameter = encodingParameter(encoding);
|
||||
encodedData = convertString(
|
||||
inputParameter.first, outputParameter.first, m_ptr.get(), m_size, outputParameter.second / inputParameter.second);
|
||||
encodedData
|
||||
= convertString(inputParameter.first, outputParameter.first, m_ptr.get(), m_size, outputParameter.second / inputParameter.second);
|
||||
}
|
||||
}
|
||||
result.assign(reinterpret_cast<const char16_t *>(encodedData.first.get()), encodedData.second / sizeof(char16_t));
|
||||
|
@ -534,9 +537,6 @@ void TagValue::toWString(std::u16string &result, TagTextEncoding encoding) const
|
|||
: convertUtf8ToUtf16BE(regularStrRes.data(), result.size());
|
||||
result.assign(reinterpret_cast<const char16_t *>(encodedData.first.get()), encodedData.second / sizeof(const char16_t));
|
||||
}
|
||||
} else {
|
||||
result.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -564,7 +564,9 @@ void TagValue::assignText(const char *text, std::size_t textSize, TagTextEncodin
|
|||
if (convertTo == TagTextEncoding::Unspecified || textEncoding == convertTo) {
|
||||
m_ptr = make_unique<char[]>(m_size = textSize);
|
||||
copy(text, text + textSize, m_ptr.get());
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
StringData encodedData;
|
||||
switch (textEncoding) {
|
||||
case TagTextEncoding::Utf8:
|
||||
|
@ -593,7 +595,6 @@ void TagValue::assignText(const char *text, std::size_t textSize, TagTextEncodin
|
|||
m_ptr = make_unique<char[]>(m_size = encodedData.second);
|
||||
copy(encodedData.first.get(), encodedData.first.get() + encodedData.second, m_ptr.get());
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Assigns the given integer \a value.
|
||||
|
|
Loading…
Reference in New Issue