Skip to content
Extraits de code Groupes Projets
Vérifiée Valider a08d7110 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

LIB: Use QRegularExpression instead of QRegExp as it's the replacement

parent 217d7010
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!7Add the ASS sub document and the ASS tree
Ce commit fait partie de la requête de fusion !7. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
#include "Line.hh"
#include "AssFactory.hh"
#include <QRegularExpression>
using namespace Vivy::Ass;
Line::Line(AssFactory *const factory, const QString &lineString)
......@@ -22,6 +24,8 @@ Line::Line(AssFactory *const factory, const QString &lineString)
// NOTE: time is of the form: `h:mm:ss.cc`
};
qDebug() << "Try to create line for" << lineString;
static const QString lineHeader = "Dialogue: ";
if (!lineString.startsWith(lineHeader))
throw std::runtime_error(("invalid event line header: " + lineString).toStdString());
......@@ -57,28 +61,38 @@ Line::Line(AssFactory *const factory, const QString &lineString)
for (int i = 0; i < LineIndex::Text; ++i)
contentList.removeFirst();
___contentAsText = contentList.join("");
qDebug() << "The content text is" << ___contentAsText;
initSylFromString(___contentAsText);
}
void
Line::initSylFromString(const QString &line) noexcept
{
// Matches syllabes like: `{\toto}{\alpha&HFF}content`
QRegExp re("(?:{[^}]*})+[^{]*", Qt::CaseInsensitive, QRegExp::RegExp);
QRegularExpression re("((?:{[^}]*})+[^{]*)");
if (!re.isValid())
qFatal("The regex '%s' is not valid...", re.pattern().toStdString().c_str());
int pos = 0;
bool once = false;
try {
while ((pos = re.indexIn(line, pos)) != -1) {
qDebug() << re.cap(1);
content.append(Syl(this, re.cap(1)));
pos += re.matchedLength();
qDebug() << "Matching...";
QRegularExpressionMatchIterator it = re.globalMatch(line);
qDebug() << "Matched!";
while (it.hasNext()) {
QRegularExpressionMatch match = it.next();
qDebug() << match.captured(1);
content.append(Syl(this, match.captured(1)));
once |= true;
}
} catch (const std::runtime_error &e) {
qCritical() << "Failed to init syllabes with line:" << line;
qCritical() << "Fallback to all line is one syllabe";
pos = 0;
once = false;
}
if (pos == 0) {
if (!once) {
qDebug() << "Use RAW for" << line;
content.clear();
content.append(Syl(this, line, Syl::ConstructMode::Raw));
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter