diff --git a/src/Lib/Ass/Line.cc b/src/Lib/Ass/Line.cc index fa58f2d1c2ee6bb7cfdf579c71fec4c034fffa7a..bc97dcc129ae8c9aff982e775464cf2f1903f977 100644 --- a/src/Lib/Ass/Line.cc +++ b/src/Lib/Ass/Line.cc @@ -1,6 +1,8 @@ #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)); } diff --git a/src/UI/DocumentViews/AssLinesView.cc b/src/UI/DocumentViews/AssLinesView.cc index 4c301705a3c3a42c823a1fb8f2ad27b22bf8d7f3..031bf9944b4023df1088bf41ca307c7e7e29d136 100644 --- a/src/UI/DocumentViews/AssLinesView.cc +++ b/src/UI/DocumentViews/AssLinesView.cc @@ -5,7 +5,7 @@ using namespace Vivy; -AssLinesView::AssLinesView(QAbstractItemModel * model, QWidget *parent) noexcept +AssLinesView::AssLinesView(QAbstractItemModel *model, QWidget *parent) noexcept : QTableView(parent) , delegate(new Delegate(this)) {