substr() returns a new string while erase() and assign() modify the existing one
return false;
const std::string nickIdent = user->nick + "!" + user->ident;
- std::string prefix = mask.substr(0, at);
+ std::string prefix(mask, 0, at);
if (InspIRCd::Match(nickIdent, prefix, NULL))
{
- std::string suffix = mask.substr(at + 1);
+ std::string suffix(mask, at + 1);
if (InspIRCd::Match(user->host, suffix, NULL) ||
InspIRCd::Match(user->dhost, suffix, NULL) ||
InspIRCd::MatchCIDR(user->GetIPString(), suffix, NULL))
}
else
{
- address_copy = address.substr(username_addr_pos + 1);
- cidr_copy = cidr_mask.substr(username_mask_pos + 1);
+ address_copy.assign(address, username_addr_pos + 1, std::string::npos);
+ cidr_copy.assign(cidr_mask, username_mask_pos + 1, std::string::npos);
}
}
else
// the leading "-" is optional; remove it if present.
if (param[0] == '-')
- param = param.substr(1);
+ param.erase(param.begin());
FOREACH_MOD(OnModuleRehash, (user, param));
return CMD_SUCCESS;
line = prefix.str();
}
- line.append(cl.substr(start, pos - start + 1));
+ line.append(cl, start, pos - start + 1);
}
if (line.length() != prefix.str().length())
/* This is the last parameter */
if (token[0] == ':' && !first)
{
- token = token.substr(1);
+ token.erase(token.begin());
if (!StreamEnd())
{
token += ' ';
if (p == std::string::npos)
p = this->tokens.length();
- token = this->tokens.substr(this->pos, p - this->pos);
+ token.assign(tokens, this->pos, p - this->pos);
this->pos = p + 1;
return true;
std::string::size_type dash = x.rfind('-');
if (dash != std::string::npos)
{
- std::string sbegin = x.substr(0, dash);
- std::string send = x.substr(dash+1, x.length());
+ std::string sbegin(x, 0, dash);
range_begin = atoi(sbegin.c_str());
- range_end = atoi(send.c_str());
+ range_end = atoi(x.c_str()+dash+1);
if ((range_begin > 0) && (range_end > 0) && (range_begin < 65536) && (range_end < 65536) && (range_begin < range_end))
{
std::string::size_type i = recvq.find(delim);
if (i == std::string::npos)
return false;
- line = recvq.substr(0, i);
- // TODO is this the most efficient way to split?
- recvq = recvq.substr(i + 1);
+ line.assign(recvq, 0, i);
+ recvq.erase(0, i + 1);
return true;
}
else if (rv < itemlen)
{
SocketEngine::ChangeEventMask(this, FD_WANT_FAST_WRITE | FD_WRITE_WILL_BLOCK);
- front = front.substr(rv);
+ front.erase(0, rv);
sendq_len -= rv;
return;
}
else
{
// stopped in the middle of this string
- front = front.substr(rv);
+ front.erase(0, rv);
rv = 0;
}
}
std::string& parameter = mcitem.param;
// crop mode parameter size to 250 characters
if (parameter.length() > 250 && adding)
- parameter = parameter.substr(0, 250);
+ parameter.erase(250);
ModResult MOD_RESULT;
FIRST_MOD_RESULT(OnRawMode, MOD_RESULT, (user, chan, mh, parameter, adding));
channel->SetMode(this, adding);
if (adding)
{
- parameter = parameter.substr(0, 32);
+ parameter.erase(32);
ext.set(channel, parameter);
}
else
}
else if (ret > 0)
{
- sendq = sendq.substr(ret);
+ sendq.erase(0, ret);
SocketEngine::ChangeEventMask(user, FD_WANT_SINGLE_WRITE);
return 0;
}
}
else if (ret > 0)
{
- buffer = buffer.substr(ret);
+ buffer.erase(0, ret);
SocketEngine::ChangeEventMask(user, FD_WANT_SINGLE_WRITE);
return 0;
}
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());
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());
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)
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;
{
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++)
}
}
- 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))
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('-');
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);
}
}
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))
if (reqbuffer.length() >= postsize)
{
- postdata = reqbuffer.substr(0, postsize);
+ postdata.assign(reqbuffer, 0, postsize);
reqbuffer.erase(0, postsize);
}
else if (!reqbuffer.empty())
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
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;
}
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);
{
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)
{
{
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;
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");
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;
}
}
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)
{
// 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;
if (ServerInstance->Modes->FindPrefix(dest[0]))
{
pfx = dest[0];
- dest = dest.substr(1);
+ dest.erase(dest.begin());
}
if (dest[0] == '#')
{
if (p != std::string::npos)
{
key.erase(p);
- val = prop.substr(p+1);
+ val.assign(prop, p+1, std::string::npos);
}
if (key == "burst")
{
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");
if (prefix[0] == ':')
{
- prefix = prefix.substr(1);
+ prefix.erase(prefix.begin());
if (prefix.empty())
{
return;
eol_found:
// just found a newline. Terminate the string, and pull it out of recvq
- recvq = recvq.substr(qpos);
+ recvq.erase(0, qpos);
// TODO should this be moved to when it was inserted in recvq?
ServerInstance->stats.Recv += qpos;
if (text.length() > ServerInstance->Config->Limits.MaxLine - 2)
{
// this should happen rarely or never. Crop the string at 512 and try again.
- std::string try_again = text.substr(0, ServerInstance->Config->Limits.MaxLine - 2);
+ std::string try_again(0, ServerInstance->Config->Limits.MaxLine - 2);
Write(try_again);
return;
}