From 1db2e8c52abb339a48ae09b9a4fc0bb98b574103 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 21 Aug 2020 10:19:15 +0200 Subject: [PATCH] regexes: conversion from std::regex to jpcre2: mkvtoolnix-gui/**/* --- src/mkvtoolnix-gui/main_window/main_window.cpp | 3 ++- .../merge/file_identification_thread.cpp | 17 +++++++++-------- src/mkvtoolnix-gui/util/settings.cpp | 3 ++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/mkvtoolnix-gui/main_window/main_window.cpp b/src/mkvtoolnix-gui/main_window/main_window.cpp index d6e3262c1..6e58d1beb 100644 --- a/src/mkvtoolnix-gui/main_window/main_window.cpp +++ b/src/mkvtoolnix-gui/main_window/main_window.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -520,7 +521,7 @@ MainWindow::silentlyCheckForUpdates() { QString MainWindow::versionStringForSettings(version_number_t const &version) { - return Q("version_%1").arg(to_qs(std::regex_replace(version.to_string(), std::regex{"[^0-9]+"}, "_"))); + return Q("version_%1").arg(Q(version.to_string()).replace(QRegularExpression{Q("[^0-9]+")}, Q("_"))); } void diff --git a/src/mkvtoolnix-gui/merge/file_identification_thread.cpp b/src/mkvtoolnix-gui/merge/file_identification_thread.cpp index 0fe291f5e..edc3b0ca0 100644 --- a/src/mkvtoolnix-gui/merge/file_identification_thread.cpp +++ b/src/mkvtoolnix-gui/merge/file_identification_thread.cpp @@ -9,6 +9,7 @@ #include #include "common/qt.h" +#include "common/regex.h" #include "common/timestamp.h" #include "mkvtoolnix-gui/merge/file_identification_thread.h" #include "mkvtoolnix-gui/merge/source_file.h" @@ -30,7 +31,7 @@ class FileIdentificationWorkerPrivate { QList m_toIdentify; QMutex m_mutex; QAtomicInteger m_abortPlaylistScan; - std::regex m_simpleChaptersRE, m_xmlChaptersRE, m_xmlSegmentInfoRE, m_xmlTagsRE; + mtx::regex::jp::Regex m_simpleChaptersRE, m_xmlChaptersRE, m_xmlSegmentInfoRE, m_xmlTagsRE; explicit FileIdentificationWorkerPrivate() { @@ -44,10 +45,10 @@ FileIdentificationWorker::FileIdentificationWorker(QObject *parent) , p_ptr{new FileIdentificationWorkerPrivate{}} { auto p = p_func(); - p->m_simpleChaptersRE = std::regex{R"(^CHAPTER\d{2}=[\s\S]*CHAPTER\d{2}NAME=)"}; - p->m_xmlChaptersRE = std::regex{R"(<\?xml[^>]+version[\s\S]*\?>[\s\S]*)"}; - p->m_xmlSegmentInfoRE = std::regex{R"(<\?xml[^>]+version[\s\S]*\?>[\s\S]*)"}; - p->m_xmlTagsRE = std::regex{R"(<\?xml[^>]+version[\s\S]*\?>[\s\S]*)"}; + p->m_simpleChaptersRE = mtx::regex::jp::Regex{R"(^CHAPTER\d{2}=[\s\S]*CHAPTER\d{2}NAME=)"}; + p->m_xmlChaptersRE = mtx::regex::jp::Regex{R"(<\?xml[^>]+version[\s\S]*\?>[\s\S]*)"}; + p->m_xmlSegmentInfoRE = mtx::regex::jp::Regex{R"(<\?xml[^>]+version[\s\S]*\?>[\s\S]*)"}; + p->m_xmlTagsRE = mtx::regex::jp::Regex{R"(<\?xml[^>]+version[\s\S]*\?>[\s\S]*)"}; } FileIdentificationWorker::~FileIdentificationWorker() { @@ -167,13 +168,13 @@ FileIdentificationWorker::handleFileThatShouldBeSelectedElsewhere(QString const auto content = std::string{ file.read(1024).data() }; - if (std::regex_search(content, p->m_simpleChaptersRE) || std::regex_search(content, p->m_xmlChaptersRE)) + if (mtx::regex::match(content, p->m_simpleChaptersRE) || mtx::regex::match(content, p->m_xmlChaptersRE)) Q_EMIT identifiedAsXmlOrSimpleChapters(fileName); - else if (std::regex_search(content, p->m_xmlSegmentInfoRE)) + else if (mtx::regex::match(content, p->m_xmlSegmentInfoRE)) Q_EMIT identifiedAsXmlSegmentInfo(fileName); - else if (std::regex_search(content, p->m_xmlTagsRE)) + else if (mtx::regex::match(content, p->m_xmlTagsRE)) Q_EMIT identifiedAsXmlTags(fileName); else diff --git a/src/mkvtoolnix-gui/util/settings.cpp b/src/mkvtoolnix-gui/util/settings.cpp index 1eec6af7c..5ddc4a4e3 100644 --- a/src/mkvtoolnix-gui/util/settings.cpp +++ b/src/mkvtoolnix-gui/util/settings.cpp @@ -12,6 +12,7 @@ #include "common/fs_sys_helpers.h" #include "common/iso639.h" #include "common/qt.h" +#include "common/regex.h" #include "common/version.h" #include "mkvtoolnix-gui/app.h" #include "mkvtoolnix-gui/jobs/program_runner.h" @@ -970,7 +971,7 @@ Settings::localeToUse(QString const &requestedLocale) locale = ""; if (locale.empty()) { - locale = std::regex_replace(translation_c::get_default_ui_locale(), std::regex{"\\..*"}, ""); + locale = mtx::regex::replace(translation_c::get_default_ui_locale(), mtx::regex::jp::Regex{"\\..*"}, "", ""); if (-1 == translation_c::look_up_translation(locale)) locale = ""; }