diff --git a/src/NH/Bass/TransitionInfo.cpp b/src/NH/Bass/TransitionInfo.cpp index 2bacef9..0fcba16 100644 --- a/src/NH/Bass/TransitionInfo.cpp +++ b/src/NH/Bass/TransitionInfo.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace NH::Bass { @@ -12,8 +13,18 @@ namespace NH::Bass { for (const auto& [key, transition]: m_FilteredTransitions) { - String regex = String(key.c_str()).Replace(",", "|").Replace(" ", "\\s*").Replace("*", ".*");; - if (regex.IsMatchesMask(targetTheme.c_str())) + String regexString = String(key.c_str()) + // interpret comma as an OR operator, "THEME_1,THEME_2" -> "THEME_1|THEME_2" + .Replace(",", "|") + // interpret a space as zero or more whitespace characters + .Replace(" ", "\\s*") + // nasty hack to avoid replacement of .* -> ..* by the next step + .Replace(".*", "*") + // interpret wildcard (*) as any match (.*) in the regex syntax + .Replace("*", ".*"); + + const std::regex regex(regexString); + if (std::smatch match; std::regex_match(targetTheme, match, regex)) { return transition; } @@ -26,7 +37,7 @@ namespace NH::Bass return m_DefaultTransition; } - void TransitionInfo::AddTransitionEffect(TransitionEffect effect, double duration, const std::string& filter) + void TransitionInfo::AddTransitionEffect(const TransitionEffect effect, const double duration, const std::string& filter) { Transition* transition = filter.empty() ? &m_DefaultTransition : GetFilteredTransition(filter); transition->Effect = effect; @@ -35,7 +46,7 @@ namespace NH::Bass void TransitionInfo::AddMidiFile(const MidiFile& file, const std::string& filter) { - Transition* transition = filter == "" ? &m_DefaultTransition : GetFilteredTransition(filter); + Transition* transition = filter.empty() ? &m_DefaultTransition : GetFilteredTransition(filter); Transition::TimePoint timePoint{-1}; for (const auto& [key, start, end] : file.GetTones()) { @@ -58,18 +69,18 @@ namespace NH::Bass void TransitionInfo::AddTimePoint(const Transition::TimePoint& timePoint, const std::string& filter) { - Transition* transition = filter == "" ? &m_DefaultTransition : GetFilteredTransition(filter); + Transition* transition = filter.empty() ? &m_DefaultTransition : GetFilteredTransition(filter); transition->TimePoints.push_back(timePoint); } void TransitionInfo::AddJingle(std::shared_ptr jingle, const double delay, const std::string& filter) { - Transition* transition = filter == "" ? &m_DefaultTransition : GetFilteredTransition(filter); + Transition* transition = filter.empty() ? &m_DefaultTransition : GetFilteredTransition(filter); transition->Jingle = std::move(jingle); transition->JingleDelay = delay; } - Transition* TransitionInfo::GetFilteredTransition(std::string filter) + Transition* TransitionInfo::GetFilteredTransition(const std::string& filter) { if (!m_FilteredTransitions.contains(filter)) { diff --git a/src/NH/Bass/TransitionInfo.h b/src/NH/Bass/TransitionInfo.h index 4a33988..5f72735 100644 --- a/src/NH/Bass/TransitionInfo.h +++ b/src/NH/Bass/TransitionInfo.h @@ -27,10 +27,10 @@ namespace NH::Bass [[nodiscard]] const Transition& GetTransition(const std::string& targetTheme) const; [[nodiscard]] const Transition& GetDefaultTransition() const; - [[nodiscard]] std::string GetSourceTheme() const { return m_SourceTheme; } + [[nodiscard]] const std::string& GetSourceTheme() const { return m_SourceTheme; } private: - Transition* GetFilteredTransition(std::string filter); + Transition* GetFilteredTransition(const std::string& filter); }; }