summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2015-01-10 15:16:03 +0100
committerAttila Molnar <attilamolnar@hush.com>2015-01-10 15:16:03 +0100
commit47dda4f61512f6047f2b1dcccd1943aab74726e3 (patch)
treea1425a9dbff58b97ef5dcdf169e0d65439513527 /src/modules
parentae10286658d6bb70e5e22526a004ec1b233f6fba (diff)
Reduce std::string::substr() usage
substr() returns a new string while erase() and assign() modify the existing one
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp2
-rw-r--r--src/modules/extra/m_ssl_openssl.cpp2
-rw-r--r--src/modules/m_alias.cpp4
-rw-r--r--src/modules/m_autoop.cpp2
-rw-r--r--src/modules/m_chanhistory.cpp2
-rw-r--r--src/modules/m_channelban.cpp4
-rw-r--r--src/modules/m_dccallow.cpp2
-rw-r--r--src/modules/m_exemptchanops.cpp4
-rw-r--r--src/modules/m_httpd.cpp4
-rw-r--r--src/modules/m_ldapauth.cpp6
-rw-r--r--src/modules/m_namedmodes.cpp4
-rw-r--r--src/modules/m_password_hash.cpp4
-rw-r--r--src/modules/m_silence.cpp2
-rw-r--r--src/modules/m_spanningtree/capab.cpp4
-rw-r--r--src/modules/m_spanningtree/compat.cpp4
-rw-r--r--src/modules/m_spanningtree/postcommand.cpp2
-rw-r--r--src/modules/m_spanningtree/server.cpp2
-rw-r--r--src/modules/m_spanningtree/treesocket1.cpp2
-rw-r--r--src/modules/m_spanningtree/treesocket2.cpp2
19 files changed, 29 insertions, 29 deletions
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index 74b66d2de..be642a79d 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -909,7 +909,7 @@ info_done_dealloc:
}
else if (ret > 0)
{
- sendq = sendq.substr(ret);
+ sendq.erase(0, ret);
SocketEngine::ChangeEventMask(user, FD_WANT_SINGLE_WRITE);
return 0;
}
diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp
index a0c30bb9e..b38478d6d 100644
--- a/src/modules/extra/m_ssl_openssl.cpp
+++ b/src/modules/extra/m_ssl_openssl.cpp
@@ -641,7 +641,7 @@ class OpenSSLIOHook : public SSLIOHook
}
else if (ret > 0)
{
- buffer = buffer.substr(ret);
+ buffer.erase(0, ret);
SocketEngine::ChangeEventMask(user, FD_WANT_SINGLE_WRITE);
return 0;
}
diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp
index 20d3f5c45..5b3979179 100644
--- a/src/modules/m_alias.cpp
+++ b/src/modules/m_alias.cpp
@@ -148,7 +148,7 @@ class ModuleAlias : public Module
return MOD_RES_PASSTHRU;
/* The parameters for the command in their original form, with the command stripped off */
- std::string compare = original_line.substr(command.length());
+ std::string compare(original_line, command.length());
while (*(compare.c_str()) == ' ')
compare.erase(compare.begin());
@@ -212,7 +212,7 @@ class ModuleAlias : public Module
return;
/* The parameters for the command in their original form, with the command stripped off */
- std::string compare = text.substr(scommand.length() + 1);
+ std::string compare(text, scommand.length() + 1);
while (*(compare.c_str()) == ' ')
compare.erase(compare.begin());
diff --git a/src/modules/m_autoop.cpp b/src/modules/m_autoop.cpp
index 801cf6c74..2b9c2e1c2 100644
--- a/src/modules/m_autoop.cpp
+++ b/src/modules/m_autoop.cpp
@@ -47,7 +47,7 @@ class AutoOpList : public ListModeBase
if (pos == 0 || pos == std::string::npos)
return adding ? MOD_RES_DENY : MOD_RES_PASSTHRU;
unsigned int mylevel = channel->GetPrefixValue(source);
- std::string mid = parameter.substr(0, pos);
+ std::string mid(parameter, 0, pos);
PrefixMode* mh = FindMode(mid);
if (adding && !mh)
diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp
index f6e7ea40e..a0929a0d0 100644
--- a/src/modules/m_chanhistory.cpp
+++ b/src/modules/m_chanhistory.cpp
@@ -65,7 +65,7 @@ class HistoryMode : public ParamMode<HistoryMode, SimpleExtItem<HistoryList> >
if (colon == std::string::npos)
return MODEACTION_DENY;
- std::string duration = parameter.substr(colon+1);
+ std::string duration(parameter, colon+1);
if ((IS_LOCAL(source)) && ((duration.length() > 10) || (!IsValidDuration(duration))))
return MODEACTION_DENY;
diff --git a/src/modules/m_channelban.cpp b/src/modules/m_channelban.cpp
index 4d3f80e36..189c0d0bc 100644
--- a/src/modules/m_channelban.cpp
+++ b/src/modules/m_channelban.cpp
@@ -32,12 +32,12 @@ class ModuleBadChannelExtban : public Module
{
if ((mask.length() > 2) && (mask[0] == 'j') && (mask[1] == ':'))
{
- std::string rm = mask.substr(2);
+ std::string rm(mask, 2);
char status = 0;
ModeHandler* mh = ServerInstance->Modes->FindPrefix(rm[0]);
if (mh)
{
- rm = mask.substr(3);
+ rm.assign(mask, 3, std::string::npos);
status = mh->GetModeChar();
}
for (User::ChanList::iterator i = user->chans.begin(); i != user->chans.end(); i++)
diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp
index 1b838be5c..7627ba8c7 100644
--- a/src/modules/m_dccallow.cpp
+++ b/src/modules/m_dccallow.cpp
@@ -101,7 +101,7 @@ class CommandDccallow : public Command
}
}
- std::string nick = parameters[0].substr(1);
+ std::string nick(parameters[0], 1);
User *target = ServerInstance->FindNickOnly(nick);
if ((target) && (!IS_SERVER(target)) && (!target->quitting) && (target->registered == REG_ALL))
diff --git a/src/modules/m_exemptchanops.cpp b/src/modules/m_exemptchanops.cpp
index 2d06b73a0..076445644 100644
--- a/src/modules/m_exemptchanops.cpp
+++ b/src/modules/m_exemptchanops.cpp
@@ -36,7 +36,7 @@ class ExemptChanOps : public ListModeBase
return false;
}
- std::string restriction = word.substr(0, p);
+ std::string restriction(word, 0, p);
// If there is a '-' in the restriction string ignore it and everything after it
// to support "auditorium-vis" and "auditorium-see" in m_auditorium
p = restriction.find('-');
@@ -98,7 +98,7 @@ class ExemptHandler : public HandlerBase3<ModResult, User*, Channel*, const std:
if (pos == std::string::npos)
continue;
if (!i->mask.compare(0, pos, restriction))
- minmode = (*i).mask.substr(pos + 1);
+ minmode.assign(i->mask, pos + 1, std::string::npos);
}
}
diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp
index a4452c9c0..bbd9f1275 100644
--- a/src/modules/m_httpd.cpp
+++ b/src/modules/m_httpd.cpp
@@ -269,7 +269,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
continue;
}
- std::string cheader = reqbuffer.substr(hbegin, hend - hbegin);
+ std::string cheader(reqbuffer, hbegin, hend - hbegin);
std::string::size_type fieldsep = cheader.find(':');
if ((fieldsep == std::string::npos) || (fieldsep == 0) || (fieldsep == cheader.length() - 1))
@@ -300,7 +300,7 @@ class HttpServerSocket : public BufferedSocket, public Timer, public insp::intru
if (reqbuffer.length() >= postsize)
{
- postdata = reqbuffer.substr(0, postsize);
+ postdata.assign(reqbuffer, 0, postsize);
reqbuffer.erase(0, postsize);
}
else if (!reqbuffer.empty())
diff --git a/src/modules/m_ldapauth.cpp b/src/modules/m_ldapauth.cpp
index e89ce4949..eee357ec0 100644
--- a/src/modules/m_ldapauth.cpp
+++ b/src/modules/m_ldapauth.cpp
@@ -64,7 +64,7 @@ class BindInterface : public LDAPInterface
while (i < text.length() - 1 && isalpha(text[i + 1]))
++i;
- std::string key = text.substr(start, (i - start) + 1);
+ std::string key(start, (i - start) + 1);
result.append(replacements[key]);
}
else
@@ -90,8 +90,8 @@ class BindInterface : public LDAPInterface
if (pos == std::string::npos) // malformed
continue;
- std::string key = dnPart.substr(0, pos);
- std::string value = dnPart.substr(pos + 1, dnPart.length() - pos + 1); // +1s to skip the = itself
+ std::string key(dnPart, 0, pos);
+ std::string value(dnPart, pos + 1, dnPart.length() - pos + 1); // +1s to skip the = itself
dnParts[key] = value;
}
diff --git a/src/modules/m_namedmodes.cpp b/src/modules/m_namedmodes.cpp
index 19dff1a8b..1735df924 100644
--- a/src/modules/m_namedmodes.cpp
+++ b/src/modules/m_namedmodes.cpp
@@ -138,8 +138,8 @@ class ModuleNamedModes : public Module
std::string::size_type eq = name.find('=');
if (eq != std::string::npos)
{
- value = name.substr(eq + 1);
- name = name.substr(0, eq);
+ value.assign(name, eq + 1, std::string::npos);
+ name.erase(eq);
}
ModeHandler* mh = ServerInstance->Modes->FindMode(name, MODETYPE_CHANNEL);
diff --git a/src/modules/m_password_hash.cpp b/src/modules/m_password_hash.cpp
index 3cdd2b3ce..09cdbb402 100644
--- a/src/modules/m_password_hash.cpp
+++ b/src/modules/m_password_hash.cpp
@@ -36,7 +36,7 @@ class CommandMkpasswd : public Command
{
if (!algo.compare(0, 5, "hmac-", 5))
{
- std::string type = algo.substr(5);
+ std::string type(algo, 5);
HashProvider* hp = ServerInstance->Modules->FindDataService<HashProvider>("hash/" + type);
if (!hp)
{
@@ -91,7 +91,7 @@ class ModuleOperHash : public Module
{
if (!hashtype.compare(0, 5, "hmac-", 5))
{
- std::string type = hashtype.substr(5);
+ std::string type(hashtype, 5);
HashProvider* hp = ServerInstance->Modules->FindDataService<HashProvider>("hash/" + type);
if (!hp)
return MOD_RES_PASSTHRU;
diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp
index 7298d77e1..22de0ac8b 100644
--- a/src/modules/m_silence.cpp
+++ b/src/modules/m_silence.cpp
@@ -134,7 +134,7 @@ class CommandSilence : public Command
else if (parameters.size() > 0)
{
// one or more parameters, add or delete entry from the list (only the first parameter is used)
- std::string mask = parameters[0].substr(1);
+ std::string mask(parameters[0], 1);
char action = parameters[0][0];
// Default is private and notice so clients do not break
int pattern = CompilePattern("pn");
diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp
index f27fe8889..047808c29 100644
--- a/src/modules/m_spanningtree/capab.cpp
+++ b/src/modules/m_spanningtree/capab.cpp
@@ -386,8 +386,8 @@ bool TreeSocket::Capab(const parameterlist &params)
std::string::size_type equals = item.find('=');
if (equals != std::string::npos)
{
- std::string var = item.substr(0, equals);
- std::string value = item.substr(equals+1, item.length());
+ std::string var(item, 0, equals);
+ std::string value(item, equals+1);
capab->CapKeys[var] = value;
}
}
diff --git a/src/modules/m_spanningtree/compat.cpp b/src/modules/m_spanningtree/compat.cpp
index 127907836..c2ee940fc 100644
--- a/src/modules/m_spanningtree/compat.cpp
+++ b/src/modules/m_spanningtree/compat.cpp
@@ -46,7 +46,7 @@ void TreeSocket::WriteLine(const std::string& original_line)
std::string line = original_line;
std::string::size_type a = line.find(' ');
std::string::size_type b = line.find(' ', a + 1);
- std::string command = line.substr(a + 1, b-a-1);
+ std::string command(line, a + 1, b-a-1);
// now try to find a translation entry
// TODO a more efficient lookup method will be needed later
if (proto_version < 1205)
@@ -68,7 +68,7 @@ void TreeSocket::WriteLine(const std::string& original_line)
{
// No TS or modes in the command
// :22DAAAAAB IJOIN #chan
- const std::string channame = line.substr(b+1, c-b-1);
+ const std::string channame(line, b+1, c-b-1);
Channel* chan = ServerInstance->FindChan(channame);
if (!chan)
return;
diff --git a/src/modules/m_spanningtree/postcommand.cpp b/src/modules/m_spanningtree/postcommand.cpp
index 0695ce632..ae98be946 100644
--- a/src/modules/m_spanningtree/postcommand.cpp
+++ b/src/modules/m_spanningtree/postcommand.cpp
@@ -89,7 +89,7 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, CommandBase* thiscm
if (ServerInstance->Modes->FindPrefix(dest[0]))
{
pfx = dest[0];
- dest = dest.substr(1);
+ dest.erase(dest.begin());
}
if (dest[0] == '#')
{
diff --git a/src/modules/m_spanningtree/server.cpp b/src/modules/m_spanningtree/server.cpp
index d7c6332f2..1c624f5c4 100644
--- a/src/modules/m_spanningtree/server.cpp
+++ b/src/modules/m_spanningtree/server.cpp
@@ -81,7 +81,7 @@ void CommandServer::HandleExtra(TreeServer* newserver, const std::vector<std::st
if (p != std::string::npos)
{
key.erase(p);
- val = prop.substr(p+1);
+ val.assign(prop, p+1, std::string::npos);
}
if (key == "burst")
diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp
index 1a8bdd06c..d2fec0118 100644
--- a/src/modules/m_spanningtree/treesocket1.cpp
+++ b/src/modules/m_spanningtree/treesocket1.cpp
@@ -177,7 +177,7 @@ void TreeSocket::OnDataReady()
{
std::string::size_type rline = line.find('\r');
if (rline != std::string::npos)
- line = line.substr(0,rline);
+ line.erase(rline);
if (line.find('\0') != std::string::npos)
{
SendError("Read null character from socket");
diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp
index 25b8e3b71..1f98f7819 100644
--- a/src/modules/m_spanningtree/treesocket2.cpp
+++ b/src/modules/m_spanningtree/treesocket2.cpp
@@ -47,7 +47,7 @@ void TreeSocket::Split(const std::string& line, std::string& prefix, std::string
if (prefix[0] == ':')
{
- prefix = prefix.substr(1);
+ prefix.erase(prefix.begin());
if (prefix.empty())
{