Skip to content
Extraits de code Groupes Projets

Add the ASS sub document and the ASS tree

Fusionnées Kubat a demandé de fusionner ass-sub-document vers master
Affichage du commit e63f1cbf
Suivant
Afficher la dernière version
3 fichiers
+ 68
53
Comparer les modifications
  • Côte à côte
  • En ligne
Fichiers
3
+ 35
26
@@ -10,17 +10,19 @@ AssFactory::initFromStorage() noexcept
QTextStream in(&diskStorage);
QString currentSection{};
quint64 lineIndex = 0;
QStringList stylesContent{};
QStringList eventsContent{};
while (!in.atEnd()) {
const QString line = in.readLine().trimmed();
/* Dectect comment */
// Dectect comment
if (line.startsWith(";") || line.isEmpty()) {
lineIndex++;
continue;
}
/* Dectect sections */
// Dectect sections
else if (line.startsWith("[") && line.endsWith("]")) {
currentSection = line.mid(1, line.size() - 2);
qDebug() << "Parsing section" << currentSection;
@@ -30,0+32,0 @@
}
}
/* Other lines */
// Other lines
else if (!currentSection.isEmpty()) {
const int separatorIndex = line.indexOf(": ");
const int baseValueIndex = separatorIndex + 2;
if (separatorIndex < 0) {
// Easy way to see if the line was invalid
if (separatorIndex < 0)
qWarning() << "Invalid line #" << lineIndex << ":" << line;
} else {
assContent[currentSection].insert(line.mid(0, separatorIndex),
line.mid(baseValueIndex));
// Script's info
else if (currentSection == sectionScriptInfo) {
assInfo.insert(line.mid(0, separatorIndex), line.mid(baseValueIndex));
qDebug() << "Got line #" << lineIndex << ":" << line;
}
// Skip the headers and the comment lines
else if ((currentSection == sectionStyles) && line.startsWith("Style: ")) {
stylesContent.append(line);
} else if ((currentSection == sectionEvents) && line.startsWith("Dialogue: ")) {
eventsContent.append(line);
}
}
lineIndex++;
}
/* Construct the styles and the lines */
for (const auto &styleLine : assContent[sectionStyles])
assStyles.push_back(std::make_shared<Style>(styleLine.toString()));
for (const auto &assLine : assContent[sectionEvents])
assLines.push_back(std::make_shared<Line>(assLine.toString()));
/* Get back some memory */
assContent.remove(sectionStyles);
assContent.remove(sectionEvents);
// Construct the styles and the lines
try {
for (const auto &styleLine : stylesContent)
assStyles.push_back(std::make_shared<Style>(styleLine));
for (const auto &assLine : eventsContent)
assLines.push_back(std::make_shared<Line>(assLine));
} catch (const std::runtime_error &e) {
qCritical() << "Failed to create ASS style or events with error:" << e.what();
}
return true;
}
@@ -62,26 +74,23 @@ AssFactory::initFromStorage() noexcept
bool
AssFactory::checkValidity() const noexcept
{
if (assContent.isEmpty()) {
if (assInfo.isEmpty())
return false;
}
const SectionContent &scriptInfo = assContent[sectionScriptInfo];
/* Check for fields that must be integers */
// Check for fields that must be integers
bool ok = false;
SectionContent::const_iterator it = scriptInfo.begin();
const SectionContent::const_iterator end = scriptInfo.end();
SectionContent::const_iterator it = assInfo.begin();
const SectionContent::const_iterator end = assInfo.end();
while (it != end) {
if (intTypeFields.contains(it.key()) && (it.value().toInt(&ok), !ok))
return false;
++it;
}
/* Check for fixed values fields */
// Check for fixed values fields
for (const auto &fixedValues : checkedValues) {
if (const auto &first = fixedValues.first;
scriptInfo.contains(first) && scriptInfo[first] != fixedValues.second)
assInfo.contains(first) && assInfo[first] != fixedValues.second)
return false;
}
@@ -120,5 +129,5 @@ AssFactory::getLines(QVector<AssFactory::LinePtr> &ret) const noexcept
AssFactory::SectionContent
AssFactory::getInfoSection() const noexcept
{
return assContent[sectionScriptInfo];
return assInfo;
}
Chargement en cours