From 78fd31bcd408367743ca3c542a2fb77acd23fe1a Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Tue, 13 Jul 2021 23:19:41 +0200
Subject: [PATCH] LIB: Loading an ASS is working, only import Dialog Events for
 now

---
 src/Lib/Ass/Line.cc |  7 -------
 src/Lib/Ass/Syl.cc  | 18 ++++++++++++------
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/Lib/Ass/Line.cc b/src/Lib/Ass/Line.cc
index bc97dcc1..ef6a9d0a 100644
--- a/src/Lib/Ass/Line.cc
+++ b/src/Lib/Ass/Line.cc
@@ -24,8 +24,6 @@ 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());
@@ -61,7 +59,6 @@ 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);
 }
 
@@ -75,13 +72,10 @@ Line::initSylFromString(const QString &line) noexcept
 
     bool once = false;
     try {
-        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;
         }
@@ -92,7 +86,6 @@ Line::initSylFromString(const QString &line) noexcept
     }
 
     if (!once) {
-        qDebug() << "Use RAW for" << line;
         content.clear();
         content.append(Syl(this, line, Syl::ConstructMode::Raw));
     }
diff --git a/src/Lib/Ass/Syl.cc b/src/Lib/Ass/Syl.cc
index 3421da6b..bac0a4d0 100644
--- a/src/Lib/Ass/Syl.cc
+++ b/src/Lib/Ass/Syl.cc
@@ -1,6 +1,8 @@
 #include "Syl.hh"
 #include "Line.hh"
 
+#include <QRegularExpression>
+
 using namespace Vivy::Ass;
 
 Syl::Syl(Line *const line, const QString &lineString, ConstructMode mode) noexcept
@@ -20,12 +22,16 @@ Syl::Syl(Line *const line, const QString &lineString, ConstructMode mode) noexce
 quint64
 Syl::getDurationFromString(const QString &line) noexcept
 {
-    QRegExp re("\\\\(?:k|K|ko|kf)(\\d+)");
-    int pos          = 0;
-    quint64 duration = 0;
-    while ((pos = re.indexIn(line, pos)) != -1) {
-        duration += re.cap(1).toUInt();
-    }
+    QRegularExpression re("\\\\(?:k|K|ko|kf)(\\d+)");
+    if (!re.isValid())
+        qFatal("The regex '%s' is not valid...", re.pattern().toStdString().c_str());
+
+    quint64 duration                   = 0;
+    QRegularExpressionMatchIterator it = re.globalMatch(line);
+
+    while (it.hasNext())
+        duration += it.next().captured(1).toUInt();
+
     return duration;
 }
 
-- 
GitLab