• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pcre_study函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中pcre_study函数的典型用法代码示例。如果您正苦于以下问题:C++ pcre_study函数的具体用法?C++ pcre_study怎么用?C++ pcre_study使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pcre_study函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: compile_study

void compile_study(pcre **re, pcre_extra **re_extra, char *q, const int pcre_opts, const int study_opts) {
    const char *pcre_err = NULL;
    int pcre_err_offset = 0;

    *re = pcre_compile(q, pcre_opts, &pcre_err, &pcre_err_offset, NULL);
    if (*re == NULL) {
        die("pcre_compile failed at position %i. Error: %s", pcre_err_offset, pcre_err);
    }
    *re_extra = pcre_study(*re, study_opts, &pcre_err);
    if (*re_extra == NULL) {
        log_debug("pcre_study returned nothing useful. Error: %s", pcre_err);
    }
}
开发者ID:Sanne,项目名称:the_silver_searcher,代码行数:13,代码来源:util.c


示例2: fb_countmatches

/* Count all matches with pattern p in src buffer. */
static int fb_countmatches(fbuf_t *src, const char *p)
{
  pcre *re;
  pcre_extra *re_ex;
  const char *re_e;
  int re_eo, m[3], pos, count;
  if (!(re = pcre_compile(p, PCRE_CASELESS, &re_e, &re_eo, NULL))) exit(1);
  re_ex = pcre_study(re, 0, &re_e);
  for (count = 0, pos = 0;
       pcre_exec(re, re_ex, src->buf, src->len, pos, 0, m, 3) >= 0;
       pos = m[1]) count++;
  return count;
}
开发者ID:pgerakios,项目名称:Concurrent-Cyclone-with-inference,代码行数:14,代码来源:regex-dna.c


示例3: oilsAuthIdentIsBarcode

// returns true if the provided identifier matches the barcode regex.
static int oilsAuthIdentIsBarcode(const char* identifier, int org_id) {

    if (org_id < 1)
        org_id = oilsUtilsGetRootOrgId();

    char* bc_regex = oilsUtilsFetchOrgSetting(org_id, "opac.barcode_regex");

    if (!bc_regex) {
        // if no regex is set, assume any identifier starting
        // with a number is a barcode.
        bc_regex = strdup("^\\d"); // dupe for later free'ing
    }

    const char *err_str;
    int err_offset, match_ret;

    pcre *compiled = pcre_compile(
        bc_regex, 0, &err_str, &err_offset, NULL);

    if (compiled == NULL) {
        osrfLogError(OSRF_LOG_MARK,
            "Could not compile '%s': %s", bc_regex, err_str);
        free(bc_regex);
        pcre_free(compiled);
        return 0;
    }

    pcre_extra *extra = pcre_study(compiled, 0, &err_str);

    if(err_str != NULL) {
        osrfLogError(OSRF_LOG_MARK,
            "Could not study regex '%s': %s", bc_regex, err_str);
        free(bc_regex);
        pcre_free(compiled);
        return 0;
    } 

    match_ret = pcre_exec(
        compiled, extra, identifier, strlen(identifier), 0, 0, NULL, 0);       

    free(bc_regex);
    pcre_free(compiled);
    if (extra) pcre_free(extra);

    if (match_ret >= 0) return 1; // regex matched

    if (match_ret != PCRE_ERROR_NOMATCH) 
        osrfLogError(OSRF_LOG_MARK, "Unknown error processing barcode regex");

    return 0; // regex did not match
}
开发者ID:IISH,项目名称:Evergreen,代码行数:52,代码来源:oils_auth.c


示例4: compile_regex

