本文整理汇总了C++中rxx类的典型用法代码示例。如果您正苦于以下问题:C++ rxx类的具体用法?C++ rxx怎么用?C++ rxx使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了rxx类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split
int
split (vec<str> *out, rxx pat, str expr, size_t lim, bool emptylast)
{
const char *p = expr;
const char *const e = p + expr.len ();
size_t n;
if (out)
out->clear ();
// check p < e to see that we're not dealing with an empty
// string (especially since x? matches "").
for (n = 0; p < e && n + 1 < lim; n++) {
if (!pat._exec (p, e - p, 0)) {
return 0;
}
if (!pat.success ())
break;
if (out)
out->push_back (str (p, pat.start (0)));
p += max (pat.end (0), 1);
}
if (lim && (p < e || emptylast)) {
n++;
if (out) {
out->push_back (str (p, e - p));
}
}
return n;
}
示例2: collect_pound_def
static void
collect_pound_def (str s)
{
static rxx x ("#\\s*define\\s*(\\S+)\\s+(.*)");
if (guess_defines && x.match (s)) {
collect_constant (x[1], "RPC_CONSTANT_POUND_DEF");
}
}
示例3: is_builtin
static bool
is_builtin(const str &s)
{
static rxx x ("(((unsigned|long|const)\\s+)*|(u_?)?)"
"(bool|char|int|short|quad|long|"
"int(8|16|32|64)_t)");
return x.match (s);
}
示例4: main
int
main (int argc, const char *argv[])
{
if (argc < 2)
return -1;
str parent, filename;
parentpath (parent, filename, str (argv[1]));
warn << parent << "\n";
warn << filename << "\n";
return 0;
vec<str> out;
splitpath (out, argv[1]);
str foo;
while (out.size () > 0 && (foo = out.pop_front ()))
warn << foo << "\n";
return 0;
str path (argv[1]);
// vec<str> out;
static rxx r ("^(.*)/([^/]+)$");
// static rxx r ("^/*([^/]+)(/.*)?$");
// static rxx r ("^s%/[^/]*$%%");
// static rxx pathsplit ("^/*([^/]+)(/.*)?$");
warn << "path: " << path << "\n";
// path = path/r;
if (r.search (path))
{
if (r.len(1) != -1)
warn << r[1] << " -> ";
if (r.len(2) != -1)
warn << r[2] << "\n";
warn << "r[0]: " << r[0] << "\n";
}
warn << split (&out, "/", path) << "\n";
for (unsigned int i=0; i< out.size(); i++)
warn << out[i] << "\n";
return 0;
}
示例5: str
void
repl_el_capture_t::output (strbuf &out, const char *s, rxx &x)
{
int start = x.start (_i);
int ln = x.len (_i);
if (start >= 0 && ln > 0) {
str repl = str (s + start, ln);
strbuf_output (out, repl);
}
}
示例6: grouphostrx
bool
sfsgroupmgr::parsegroup (str group, str *gname, str *ghost)
{
static rxx grouphostrx ("([A-Za-z][\\-\\w\\.]{0,31})(@[A-Za-z].+)?");
if (!grouphostrx.match (group)) {
warn << "Could not parse group[@host]: " << group << "\n";
return false;
}
*gname = grouphostrx[1];
*ghost = grouphostrx[2] ? grouphostrx[2].cstr () : "-";
return true;
}
示例7: extract_matches
static void
extract_matches (vec<str> *out, const char *base, rxx &x)
{
bool go = true;
for (int i = 0; go; i++) {
int ln = x.len (i);
int start = x.start (i);
if (ln < 0 || start < 0) { go = false; }
else if (ln > 0) { out->push_back (str (base + start, ln)); }
}
}
示例8: is_safe
bool
is_safe (const str &d)
{
if (!d || d[0] == '.' || d[d.len () - 1] == '.' || safe_rxx.search (d))
return false;
return true;
}
示例9: parse_hn
bool
parse_hn (const str &in, str *host, int *port)
{
static rxx host_port_rxx ("([.0-9A-Za-z_-]*)(:[0-9]+)?");
if (!host_port_rxx.match (in))
return false;
str h = host_port_rxx[1];
if (h && h.len () > 0 && h != "-")
*host = h;
str p = host_port_rxx[2];
if (p && p.len () > 1) {
const char *pc = p.cstr () + 1;
p = pc;
if (!convertint (p, port))
return false;
}
return true;
}
示例10:
bool
cgi_mpfd_t::match (const http_inhdr_t &hdr, str *bndry)
{
if (multipart_rxx.match (hdr["content-type"])) {
*bndry = multipart_rxx[1];
return true;
}
return false;
}
示例11: rxx_replace_2
str
rxx_replace_2 (str input, rxx pat, str repl_str)
{
repl_t repl;
str ret;
if (!repl.parse (repl_str)) {
warn << "XX cannot parse replacement string: " << repl_str << "\n";
} else {
const char *p = input;
const char *const e = p + input.len ();
strbuf b;
bool go = true;
bool err = false;
// check p < e to see that we're not dealing with an empty
// string (especially since x? matches "").
while (go && !err && p < e) {
if (!pat._exec (p, e - p, 0)) {
warn << "XX regex execution failed\n";
err = true;
}
else if (!pat.success ()) { go = false; }
else {
str pre = str (p, pat.start (0));
strbuf_output (b, pre);
repl.output (b, p, pat);
p += max (pat.end (0), 1);
}
}
if (p < e && !err) {
str post = str (p, e - p);
strbuf_output (b, post);
}
if (!err) { ret = b; }
}
return ret;
}
示例12: rxx_replace
// Call the replace function for each matched pattern.
str
rxx_replace (str input, rxx pat, rxx_replace_cb_t cb)
{
const char *p = input;
const char *const e = p + input.len ();
strbuf b;
bool go = true;
bool err = false;
str ret;
// check p < e to see that we're not dealing with an empty
// string (especially since x? matches "").
while (go && !err && p < e) {
if (!pat._exec (p, e - p, 0)) {
warn << "XX regex execution failed\n";
err = true;
}
else if (!pat.success ()) { go = false; }
else {
str pre = str (p, pat.start (0));
strbuf_output (b, pre);
vec<str> v;
extract_matches (&v, p, pat);
str repl = (*cb) (&v);
if (repl) {
strbuf_output (b, repl);
}
p += max (pat.end (0), 1);
}
}
if (p < e && !err) {
str post = str (p, e - p);
strbuf_output (b, post);
}
if (!err) { ret = b; }
return ret;
}
示例13: sockfdre
int
agentconn::cagent_fd (bool required)
{
if (agentfd >= 0)
return agentfd;
static rxx sockfdre ("^-(\\d+)?$");
if (agentsock && sockfdre.search (agentsock)) {
if (sockfdre[1])
agentfd = atoi (sockfdre[1]);
else
agentfd = 0;
if (!isunixsocket (agentfd))
fatal << "fd specified with '-S' not unix domain socket\n";
}
else if (agentsock) {
agentfd = unixsocket_connect (agentsock);
if (agentfd < 0 && required)
fatal ("%s: %m\n", agentsock.cstr ());
}
else if (ccd (false)) {
int32_t res;
if (clnt_stat err = ccd ()->scall (AGENT_GETAGENT, NULL, &res)) {
if (required)
fatal << "sfscd: " << err << "\n";
}
else if (res) {
if (required)
fatal << "connecting to agent via sfscd: " << strerror (res) << "\n";
}
else if ((agentfd = sfscdxprt->recvfd ()) < 0) {
fatal << "connecting to agent via sfscd: "
<< "could not get file descriptor\n";
}
}
else {
if (str sock = agent_usersock (true))
agentfd = unixsocket_connect (sock);
if (agentfd < 0 && required)
fatal << "sfscd not running and no standalone agent socket\n";
}
return agentfd;
}
示例14: pri2del
bool
pri2del (sfsauth_dbrec *dbrp, str aek)
{
static rxx userrx ("^USER:([^:])$");
static rxx grouprx ("^GROUP:([^:])$");
if (userrx.match (aek)) {
dbrp->set_type (SFSAUTH_DELUSER);
*dbrp->deleted = userrx[1];
}
else if (grouprx.match (aek)) {
dbrp->set_type (SFSAUTH_DELGROUP);
*dbrp->deleted = grouprx[1];
}
else {
dbrp->set_type (SFSAUTH_ERROR);
*dbrp->errmsg = strbuf () << "illegal deleted DB key " << aek;
return false;
}
return true;
}
示例15: aekey
str
aekey (const sfsauth_dbrec &ae)
{
switch (ae.type) {
case SFSAUTH_USER:
return strbuf () << "USER:" << ae.userinfo->name;
case SFSAUTH_GROUP:
return strbuf () << "GROUP:" << ae.groupinfo->name;
case SFSAUTH_CACHEENTRY:
return strbuf () << "CACHE:" << ae.cacheentry->key;
default:
{
static rxx knrx ("^[^:]*:[^:]*");
str astr = authdbrec2str (&ae);
if (!astr)
return NULL;
if (!knrx.search (astr))
panic << "missing colon: " << astr << "\n";
return knrx[0];
}
}
}