Skip to content

Commit

Permalink
Trim address entry field.
Browse files Browse the repository at this point in the history
Sometimes a stray whitespace may be inserted in the address field, for
example when copying and pasting from somewhere else.
  • Loading branch information
wolfpld committed Sep 9, 2024
1 parent 5795bc5 commit d46eebf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
7 changes: 3 additions & 4 deletions profiler/src/ConnectionHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,16 @@ void ConnectionHistory::Rebuild()
std::swap( m_connHistVec, vec );
}

void ConnectionHistory::Count( const char* name )
void ConnectionHistory::Count( const std::string& name )
{
std::string addr( name );
auto it = m_connHistMap.find( addr );
auto it = m_connHistMap.find( name );
if( it != m_connHistMap.end() )
{
it->second++;
}
else
{
m_connHistMap.emplace( std::move( addr ), 1 );
m_connHistMap.emplace( name, 1 );
}
Rebuild();
}
Expand Down
2 changes: 1 addition & 1 deletion profiler/src/ConnectionHistory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ConnectionHistory

const std::string& Name( size_t idx ) const { return m_connHistVec[idx]->first; }

void Count( const char* name );
void Count( const std::string& name );
void Erase( size_t idx );

bool empty() const { return m_connHistVec.empty(); }
Expand Down
33 changes: 21 additions & 12 deletions profiler/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,20 +967,29 @@ static void DrawContents()
connectClicked |= ImGui::Button( ICON_FA_WIFI " Connect" );
if( connectClicked && *addr && !loadThread.joinable() )
{
connHist->Count( addr );
auto aptr = addr;
while( *aptr == ' ' || *aptr == '\t' ) aptr++;
auto aend = aptr;
while( *aend && *aend != ' ' && *aend != '\t' ) aend++;

const auto addrLen = strlen( addr );
auto ptr = addr + addrLen - 1;
while( ptr > addr && *ptr != ':' ) ptr--;
if( *ptr == ':' )
if( aptr != aend )
{
std::string addrPart = std::string( addr, ptr );
uint16_t portPart = (uint16_t)atoi( ptr+1 );
view = std::make_unique<tracy::View>( RunOnMainThread, addrPart.c_str(), portPart, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements );
}
else
{
view = std::make_unique<tracy::View>( RunOnMainThread, addr, port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements );
std::string address( aptr, aend );
connHist->Count( address );

auto adata = address.data();
auto ptr = adata + address.size() - 1;
while( ptr > adata && *ptr != ':' ) ptr--;
if( *ptr == ':' )
{
std::string addrPart = std::string( adata, ptr );
uint16_t portPart = (uint16_t)atoi( ptr+1 );
view = std::make_unique<tracy::View>( RunOnMainThread, addrPart.c_str(), portPart, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements );
}
else
{
view = std::make_unique<tracy::View>( RunOnMainThread, address.c_str(), port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements );
}
}
}
if( s_config.memoryLimit )
Expand Down

0 comments on commit d46eebf

Please sign in to comment.