From 47cfb4ae351a022aa45aeca3df33b0e3e80a2217 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 17 Apr 2020 18:59:24 +0200 Subject: [PATCH] Expose source substitution interface. --- server/TracyView.cpp | 22 ++++++++++++++-------- server/TracyView.hpp | 2 ++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 6bc246ba..8ef1fbfc 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -12949,16 +12949,9 @@ void View::DrawInfo() static char test[1024] = {}; ImGui::SetNextItemWidth( -1 ); ImGui::InputTextWithHint( "##srcSubstTest", "Enter example source location to test substitutions", test, 1024 ); - std::string res = test; - std::string tmp; if( m_sourceRegexValid ) { - for( auto& v : m_sourceSubstitutions ) - { - tmp = std::regex_replace( res, v.regex, v.target ); - std::swap( tmp, res ); - } - TextFocused( "Result:", res.c_str() ); + TextFocused( "Result:", SourceSubstitution( test ) ); } else { @@ -16122,4 +16115,17 @@ bool View::GetZoneRunningTime( const ContextSwitch* ctx, const ZoneEvent& ev, in return true; } +const char* View::SourceSubstitution( const char* srcFile ) const +{ + if( !m_sourceRegexValid || m_sourceSubstitutions.empty() ) return srcFile; + static std::string res, tmp; + res.assign( srcFile ); + for( auto& v : m_sourceSubstitutions ) + { + tmp = std::regex_replace( res, v.regex, v.target ); + std::swap( tmp, res ); + } + return res.c_str(); +} + } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index f1514f20..cfd7852a 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -89,6 +89,8 @@ public: std::string GetAddress() const { return m_worker.GetAddr(); } int GetPort() const { return m_worker.GetPort(); } + const char* SourceSubstitution( const char* srcFile ) const; + private: enum class Namespace : uint8_t {