Expose source substitution interface.

This commit is contained in:
Bartosz Taudul 2020-04-17 18:59:24 +02:00
parent 5f22e35c26
commit 47cfb4ae35
2 changed files with 16 additions and 8 deletions

View File

@ -12949,16 +12949,9 @@ void View::DrawInfo()
static char test[1024] = {}; static char test[1024] = {};
ImGui::SetNextItemWidth( -1 ); ImGui::SetNextItemWidth( -1 );
ImGui::InputTextWithHint( "##srcSubstTest", "Enter example source location to test substitutions", test, 1024 ); ImGui::InputTextWithHint( "##srcSubstTest", "Enter example source location to test substitutions", test, 1024 );
std::string res = test;
std::string tmp;
if( m_sourceRegexValid ) if( m_sourceRegexValid )
{ {
for( auto& v : m_sourceSubstitutions ) TextFocused( "Result:", SourceSubstitution( test ) );
{
tmp = std::regex_replace( res, v.regex, v.target );
std::swap( tmp, res );
}
TextFocused( "Result:", res.c_str() );
} }
else else
{ {
@ -16122,4 +16115,17 @@ bool View::GetZoneRunningTime( const ContextSwitch* ctx, const ZoneEvent& ev, in
return true; 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();
}
} }

View File

@ -89,6 +89,8 @@ public:
std::string GetAddress() const { return m_worker.GetAddr(); } std::string GetAddress() const { return m_worker.GetAddr(); }
int GetPort() const { return m_worker.GetPort(); } int GetPort() const { return m_worker.GetPort(); }
const char* SourceSubstitution( const char* srcFile ) const;
private: private:
enum class Namespace : uint8_t enum class Namespace : uint8_t
{ {