static int compile_regex(struct saved_data *data, spec_t *spec, const char **errbuf)
{
	const char *tmperrbuf;
	char *reg_buf, *anchored_regex, *cp;
	stem_t *stem_arr = data->stem_arr;
	size_t len;
	int erroff;

	if (spec->regcomp)
		return 0; /* already done */

	data->ncomp++; /* how many compiled regexes required */

	/* Skip the fixed stem. */
	reg_buf = spec->regex_str;
	if (spec->stem_id >= 0)
		reg_buf += stem_arr[spec->stem_id].len;

	/* Anchor the regular expression. */
	len = strlen(reg_buf);
	cp = anchored_regex = (char *) malloc(len + 3);
	if (!anchored_regex)
		return -1;
	/* Create ^...$ regexp.  */
	*cp++ = '^';
	memcpy(cp, reg_buf, len);
	cp += len;
	*cp++ = '$';
	*cp = '\0';

	/* Compile the regular expression. */
	spec->regex = pcre_compile(anchored_regex, PCRE_DOTALL, &tmperrbuf, &erroff, NULL);
	free(anchored_regex);
	if (!spec->regex) {
		if (errbuf)
			*errbuf=tmperrbuf;
		return -1;
	}

	spec->sd = pcre_study(spec->regex, 0, &tmperrbuf);
	if (!spec->sd && tmperrbuf) {
		if (errbuf)
			*errbuf=tmperrbuf;
		return -1;
	}

	/* Done. */
	spec->regcomp = 1;

	return 0;
}
开发者ID:TheDauntless,项目名称:frida-core,代码行数:51,代码来源:label_file.c


示例5: ccze_xferlog_setup

static void
ccze_xferlog_setup (void)
{
  const char *error;
  int errptr;

  /* FIXME: Does not handle spaces in filenames! */
  reg_xferlog = pcre_compile
    ("^(... ... +\\d{1,2} +\\d{1,2}:\\d{1,2}:\\d{1,2} \\d+) (\\d+) ([^ ]+) "
     "(\\d+) (\\S+) (a|b) (C|U|T|_) (o|i) (a|g|r) ([^ ]+) ([^ ]+) " 
     "(0|1) ([^ ]+) (c|i)", 0, &error,
     &errptr, NULL);
  hints_xferlog = pcre_study (reg_xferlog, 0, &error);
}
开发者ID:AsherBond,项目名称:ccze,代码行数:14,代码来源:mod_xferlog.c


示例6: ccze_oops_setup

static void
ccze_oops_setup (void)
{
  const char *error;
  int errptr;

  reg_oops = pcre_compile
    ("^((Mon|Tue|Wed|Thu|Fri|Sat|Sun) "
     "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) "
     "\\d+ \\d+:\\d+:\\d+ \\d+)(\\s+)\\[([\\dxa-fA-F]+)\\]"
     "statistics\\(\\): ([\\S]+)(\\s*): (\\d+)(.*)",
     0, &error, &errptr, NULL);
  hints_oops = pcre_study (reg_oops, 0, &error);
}
开发者ID:AsherBond,项目名称:ccze,代码行数:14,代码来源:mod_oops.c


示例7: pcre_study_exp

pcre_extra * 
pcre_study_exp(pcre *re, int options)
{
	pcre_extra *extra;
	const char *err;

	if (re == NULL) {
		return NULL;
	}

	extra = pcre_study(re, options, &err);

	return extra;
}
开发者ID:shengxinking,项目名称:xxx,代码行数:14,代码来源:pcre_func.c


示例8: _pcre

RegularExpression::RegularExpression(const std::string& pattern, int options, bool study): _pcre(0), _extra(0)
{
	const char* error;
	int offs;
	_pcre = pcre_compile(pattern.c_str(), options, &error, &offs, 0);
	if (!_pcre)
	{
		std::ostringstream msg;
		msg << error << " (at offset " << offs << ")";
		throw RegularExpressionException(msg.str());
	}
	if (study)
		_extra = pcre_study(_pcre, 0, &error);
}
开发者ID:atinm,项目名称:xmlplus-0.2.2-lgpl,代码行数:14,代码来源:RegularExpression.cpp


示例9: mc_search__cond_struct_new_init_regex

void
mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * mc_search,
                                       mc_search_cond_t * mc_search_cond)
{
    GString *tmp = NULL;
#ifdef SEARCH_TYPE_GLIB
    GError *error = NULL;
#else /* SEARCH_TYPE_GLIB */
    const char *error;
    int erroffset;
#endif /* SEARCH_TYPE_GLIB */

    if (!mc_search->is_case_sentitive) {
        tmp = g_string_new_len (mc_search_cond->str->str, mc_search_cond->str->len);
        g_string_free (mc_search_cond->str, TRUE);
        mc_search_cond->str = mc_search__cond_struct_new_regex_ci_str (charset, tmp->str, tmp->len);
        g_string_free (tmp, TRUE);
    }
#ifdef SEARCH_TYPE_GLIB
    mc_search_cond->regex_handle =
        g_regex_new (mc_search_cond->str->str, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_DOTALL, 0,
                     &error);

    if (error != NULL) {
        mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
        mc_search->error_str = str_conv_gerror_message (error, _(" Regular expression error "));
        g_error_free (error);
        return;
    }
#else /* SEARCH_TYPE_GLIB */
    mc_search_cond->regex_handle =
        pcre_compile (mc_search_cond->str->str, PCRE_EXTRA, &error, &erroffset, NULL);
    if (mc_search_cond->regex_handle == NULL) {
        mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
        mc_search->error_str = g_strdup (error);
        return;
    }
    mc_search->regex_match_info = pcre_study (mc_search_cond->regex_handle, 0, &error);
    if (mc_search->regex_match_info == NULL) {
        if (error) {
            mc_search->error = MC_SEARCH_E_REGEX_COMPILE;
            mc_search->error_str = g_strdup (error);
            g_free (mc_search_cond->regex_handle);
            mc_search_cond->regex_handle = NULL;
            return;
        }
    }
#endif /* SEARCH_TYPE_GLIB */
}
开发者ID:sfionov,项目名称:mc-dev,代码行数:49,代码来源:regex.c


示例10: regex_comp

int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char **err)
{
    /* copy the original regex format */
    regex->regstr = strdup(str);
    if (!regex->regstr) {
        memprintf(err, "out of memory");
        return 0;
    }

#ifdef USE_PCRE_JIT
    int flags = 0;
    const char *error;
    int erroffset;

    if (!cs)
        flags |= PCRE_CASELESS;
    if (!cap)
        flags |= PCRE_NO_AUTO_CAPTURE;

    regex->reg = pcre_compile(str, flags, &error, &erroffset, NULL);
    if (!regex->reg) {
        free(regex->regstr);
        memprintf(err, "regex '%s' is invalid (error=%s, erroffset=%d)", str, error, erroffset);
        return 0;
    }

    regex->extra = pcre_study(regex->reg, PCRE_STUDY_JIT_COMPILE, &error);
    if (!regex->extra) {
        free(regex->regstr);
        pcre_free(regex->reg);
        memprintf(err, "failed to compile regex '%s' (error=%s)", str, error);
        return 0;
    }
#else
    int flags = REG_EXTENDED;

    if (!cs)
        flags |= REG_ICASE;
    if (!cap)
        flags |= REG_NOSUB;

    if (regcomp(&regex->regex, str, flags) != 0) {
        free(regex->regstr);
        memprintf(err, "regex '%s' is invalid", str);
        return 0;
    }
#endif
    return 1;
}
开发者ID:mross462,项目名称:haproxy,代码行数:49,代码来源:regex.c


示例11: Compile

bool RegExp::Study(bool restudy)
{
	if(!cpattern)
		Compile();
	if(study){
		if(restudy)
			pcre_free(study);
		else
			return true;
	}
	study = pcre_study(cpattern, 0, &error_string);
	if(error_string != NULL)
		error_code = -1; // unfortunatelly, pcre_study doesn't return error codes...
	return error_code == 0;
}
开发者ID:rfdiazpr,项目名称:upp-mirror,代码行数:15,代码来源:RegExp.cpp


示例12: ccze_squid_setup

static void
ccze_squid_setup (void)
{
  const char *error;
  int errptr;

  reg_squid_access = pcre_compile
    ("^(\\d{9,10}\\.\\d{3})(\\s+)(\\d+)\\s(\\S+)\\s(\\w+)\\/(\\d{3})"
     "\\s(\\d+)\\s(\\w+)\\s(\\S+)\\s(\\S+)\\s(\\w+)\\/([\\d\\.]+|-)\\s(.*)",
     0, &error, &errptr, NULL);
  hints_squid_access = pcre_study (reg_squid_access, 0, &error);

  reg_squid_cache = pcre_compile
    ("^(\\d{4}\\/\\d{2}\\/\\d{2}\\s(\\d{2}:){2}\\d{2}\\|)\\s(.*)$", 0,
     &error, &errptr, NULL);
  hints_squid_cache = pcre_study (reg_squid_cache, 0, &error);

  reg_squid_store = pcre_compile
    ("^([\\d\\.]+)\\s(\\w+)\\s(\\-?[\\dA-F]+)\\s+(\\S+)\\s([\\dA-F]+)"
     "(\\s+)(\\d{3}|\\?)(\\s+)(\\-?[\\d\\?]+)(\\s+)(\\-?[\\d\\?]+)(\\s+)"
     "(\\-?[\\d\\?]+)\\s(\\S+)\\s(\\-?[\\d|\\?]+)\\/(\\-?[\\d|\\?]+)\\s"
     "(\\S+)\\s(.*)", 0, &error, &errptr, NULL);
  hints_squid_store = pcre_study (reg_squid_store, 0, &error);
}
开发者ID:AsherBond,项目名称:ccze,代码行数:24,代码来源:mod_squid.c


示例13: AddInternalTrigger

// Internal triggers
static void AddInternalTrigger (char* regexpstr, unsigned mask, internal_trigger_func func)
{
	pcre_internal_trigger_t *trig;
	const char *error;
	int error_offset;
 
	trig = (pcre_internal_trigger_t *) Z_Malloc (sizeof(pcre_internal_trigger_t));
	trig->next = internal_triggers;
	internal_triggers = trig;
 
	trig->regexp = pcre_compile (regexpstr, 0, &error, &error_offset, NULL);
	trig->regexp_extra = pcre_study (trig->regexp, 0, &error);
	trig->func = func;
	trig->flags = mask;
}
开发者ID:jogi1,项目名称:camquake,代码行数:16,代码来源:tp_triggers.c


示例14: compile_study

void compile_study(pcre **re, pcre_extra **re_extra, char *q, const int pcre_opts, const int study_opts) {
    const char *pcre_err = NULL;
    int pcre_err_offset = 0;

    *re = pcre_compile(q, pcre_opts, &pcre_err, &pcre_err_offset, NULL);
    if (*re == NULL) {
        die("Bad regex! pcre_compile() failed at position %i: %s\nIf you meant to search for a literal string, run ag with -Q",
            pcre_err_offset,
            pcre_err);
    }
    *re_extra = pcre_study(*re, study_opts, &pcre_err);
    if (*re_extra == NULL) {
        log_debug("pcre_study returned nothing useful. Error: %s", pcre_err);
    }
}
开发者ID:TidyHuang,项目名称:DLP,代码行数:15,代码来源:util.c


示例15: pcre_compile_do

static int
pcre_compile_do(struct sol_flow_node *node,
    const char *regexp,
    pcre **compiled_re,
    pcre_extra **p_extra,
    int *sub_match_count)
{
    int r;
    int pcre_error_offset;
    const char *pcre_error_str = NULL;

    SOL_NULL_CHECK(compiled_re, -EINVAL);
    SOL_NULL_CHECK(p_extra, -EINVAL);
    SOL_NULL_CHECK(sub_match_count, -EINVAL);

    *compiled_re = NULL;
    *p_extra = NULL;
    *sub_match_count = 0;

    *compiled_re = pcre_compile(regexp, PCRE_UTF8,
        &pcre_error_str, &pcre_error_offset, NULL);
    if (!*compiled_re) {
        sol_flow_send_error_packet(node, EINVAL,
            "Could not compile '%s': %s", regexp, pcre_error_str);
        return -EINVAL;
    }

    r = pcre_fullinfo(*compiled_re, NULL, PCRE_INFO_CAPTURECOUNT,
        sub_match_count);
    if (r < 0) {
        sol_flow_send_error_packet(node, EINVAL, "Could not"
            "extract info from compiled regular expression %s", regexp);
        pcre_free(compiled_re);
        return -EINVAL;
    }

    //A null pcre_extra is fine (no optimization possible), errors are
    //reported on the last argument
    *p_extra = pcre_study(*compiled_re, 0, &pcre_error_str);
    if (pcre_error_str != NULL) {
        sol_flow_send_error_packet(node, EINVAL,
            "Error optimizing '%s': %s", regexp, pcre_error_str);
        pcre_free(compiled_re);
        return -EINVAL;
    }

    return 0;
}
开发者ID:ceolin,项目名称:soletta,代码行数:48,代码来源:string-regexp.c


示例16: re_compile

void re_compile(re *r, const char *s, int options)
{
	options |= PCRE_NO_AUTO_CAPTURE;
	options |= PCRE_NO_AUTO_POSSESS;
	int erroff;
	const char *err = NULL;
	r->re = pcre_compile(s, options, &err, &erroff, NULL);
	if (err != NULL)
		die("error at %d: %s", erroff, err);
	r->extra = pcre_study(r->re, PCRE_STUDY_JIT_COMPILE, &err);
	if (err != NULL)
		die("error at %d: %s", erroff, err);
	r->stack = pcre_jit_stack_alloc(32*1024, 1024*1024);
	if (r->stack == NULL)
		die_errno("%s", "compile: pcre_jit_stack_alloc failed");
}
开发者ID:lucy,项目名称:af,代码行数:16,代码来源:af.c


示例17: copy_invalidate_t

static invalidate_t *
copy_invalidate_t(invalidate_t *i)
{
  invalidate_t *iptr;
  const char *errptr;
  int erroffset;

  iptr = (invalidate_t *)TSmalloc(sizeof(invalidate_t));
  iptr->regex_text = TSstrdup(i->regex_text);
  iptr->regex = pcre_compile(iptr->regex_text, 0, &errptr, &erroffset, NULL); // There is no pcre_copy :-(
  iptr->regex_extra = pcre_study(iptr->regex, 0, &errptr);                    // Assuming no errors since this worked before :-/
  iptr->epoch = i->epoch;
  iptr->expiry = i->expiry;
  iptr->next = NULL;
  return iptr;
}
开发者ID:BillTheBest,项目名称:trafficserver,代码行数:16,代码来源:regex_revalidate.c


示例18: regex

template <typename Traits> inline void
branch<Traits>::add_regex_match(char const *pattern) {
	int error_offset = 0;
	char const *error_ptr = 0;
	resource<pcre*, pcre_traits> regex(pcre_compile(pattern, 0, &error_ptr, &error_offset, 0));
	if (!regex) {
		throw error("%s at %d in %s", error_ptr, error_offset, pattern);
	}
	resource<pcre_extra*, pcre_extra_traits> extra(pcre_study(regex.get(), PCRE_STUDY_JIT_COMPILE, &error_ptr));
	if (!extra) {
		throw error("%s in %s", error_ptr, pattern);
	}
	regex_matches_.push_back(std::make_pair(regex.get(), extra.get()));
	extra.release();
	regex.release();
}
开发者ID:zasimov,项目名称:uatraits,代码行数:16,代码来源:branch.hpp


示例19: regexp_copy

static EC_OBJ regexp_copy( EC_OBJ obj, EcCopyType type )
{
	pcre       *code;
	pcre_extra *extra;
	EC_OBJ      src, sobj;
	EC_OBJ      res;

	const char *old_str;
	EcInt       old_slen;
	int         old_options;

	const char *errptr  = NULL;
	int         erroffs = 0;

	/* compile a new regexp with the same string and options of the old one */
	src = EC_REGEXPSRC(obj);
	ASSERT( EC_ARRAYP(src) );
	ASSERT( EC_ARRAYLEN(src) == 2 );
	sobj = EcArrayGet( src, 0 );
	res  = EcArrayGet( src, 1 );
	ASSERT( EC_STRINGP(sobj) );
	ASSERT( EC_INUMP(res) );

	old_str     = EC_STRDATA(sobj);
	old_slen    = EC_STRLEN(sobj);
	old_options = EC_INUM(res);

	code = pcre_compile( old_str, old_options,
						 &errptr, &erroffs,
						 /* tableptr */ NULL );
	if (! code) return EcReError( errptr, erroffs );

	extra = NULL;
	if (EC_PCREXTRA(obj))
	{
		extra = pcre_study( code,
							0,									/* currently pcre has no options for study */
							&errptr );
		if (! extra) return EcReError( errptr, -1 );
	}

	return make_regexp( code, extra,
						old_str,
						old_slen,
						old_options );
}
开发者ID:BackupTheBerlios,项目名称:elastic-svn,代码行数:46,代码来源:re_m.c


示例20: ccze_exim_setup

static void
ccze_exim_setup (void)
{
  const char *error;
  int errptr;

  reg_exim = pcre_compile
    ("^(\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2})\\s(.*)$", 0,
     &error, &errptr, NULL);
  hints_exim = pcre_study (reg_exim, 0, &error);

  reg_exim_actiontype = pcre_compile
    ("^(\\S{16})\\s([<=\\*][=>\\*])\\s(\\S+.*)$", 0, &error,
     &errptr, NULL);
  reg_exim_uniqn = pcre_compile ("^(\\S{16})\\s(.*)$", 0, &error,
				 &errptr, NULL);
}
开发者ID:AsherBond,项目名称:ccze,代码行数:17,代码来源:mod_exim.c



注:本文中的pcre_study函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pcs_free函数代码示例发布时间:2022-05-30
下一篇:
C++ pcre_get_substring函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap