mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Improve NetAdr2 regex
This commit is contained in:
parent
70503bd975
commit
ffa6eb55e8
@ -225,12 +225,18 @@ bool CNetAdr2::SetFromSockadr(sockaddr_storage* s)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
string CNetAdr2::GetBase(void) const
|
string CNetAdr2::GetBase(void) const
|
||||||
{
|
{
|
||||||
string svIpAdr = m_svip;
|
static std::regex rx("[^\\[]*.(.*)(\\]).*");
|
||||||
static std::regex rx("\\].*");
|
std::smatch smRegexMatches;
|
||||||
svIpAdr.erase(0, 1);
|
std::regex_search(m_svip, smRegexMatches, rx);
|
||||||
svIpAdr = std::regex_replace(svIpAdr, rx, "");
|
|
||||||
|
|
||||||
return svIpAdr;
|
if (smRegexMatches.size() > 0)
|
||||||
|
{
|
||||||
|
return smRegexMatches[1].str();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "127.0.0.1";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -239,11 +245,18 @@ string CNetAdr2::GetBase(void) const
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
string CNetAdr2::GetBase(string svInAdr) const
|
string CNetAdr2::GetBase(string svInAdr) const
|
||||||
{
|
{
|
||||||
static std::regex rx("\\].*");
|
static std::regex rx("[^\\[]*.(.*)(\\]).*");
|
||||||
svInAdr.erase(0, 1);
|
std::smatch smRegexMatches;
|
||||||
svInAdr = std::regex_replace(svInAdr, rx, "");
|
std::regex_search(svInAdr, smRegexMatches, rx);
|
||||||
|
|
||||||
return svInAdr;
|
if (smRegexMatches.size() > 0)
|
||||||
|
{
|
||||||
|
return smRegexMatches[1].str();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "127.0.0.1";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user