Allow converting the description encoding
This commit is contained in:
parent
7885b99f72
commit
a8e20c5ef4
41
tagvalue.cpp
41
tagvalue.cpp
|
@ -436,6 +436,47 @@ void TagValue::convertDataEncodingForTag(const Tag *tag)
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the assigned description to use the specified \a encoding.
|
||||
*/
|
||||
void TagValue::convertDescriptionEncoding(TagTextEncoding encoding)
|
||||
{
|
||||
if (encoding == m_descEncoding) {
|
||||
return;
|
||||
}
|
||||
if (m_desc.empty()) {
|
||||
m_descEncoding = encoding;
|
||||
return;
|
||||
}
|
||||
StringData encodedData;
|
||||
switch (encoding) {
|
||||
case TagTextEncoding::Utf8:
|
||||
// use pre-defined methods when encoding to UTF-8
|
||||
switch (dataEncoding()) {
|
||||
case TagTextEncoding::Latin1:
|
||||
encodedData = convertLatin1ToUtf8(m_ptr.get(), m_size);
|
||||
break;
|
||||
case TagTextEncoding::Utf16LittleEndian:
|
||||
encodedData = convertUtf16LEToUtf8(m_ptr.get(), m_size);
|
||||
break;
|
||||
case TagTextEncoding::Utf16BigEndian:
|
||||
encodedData = convertUtf16BEToUtf8(m_ptr.get(), m_size);
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
// otherwise, determine input and output parameter to use general covertString method
|
||||
const auto inputParameter = encodingParameter(m_descEncoding);
|
||||
const auto outputParameter = encodingParameter(encoding);
|
||||
encodedData = convertString(
|
||||
inputParameter.first, outputParameter.first, m_desc.data(), m_desc.size(), outputParameter.second / inputParameter.second);
|
||||
}
|
||||
}
|
||||
m_desc.assign(encodedData.first.get(), encodedData.second);
|
||||
m_descEncoding = encoding;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the value of the current TagValue object to its equivalent
|
||||
* std::string representation.
|
||||
|
|
18
tagvalue.h
18
tagvalue.h
|
@ -119,6 +119,7 @@ public:
|
|||
void convertDataEncoding(TagTextEncoding encoding);
|
||||
void convertDataEncodingForTag(const Tag *tag);
|
||||
TagTextEncoding descriptionEncoding() const;
|
||||
void convertDescriptionEncoding(TagTextEncoding encoding);
|
||||
static const TagValue &empty();
|
||||
|
||||
void assignText(const char *text, std::size_t textSize, TagTextEncoding textEncoding = TagTextEncoding::Latin1,
|
||||
|
@ -477,9 +478,12 @@ inline const char *TagValue::dataPointer() const
|
|||
|
||||
/*!
|
||||
* \brief Returns the description.
|
||||
* \remarks The usage of this meta information depends on the tag implementation.
|
||||
* \sa descriptionEncoding()
|
||||
* \sa setDescription()
|
||||
* \remarks The usage of this meta information depends on the tag implementation. It might be ignored
|
||||
* if not supported.
|
||||
* \sa
|
||||
* - descriptionEncoding() for the encoding of the returned string
|
||||
* - convertDescriptionEncoding() to change the encoding of the description
|
||||
* - setDescription() for setting the description
|
||||
*/
|
||||
inline const std::string &TagValue::description() const
|
||||
{
|
||||
|
@ -490,9 +494,11 @@ inline const std::string &TagValue::description() const
|
|||
* \brief Sets the description.
|
||||
* \param value Specifies the description.
|
||||
* \param encoding Specifies the encoding used to provide the description.
|
||||
* \remarks The usage of this meta information depends on the tag implementation.
|
||||
* \sa description()
|
||||
* \sa descriptionEncoding()
|
||||
* \remarks The usage of this meta information depends on the tag implementation. It might be ignored
|
||||
* if not supported.
|
||||
* \sa
|
||||
* - description() and descriptionEncoding()
|
||||
* - convertDescriptionEncoding() to change the description encoding after assignment
|
||||
*/
|
||||
inline void TagValue::setDescription(const std::string &value, TagTextEncoding encoding)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue