mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-07 17:16:00 -05:00
Switch to RegexConfig
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "utility.hpp"
|
||||
#include "platform-funcs.hpp"
|
||||
#include "scene-selection.hpp"
|
||||
#include "regex-config.hpp"
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QLabel>
|
||||
@@ -333,9 +334,8 @@ std::vector<obs_scene_item *> getSceneItemsWithName(obs_scene_t *scene,
|
||||
|
||||
// Match json1 with pattern json2
|
||||
bool matchJson(const std::string &json1, const std::string &json2,
|
||||
bool useRegex)
|
||||
const RegexConfig ®ex)
|
||||
{
|
||||
bool ret = false;
|
||||
auto j1 = formatJsonString(json1).toStdString();
|
||||
auto j2 = formatJsonString(json2).toStdString();
|
||||
|
||||
@@ -346,24 +346,23 @@ bool matchJson(const std::string &json1, const std::string &json2,
|
||||
j2 = json2;
|
||||
}
|
||||
|
||||
if (useRegex) {
|
||||
try {
|
||||
std::regex expr(j2);
|
||||
ret = std::regex_match(
|
||||
j1, expr, std::regex_constants::match_default);
|
||||
} catch (const std::regex_error &) {
|
||||
if (regex.Enabled()) {
|
||||
auto expr = regex.GetRegularExpression(j2);
|
||||
if (!expr.isValid()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
ret = j1 == j2;
|
||||
auto match = expr.match(QString::fromStdString(j1));
|
||||
return match.hasMatch();
|
||||
}
|
||||
return ret;
|
||||
return j1 == j2;
|
||||
}
|
||||
|
||||
bool compareSourceSettings(const OBSWeakSource &source,
|
||||
const std::string &settings, bool useRegex)
|
||||
const std::string &settings,
|
||||
const RegexConfig ®ex)
|
||||
{
|
||||
std::string currentSettings = getSourceSettings(source);
|
||||
return matchJson(currentSettings, settings, useRegex);
|
||||
return matchJson(currentSettings, settings, regex);
|
||||
}
|
||||
|
||||
std::string getDataFilePath(const std::string &file)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "scene-group.hpp"
|
||||
|
||||
class SceneSelection;
|
||||
class RegexConfig;
|
||||
|
||||
bool WeakSourceValid(obs_weak_source_t *ws);
|
||||
std::string GetWeakSourceName(obs_weak_source_t *weak_source);
|
||||
@@ -26,12 +27,13 @@ bool compareIgnoringLineEnding(QString &s1, QString &s2);
|
||||
std::string getSourceSettings(OBSWeakSource ws);
|
||||
void setSourceSettings(obs_source_t *s, const std::string &settings);
|
||||
bool compareSourceSettings(const OBSWeakSource &source,
|
||||
const std::string &settings, bool regex);
|
||||
const std::string &settings,
|
||||
const RegexConfig ®ex);
|
||||
std::vector<obs_scene_item *> getSceneItemsWithName(obs_scene_t *scene,
|
||||
std::string &name);
|
||||
std::string getDataFilePath(const std::string &file);
|
||||
bool matchJson(const std::string &json1, const std::string &json2,
|
||||
bool useRegex);
|
||||
const RegexConfig ®ex);
|
||||
QString formatJsonString(std::string);
|
||||
QString formatJsonString(QString);
|
||||
QString escapeForRegex(QString &s);
|
||||
|
||||
Reference in New Issue
Block a user