Sélectionner une révision Git
Line.cc 4,13 Kio
#include "Line.hh"
#include "AssFactory.hh"
using namespace Vivy::Ass;
Line::Line(AssFactory *const factory, const QString &lineString)
: assFactory(factory)
{
enum LineIndex : int {
Layer = 0, // int
Start = 1, // time
End = 2, // time
Style = 3, // text
Name = 4, // text
MarginL = 5, // int
MarginR = 6, // int
MarginV = 7, // int
Effect = 8, // text
Text = 9, // text
PastLastCode
// NOTE: time is of the form: `h:mm:ss.cc`
};
const QString lineHeader = QStringLiteral("Dialogue: ");
isComment = !lineString.startsWith(lineHeader);
const QString lineContent = lineString.mid(lineString.indexOf(": ") + 2 /* strlen ": " */);
QStringList contentList = lineContent.split(",", Qt::KeepEmptyParts, Qt::CaseInsensitive);
if (contentList.size() < LineIndex::PastLastCode)
throw std::runtime_error(("invalid number of items " + QString::number(contentList.size()) +
" instead of something superiror or equal to " +
QString::number(PastLastCode) + " for line: " + lineContent)
.toStdString());
layer = Utils::decodeLineToInteger(contentList[LineIndex::Layer], "Layer is not an integer");
effect = contentList[LineIndex::Effect];
nameOrActor = contentList[LineIndex::Name];
start = Utils::Time::fromString(contentList[LineIndex::Start]).toUInt();
end = Utils::Time::fromString(contentList[LineIndex::End]).toUInt();
styleProperties.marginL =
Utils::decodeLineToInteger(contentList[LineIndex::MarginL], "MarginL is not an integer");
styleProperties.marginR =
Utils::decodeLineToInteger(contentList[LineIndex::MarginR], "MarginR is not an integer");
styleProperties.marginV =
Utils::decodeLineToInteger(contentList[LineIndex::MarginV], "MarginV is not an integer");
const QString style = contentList[LineIndex::Style];
if (!assFactory->hasStyle(style))
throw std::runtime_error(("Invalid or not declared style name: " + style).toStdString());
lineStyle = assFactory->getStyle(style);
// Pop all but the text, it may contains `,` characters
for (int i = 0; i < LineIndex::Text; ++i)
contentList.removeFirst();
___contentAsText = contentList.join("");
initSylFromString(___contentAsText);
}
void
Line::initSylFromString(const QString &line) noexcept
{
// Matches syllabes like: `{\toto}{\alpha&HFF}content`
QRegularExpression re("((?:{[^}]*})+[^{]*)");
if (!re.isValid())
logFatal() << "The regex " << VIVY_LOG_QUOTED(re.pattern().toStdString().c_str())
<< " is not valid...";