本文整理汇总了C++中anope::string::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ string::substr方法的具体用法?C++ string::substr怎么用?C++ string::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anope::string
的用法示例。
在下文中一共展示了string::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Parse
void IRCDProto::Parse(const Anope::string &buffer, Anope::string &source, Anope::string &command, std::vector<Anope::string> ¶ms)
{
spacesepstream sep(buffer);
if (buffer[0] == ':')
{
sep.GetToken(source);
source.erase(0, 1);
}
sep.GetToken(command);
for (Anope::string token; sep.GetToken(token);)
{
if (token[0] == ':')
{
if (!sep.StreamEnd())
params.push_back(token.substr(1) + " " + sep.GetRemaining());
else
params.push_back(token.substr(1));
break;
}
else
params.push_back(token);
}
}
示例2:
void IRC2SQL::OnBotNotice(User *u, BotInfo *bi, Anope::string &message)
{
Anope::string versionstr;
if (bi != StatServ)
return;
if (message[0] == '\1' && message[message.length() - 1] == '\1')
{
if (message.substr(0, 9).equals_ci("\1VERSION "))
{
if (u->HasExt("CTCPVERSION"))
return;
u->Extend<bool>("CTCPVERSION");
versionstr = Anope::NormalizeBuffer(message.substr(9, message.length() - 10));
if (versionstr.empty())
return;
query = "UPDATE `" + prefix + "user` "
"SET [email protected]@ "
"WHERE [email protected]@";
query.SetValue("version", versionstr);
query.SetValue("nick", u->nick);
this->RunQuery(query);
}
}
}
示例3: Unescape
static Anope::string Unescape(const Anope::string &string)
{
Anope::string ret = string;
for (int i = 0; special[i].character.empty() == false; ++i)
if (!special[i].replace.empty())
ret = ret.replace_all_cs(special[i].replace, special[i].character);
for (size_t i, last = 0; (i = string.find("&#", last)) != Anope::string::npos;)
{
last = i + 1;
size_t end = string.find(';', i);
if (end == Anope::string::npos)
break;
Anope::string ch = string.substr(i + 2, end - (i + 2));
if (ch.empty())
continue;
long l;
if (!ch.empty() && ch[0] == 'x')
l = strtol(ch.substr(1).c_str(), NULL, 16);
else
l = strtol(ch.c_str(), NULL, 10);
if (l > 0 && l < 256)
ret = ret.replace_all_cs("&#" + ch + ";", Anope::string(l));
}
return ret;
}
示例4: GetFullProgDir
/** The following comes from InspIRCd to get the full path of the Anope executable
*/
static Anope::string GetFullProgDir(const Anope::string &argv0)
{
char buffer[PATH_MAX];
#ifdef _WIN32
/* Windows has specific API calls to get the EXE path that never fail.
* For once, Windows has something of use, compared to the POSIX code
* for this, this is positively neato.
*/
if (GetModuleFileName(NULL, buffer, PATH_MAX))
{
Anope::string fullpath = buffer;
Anope::string::size_type n = fullpath.rfind("\\");
Anope::ServicesBin = fullpath.substr(n + 1, fullpath.length());
return fullpath.substr(0, n);
}
#else
// Get the current working directory
if (getcwd(buffer, PATH_MAX))
{
Anope::string remainder = argv0;
Anope::ServicesBin = remainder;
Anope::string::size_type n = Anope::ServicesBin.rfind("/");
Anope::string fullpath;
if (Anope::ServicesBin[0] == '/')
fullpath = Anope::ServicesBin.substr(0, n);
else
fullpath = Anope::string(buffer) + "/" + Anope::ServicesBin.substr(0, n);
Anope::ServicesBin = Anope::ServicesBin.substr(n + 1, remainder.length());
return fullpath;
}
#endif
return "/";
}
示例5:
cidr::cidr(const Anope::string &ip)
{
bool ipv6 = ip.find(':') != Anope::string::npos;
size_t sl = ip.find_last_of('/');
if (sl == Anope::string::npos)
{
this->cidr_ip = ip;
this->cidr_len = ipv6 ? 128 : 32;
this->addr.pton(ipv6 ? AF_INET6 : AF_INET, ip);
}
else
{
Anope::string real_ip = ip.substr(0, sl);
Anope::string cidr_range = ip.substr(sl + 1);
this->cidr_ip = real_ip;
this->cidr_len = ipv6 ? 128 : 32;
try
{
if (cidr_range.is_pos_number_only())
this->cidr_len = convertTo<unsigned int>(cidr_range);
}
catch (const ConvertException &) { }
this->addr.pton(ipv6 ? AF_INET6 : AF_INET, real_ip);
}
}
示例6: sep
NumberList::NumberList(const Anope::string &list, bool descending) : is_valid(true), desc(descending)
{
Anope::string error;
commasepstream sep(list);
Anope::string token;
sep.GetToken(token);
if (token.empty())
token = list;
do
{
size_t t = token.find('-');
if (t == Anope::string::npos)
{
unsigned num = convertTo<unsigned>(token, error, false);
if (error.empty())
numbers.insert(num);
else
{
if (!this->InvalidRange(list))
{
is_valid = false;
return;
}
}
}
else
{
Anope::string error2;
unsigned num1 = convertTo<unsigned>(token.substr(0, t), error, false);
unsigned num2 = convertTo<unsigned>(token.substr(t + 1), error2, false);
if (error.empty() && error2.empty())
{
for (unsigned i = num1; i <= num2; ++i)
numbers.insert(i);
}
else
{
if (!this->InvalidRange(list))
{
is_valid = false;
return;
}
}
}
} while (sep.GetToken(token));
}
示例7: MailValidate
/**
* Checks whether we have a valid, common e-mail address.
* This is NOT entirely RFC compliant, and won't be so, because I said
* *common* cases. ;) It is very unlikely that e-mail addresses that
* are really being used will fail the check.
*
* @param email Email to Validate
* @return bool
*/
bool MailValidate(const Anope::string &email)
{
bool has_period = false;
static char specials[] = {'(', ')', '<', '>', '@', ',', ';', ':', '\\', '\"', '[', ']', ' '};
if (email.empty())
return false;
Anope::string copy = email;
size_t at = copy.find('@');
if (at == Anope::string::npos)
return false;
Anope::string domain = copy.substr(at + 1);
copy = copy.substr(0, at);
/* Don't accept empty copy or domain. */
if (copy.empty() || domain.empty())
return false;
/* Check for forbidden characters in the name */
for (unsigned i = 0, end = copy.length(); i < end; ++i)
{
if (copy[i] <= 31 || copy[i] >= 127)
return false;
for (unsigned int j = 0; j < 13; ++j)
if (copy[i] == specials[j])
return false;
}
/* Check for forbidden characters in the domain */
for (unsigned i = 0, end = domain.length(); i < end; ++i)
{
if (domain[i] <= 31 || domain[i] >= 127)
return false;
for (unsigned int j = 0; j < 13; ++j)
if (domain[i] == specials[j])
return false;
if (domain[i] == '.')
{
if (!i || i == end - 1)
return false;
has_period = true;
}
}
return has_period;
}
示例8: GetData
static bool GetData(Anope::string &content, Anope::string &tag, Anope::string &data)
{
if (content.empty())
return false;
Anope::string prev, cur;
bool istag;
do
{
prev = cur;
cur.clear();
int len = 0;
istag = false;
if (content[0] == '<')
{
len = content.find_first_of('>');
istag = true;
}
else if (content[0] != '>')
{
len = content.find_first_of('<');
}
if (len)
{
if (istag)
{
cur = content.substr(1, len - 1);
content.erase(0, len + 1);
while (!content.empty() && content[0] == ' ')
content.erase(content.begin());
}
else
{
cur = content.substr(0,len);
content.erase(0, len);
}
}
}
while (istag && !content.empty());
tag = Unescape(prev);
data = Unescape(cur);
return !istag && !data.empty();
}
示例9:
void plexus::senders::SVSLogin::Send(const Anope::string& uid, const Anope::string& acc, const Anope::string& vident, const Anope::string& vhost)
{
Anope::string sid = uid.substr(0, 3);
Server *s = Server::Find(sid);
Uplink::Send(Me, "ENCAP", s ? s->GetName() : sid, "SVSLOGIN", uid, "*", vident.empty() ? "*" : vident, vhost.empty() ? "*" : vhost, acc);
}
示例10: CleanMail
/* strip dots from username, and remove anything after the first + */
Anope::string CleanMail(const Anope::string &email)
{
size_t host = email.find('@');
if (host == Anope::string::npos)
return email;
Anope::string username = email.substr(0, host);
username = username.replace_all_cs(".", "");
size_t sz = username.find('+');
if (sz != Anope::string::npos)
username = username.substr(0, sz);
Anope::string cleaned = username + email.substr(host);
logger.Debug("cleaned {0} to {1}", email, cleaned);
return cleaned;
}
示例11: DoAdd
void DoAdd(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word)
{
size_t pos = word.rfind(' ');
BadWordType bwtype = BW_ANY;
Anope::string realword = word;
if (pos != Anope::string::npos)
{
Anope::string opt = word.substr(pos + 1);
if (!opt.empty())
{
if (opt.equals_ci("SINGLE"))
bwtype = BW_SINGLE;
else if (opt.equals_ci("START"))
bwtype = BW_START;
else if (opt.equals_ci("END"))
bwtype = BW_END;
}
realword = word.substr(0, pos);
}
unsigned badwordsmax = Config->GetModule(this->module)->Get<unsigned>("badwordsmax");
if (badwords->GetBadWordCount(ci) >= badwordsmax)
{
source.Reply(_("Sorry, you can only have \002{0}\002 bad words entries on a channel."), badwordsmax);
return;
}
bool casesensitive = Config->GetModule(this->module)->Get<bool>("casesensitive");
for (BadWord *bw : badwords->GetBadWords(ci))
if ((casesensitive && realword.equals_cs(bw->GetWord())) || (!casesensitive && realword.equals_ci(bw->GetWord())))
{
source.Reply(_("\002{0}\002 already exists in \002{1}\002 bad words list."), bw->GetWord(), ci->GetName());
return;
}
bool override = !source.AccessFor(ci).HasPriv("BADWORDS");
Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "ADD " << realword;
badwords->AddBadWord(ci, realword, bwtype);
source.Reply(_("\002{0}\002 added to \002{1}\002 bad words list."), realword, ci->GetName());
}
示例12: nickIsServices
/**
* Is the given nick a network service
* @param nick to check
* @param int Check if botserv bots
* @return int
*/
bool nickIsServices(const Anope::string &tempnick, bool bot)
{
if (tempnick.empty())
return false;
Anope::string nick = tempnick;
size_t at = nick.find('@');
if (at != Anope::string::npos)
{
Anope::string servername = nick.substr(at + 1);
if (!servername.equals_ci(Config->ServerName))
return false;
nick = nick.substr(0, at);
}
BotInfo *bi = findbot(nick);
if (bi)
return bot ? true : bi->HasFlag(BI_CORE);
return false;
}
示例13: IsValid
bool IsValid(const Anope::string &value) const
{
try
{
Anope::string rest;
if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty())
return true;
}
catch (const ConvertException &) { }
return false;
}
示例14:
void Message::Mode::Run(MessageSource &source, const std::vector<Anope::string> ¶ms)
{
Anope::string buf;
for (unsigned i = 1; i < params.size(); ++i)
buf += " " + params[i];
if (IRCD->IsChannelValid(params[0]))
{
Channel *c = Channel::Find(params[0]);
if (c)
c->SetModesInternal(source, buf.substr(1), 0);
}
else
{
User *u = User::Find(params[0]);
if (u)
u->SetModesInternal(source, "%s", buf.substr(1).c_str());
}
}
示例15: DoDel
void DoDel(CommandSource &source, NickServ::Account *nc, const Anope::string &chans)
{
std::vector<AutoJoin *> channels = nc->GetRefs<AutoJoin *>();
Anope::string delchans;
Anope::string notfoundchans;
commasepstream sep(chans);
for (Anope::string chan; sep.GetToken(chan);)
{
unsigned i = 0;
for (; i < channels.size(); ++i)
if (channels[i]->GetChannel().equals_ci(chan))
break;
if (i == channels.size())
notfoundchans += chan + ", ";
else
{
delete channels[i];
delchans += chan + ", ";
}
}
if (!notfoundchans.empty())
{
notfoundchans = notfoundchans.substr(0, notfoundchans.length() - 2);
source.Reply(_("\002{0}\002 was not found on the auto join list of \002{1}\002."), notfoundchans, nc->GetDisplay());
}
if (delchans.empty())
return;
delchans = delchans.substr(0, delchans.length() - 2);
Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to DELETE channel " << delchans << " from " << nc->GetDisplay();
source.Reply(_("\002{0}\002 was removed from the auto join list of \002{1}\002."), delchans, nc->GetDisplay());
}