本文整理汇总了C++中anope::string::length方法的典型用法代码示例。如果您正苦于以下问题:C++ string::length方法的具体用法?C++ string::length怎么用?C++ string::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anope::string
的用法示例。
在下文中一共展示了string::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 "/";
}
示例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: IsValidIdent
/** Checks if a username is valid
* @param ident The username
* @return true if the ident is valid
*/
bool IsValidIdent(const Anope::string &ident)
{
if (ident.empty() || ident.length() > Config->UserLen)
return false;
for (unsigned i = 0; i < ident.length(); ++i)
{
const char &c = ident[i];
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-')
;
else
return false;
}
return true;
}
示例4: 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;
}
示例5: OnEncrypt
EventReturn OnEncrypt(const Anope::string &src, Anope::string &dest) override
{
if (!md5)
return EVENT_CONTINUE;
Encryption::Context *context = md5->CreateContext();
context->Update(reinterpret_cast<const unsigned char *>(src.c_str()), src.length());
context->Finalize();
Encryption::Hash hash = context->GetFinalizedHash();
char digest[32], digest2[16];
memset(digest, 0, sizeof(digest));
if (hash.second > sizeof(digest))
throw CoreException("Hash too large");
memcpy(digest, hash.first, hash.second);
for (int i = 0; i < 32; i += 2)
digest2[i / 2] = XTOI(digest[i]) << 4 | XTOI(digest[i + 1]);
Anope::string buf = "oldmd5:" + Anope::Hex(digest2, sizeof(digest2));
Log(LOG_DEBUG_2) << "(enc_old) hashed password from [" << src << "] to [" << buf << "]";
dest = buf;
delete context;
return EVENT_ALLOW;
}
示例6: IsIdentValid
bool IRCDProto::IsIdentValid(const Anope::string &ident)
{
if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
return false;
for (unsigned int i = 0; i < ident.length(); ++i)
{
const char &c = ident[i];
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-')
continue;
return false;
}
return true;
}
示例7: myNumToken
/**
* Number of tokens in a string
* @param str String
* @param dilim Dilimiter
* @return number of tokens
*/
int myNumToken(const Anope::string &str, char dilim)
{
if (str.empty())
return 0;
int counter = 0;
for (size_t idx = 0, len = str.length(); idx <= len; ++idx)
if (str[idx] == dilim || idx == len)
++counter;
return counter;
}
示例8: IsChannelValid
bool IRCDProto::IsChannelValid(const Anope::string &chan)
{
if (chan.empty() || chan[0] != '#' || chan.length() > Config->GetBlock("networkinfo")->Get<unsigned>("chanlen"))
return false;
if (chan.find_first_of(" ,") != Anope::string::npos)
return false;
return true;
}
示例9: SendMessage
void User::SendMessage(const MessageSource &source, const Anope::string &msg)
{
const char *translated_message = Language::Translate(this, msg.c_str());
/* Send privmsg instead of notice if:
* - UsePrivmsg is enabled
* - The user is not registered and NSDefMsg is enabled
* - The user is registered and has set /ns set msg on
*/
bool send_privmsg = Config->UsePrivmsg && ((!this->nc && Config->DefPrivmsg) || (this->nc && this->nc->HasFieldS("MSG")));
sepstream sep(translated_message, '\n', true);
for (Anope::string tok; sep.GetToken(tok);)
{
if (tok.empty())
tok = " ";
spacesepstream ssep(tok, true);
Anope::string buf;
for (Anope::string word; ssep.GetToken(word);)
{
Anope::string add = buf.empty() ? word : " " + word;
if (buf.length() + add.length() > Config->LineWrap)
{
if (send_privmsg)
IRCD->SendPrivmsg(source, this->GetUID(), "%s", buf.c_str());
else
IRCD->SendNotice(source, this->GetUID(), "%s", buf.c_str());
buf.clear();
add = word;
}
buf.append(add);
}
if (!buf.empty())
{
if (send_privmsg)
IRCD->SendPrivmsg(source, this->GetUID(), "%s", buf.c_str());
else
IRCD->SendNotice(source, this->GetUID(), "%s", buf.c_str());
}
}
}
示例10: Unhex
void Anope::Unhex(const Anope::string &src, char *dest)
{
size_t len = src.length(), destpos = 0;
for (size_t i = 0; i < len; i += 2)
{
char h = src[i], l = src[i + 1];
unsigned char byte = (h >= 'a' ? h - 'a' + 10 : h - '0') << 4;
byte += (l >= 'a' ? l - 'a' + 10 : l - '0');
dest[destpos++] = byte;
}
dest[destpos] = 0;
}
示例11: run
int LDAPBind::run()
{
berval cred;
cred.bv_val = strdup(pass.c_str());
cred.bv_len = pass.length();
int i = ldap_sasl_bind_s(service->GetConnection(), who.c_str(), LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL);
free(cred.bv_val);
return i;
}
示例12: IsValidHost
/** Checks if a host is valid
* @param host The host
* @param true if the host is valid
*/
bool IsValidHost(const Anope::string &host)
{
if (host.empty() || host.length() > Config->HostLen)
return false;
if (Config->VhostDisallowBE.find_first_of(host[0]) != Anope::string::npos)
return false;
else if (Config->VhostDisallowBE.find_first_of(host[host.length() - 1]) != Anope::string::npos)
return false;
int dots = 0;
for (unsigned i = 0; i < host.length(); ++i)
{
if (host[i] == '.')
++dots;
if (Config->VhostChars.find_first_of(host[i]) == Anope::string::npos)
return false;
}
return Config->VhostUndotted || dots > 0;
}
示例13: SendSyntax
void Command::SendSyntax(CommandSource &source)
{
Anope::string s = Language::Translate(source.GetAccount(), _("Syntax"));
if (!this->syntax.empty())
{
source.Reply("%s: \002%s %s\002", s.c_str(), source.command.c_str(), Language::Translate(source.GetAccount(), this->syntax[0].c_str()));
Anope::string spaces(s.length(), ' ');
for (unsigned i = 1, j = this->syntax.size(); i < j; ++i)
source.Reply("%s \002%s %s\002", spaces.c_str(), source.command.c_str(), Language::Translate(source.GetAccount(), this->syntax[i].c_str()));
}
else
source.Reply("%s: \002%s\002", s.c_str(), source.command.c_str());
}
示例14: IsIdentValid
bool IsIdentValid(const Anope::string &ident) override
{
if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen"))
return false;
Anope::string chars = "~}|{ `_^]\\[ .-$";
for (unsigned i = 0; i < ident.length(); ++i)
{
const char &c = ident[i];
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))
continue;
if (chars.find(c) != Anope::string::npos)
continue;
return false;
}
return true;
}
示例15: DoChannel
void DoChannel(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request)
{
if (request.data.empty())
return;
Channel *c = Channel::Find(request.data[0]);
request.reply("name", iface->Sanitize(c ? c->name : request.data[0]));
if (c)
{
request.reply("bancount", stringify(c->HasMode("BAN")));
int count = 0;
std::vector<Anope::string> v = c->GetModeList("BAN");
for (unsigned int i = 0; i < v.size(); ++i)
request.reply("ban" + stringify(++count), iface->Sanitize(v[i]));
request.reply("exceptcount", stringify(c->HasMode("EXCEPT")));
count = 0;
v = c->GetModeList("EXCEPT");
for (unsigned int i = 0; i < v.size(); ++i)
request.reply("except" + stringify(++count), iface->Sanitize(v[i]));
request.reply("invitecount", stringify(c->HasMode("INVITEOVERRIDE")));
count = 0;
v = c->GetModeList("INVITEOVERRIDE");
for (unsigned int i = 0; i < v.size(); ++i)
request.reply("invite" + stringify(++count), iface->Sanitize(v[i]));
Anope::string users;
for (Channel::ChanUserList::const_iterator it = c->users.begin(); it != c->users.end(); ++it)
{
ChanUserContainer *uc = it->second;
users += uc->status.BuildModePrefixList() + uc->user->nick + " ";
}
if (!users.empty())
{
users.erase(users.length() - 1);
request.reply("users", iface->Sanitize(users));
}
if (!c->topic.empty())
request.reply("topic", iface->Sanitize(c->topic));
if (!c->topic_setter.empty())
request.reply("topicsetter", iface->Sanitize(c->topic_setter));
request.reply("topictime", stringify(c->topic_time));
request.reply("topicts", stringify(c->topic_ts));
}
}