5 #include "../exceptions.h"
7 #include <c++utilities/io/binarywriter.h>
24 MatroskaTagField::MatroskaTagField()
31 MatroskaTagField::MatroskaTagField(
const string &
id,
const TagValue &value)
48 string context(
"parsing Matroska tag field");
49 simpleTagElement.
parse(diag);
50 bool tagDefaultFound =
false, tagLanguageFound =
false, tagLanguageIETFFound =
false;
55 diag.emplace_back(DiagLevel::Critical,
"Unable to parse children of \"SimpleTag\"-element.", context);
58 switch (child->id()) {
61 setId(child->readString());
62 context =
"parsing Matroska tag field " +
id();
64 diag.emplace_back(DiagLevel::Warning,
65 "\"SimpleTag\"-element contains multiple \"TagName\"-elements. Surplus TagName elements will be ignored.", context);
70 if (
value().isEmpty()) {
71 unique_ptr<char[]> buffer = make_unique<char[]>(child->dataSize());
72 child->stream().seekg(
static_cast<streamoff
>(child->dataOffset()));
73 child->stream().read(buffer.get(),
static_cast<streamoff
>(child->dataSize()));
74 switch (child->id()) {
83 diag.emplace_back(DiagLevel::Warning,
84 "\"SimpleTag\"-element contains multiple \"TagString\"/\"TagBinary\"-elements. Surplus \"TagName\"/\"TagBinary\"-elements will "
90 if (!tagLanguageFound && !tagLanguageIETFFound) {
91 tagLanguageFound =
true;
92 string lng = child->readString();
96 }
else if (tagLanguageFound) {
97 diag.emplace_back(DiagLevel::Warning,
98 "\"SimpleTag\"-element contains multiple \"TagLanguage\"-elements. Surplus \"TagLanguage\"-elements will be ignored.", context);
102 if (!tagLanguageIETFFound) {
103 tagLanguageIETFFound =
true;
104 diag.emplace_back(DiagLevel::Warning,
105 "\"SimpleTag\"-element contains a \"TagLanguageIETF\"-element. That's not supported at this point. The element will be dropped "
106 "when applying changes.",
109 diag.emplace_back(DiagLevel::Warning,
110 "\"SimpleTag\"-element contains multiple \"TagLanguageIETF\"-elements. Surplus \"TagLanguageIETF\"-elements will be ignored.",
115 if (!tagDefaultFound) {
117 tagDefaultFound =
true;
119 diag.emplace_back(DiagLevel::Warning,
120 "\"SimpleTag\"-element contains multiple \"TagDefault\" elements. Surplus \"TagDefault\"-elements will be ignored.", context);
124 if (parseNestedFields) {
128 diag.emplace_back(DiagLevel::Warning,
129 "Nested fields are currently not supported. Nested tags can not be displayed and will be discarded when rewriting the file.",
137 diag.emplace_back(DiagLevel::Warning,
139 "\"SimpleTag\"-element contains unknown element ", child->idToString(),
" at ", child->startOffset(),
". It will be ignored."),
157 static const string context(
"making Matroska \"SimpleTag\" element.");
160 diag.emplace_back(DiagLevel::Critical,
"Can not make \"SimpleTag\" element with empty \"TagName\".", context);
165 }
catch (
const ConversionException &) {
166 diag.emplace_back(DiagLevel::Critical,
"The assigned tag value can not be converted to be written appropriately.", context);
198 m_stringValue = m_field.value().toString();
199 }
catch (
const ConversionException &) {
200 diag.emplace_back(DiagLevel::Warning,
201 "The assigned tag value can not be converted to a string and is treated as binary value (which is likely not what you want since "
202 "official Matroska specifiecation doesn't list any binary fields).",
203 "making Matroska \"SimpleTag\" element.");
206 size_t languageSize = m_field.value().language().size();
213 + m_field.id().size()
224 m_nestedMaker.emplace_back(nestedField.prepareMaking(diag));
225 m_simpleTagSize += m_nestedMaker.back().m_totalSize;
239 BinaryWriter writer(&stream);
244 stream.write(buff, sizeDenotationLen);
248 stream.write(buff, sizeDenotationLen);
249 stream.write(m_field.
id().c_str(), m_field.
id().size());
253 stream.put(
static_cast<ostream::char_type
>(0x80 | 3));
254 stream.write(
"und", 3);
257 stream.write(buff, sizeDenotationLen);
262 stream.put(
static_cast<ostream::char_type
>(0x80 | 1));
268 stream.write(buff, sizeDenotationLen);
273 stream.write(buff, sizeDenotationLen);
274 stream.write(m_stringValue.data(), m_stringValue.size());
277 for (
const auto &maker : m_nestedMaker) {