extract params from std::string_view

This commit is contained in:
orignal 2025-07-06 16:45:47 -04:00
parent 88375bf9c0
commit 1862f28a98
2 changed files with 19 additions and 15 deletions

View file

@ -968,24 +968,28 @@ namespace client
SendMessageReply (m_Buffer, l, false);
}
const std::map<std::string_view, std::string_view> SAMSocket::ExtractParams (char * buf)
const std::map<std::string_view, std::string_view> SAMSocket::ExtractParams (std::string_view buf)
{
std::map<std::string_view, std::string_view> params;
char * separator;
do
size_t pos = 0;
while (pos < buf.length ())
{
separator = strchr (buf, ' ');
if (separator) *separator = 0;
char * value = strchr (buf, '=');
if (value)
std::string_view field;
auto separator = buf.find (' ', pos);
if (separator != std::string_view::npos)
{
*value = 0;
value++;
params.emplace (buf, value);
field = buf.substr (pos, separator - pos);
pos = separator + 1;
}
buf = separator + 1;
else
{
field = buf.substr (pos);
pos = buf.length ();
}
auto value = field.find ('=');
if (value != std::string_view::npos)
params.emplace (field.substr (0, value), field.substr (value + 1));
}
while (separator);
return params;
}

View file

@ -152,7 +152,7 @@ namespace client
void SendStreamI2PError(const std::string & msg);
void SendStreamCantReachPeer(const std::string & msg);
size_t ProcessDatagramSend (char * buf, size_t len, const char * data); // from SAM 1.0
const std::map<std::string_view, std::string_view> ExtractParams (char * buf);
const std::map<std::string_view, std::string_view> ExtractParams (std::string_view buf);
void Connect (std::shared_ptr<const i2p::data::LeaseSet> remote, std::shared_ptr<SAMSession> session = nullptr);
void HandleConnectLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet);