当前位置: 首页>>代码示例>>C++>>正文


C++ pcre_study函数代码示例

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


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


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