aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKawe Mazidjatari <48657826+Mauler125@users.noreply.github.com>2022-05-13 21:54:39 +0200
committerKawe Mazidjatari <48657826+Mauler125@users.noreply.github.com>2022-05-13 21:54:39 +0200
commit76ed31a29822e40d157792fcbccc604587c3d790 (patch)
treed2f63a4e45fde87775749944f507484784510f8b
parentaf9e2fe286e97140c40b2461bbd5d131125ac768 (diff)
downloadNorthstarLauncher-76ed31a29822e40d157792fcbccc604587c3d790.tar.gz
NorthstarLauncher-76ed31a29822e40d157792fcbccc604587c3d790.zip
Improve regex in 'CNetAdr2::GetBase'
-rw-r--r--NorthstarDedicatedTest/NetAdr2.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/NorthstarDedicatedTest/NetAdr2.cpp b/NorthstarDedicatedTest/NetAdr2.cpp
index edf2d180..1a44390b 100644
--- a/NorthstarDedicatedTest/NetAdr2.cpp
+++ b/NorthstarDedicatedTest/NetAdr2.cpp
@@ -224,12 +224,18 @@ bool CNetAdr2::SetFromSockadr(sockaddr_storage* s)
//-----------------------------------------------------------------------------
std::string CNetAdr2::GetBase(void) const
{
- std::string svIpAdr = m_svip;
- static std::regex rx("\\].*");
- svIpAdr.erase(0, 1);
- svIpAdr = std::regex_replace(svIpAdr, rx, "");
+ static std::regex rx("[^\\[]*.(.*)(\\]).*");
+ std::smatch smRegexMatches;
+ std::regex_search(m_svip, smRegexMatches, rx);
- return svIpAdr;
+ if (smRegexMatches.size() > 0)
+ {
+ return smRegexMatches[1].str();
+ }
+ else
+ {
+ return "127.0.0.1";
+ }
}
//-----------------------------------------------------------------------------
@@ -238,11 +244,18 @@ std::string CNetAdr2::GetBase(void) const
//-----------------------------------------------------------------------------
std::string CNetAdr2::GetBase(std::string svInAdr) const
{
- static std::regex rx("\\].*");
- svInAdr.erase(0, 1);
- svInAdr = std::regex_replace(svInAdr, rx, "");
+ static std::regex rx("[^\\[]*.(.*)(\\]).*");
+ std::smatch smRegexMatches;
+ std::regex_search(svInAdr, smRegexMatches, rx);
- return svInAdr;
+ if (smRegexMatches.size() > 0)
+ {
+ return smRegexMatches[1].str();
+ }
+ else
+ {
+ return "127.0.0.1";
+ }
}
//-----------------------------------------------------------------------------