本文整理汇总了C++中pcre_get_substring函数的典型用法代码示例。如果您正苦于以下问题:C++ pcre_get_substring函数的具体用法?C++ pcre_get_substring怎么用?C++ pcre_get_substring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pcre_get_substring函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Download_file
void TGielda::Refresh_data_onet()
{
/* FIXME: jesli spolka, umarla ( jej cena to --- ) to nie zostanie
* to sparsowane poprawnie i pominieta zostanie kolejna spolka
* now blad - onet chyba teraz pokazuje cene w "[]", trzeba poprawic regexp
*/
char* bufor = NULL;
pcre* re;
const char* error = NULL;
int erroffset;
int index = 0;
int rc;
const int OVECCOUNT = 30;
int ovector[OVECCOUNT];
char* pozycja;
bufor = Download_file(curl, "http://gielda.onet.pl/indeksy-i-akcje,18633,100,0,notowania-gpw-start");
my_companies.clear();
my_companies.reserve(512);
do
{
re = pcre_compile("<div class=\"name2\"><a.*?>(.*?)<.*?raitings.*?>\\s*?\\[?([-0-9, ]+)\\]?\\s*?<.*?raitings.*?>\\s*?\\[?([-0-9,]+)\\]?\\s*?<",
PCRE_DOTALL, &error, &erroffset, NULL);
rc = pcre_exec(re, NULL, bufor + index, strlen(bufor + index), 0, 0, ovector,
OVECCOUNT);
if (rc == PCRE_ERROR_NOMATCH)
break;
if (rc < 0)
break;
if (rc == 0)
puts("za malo miejsca w buforze");
char* name;
char* price;
char* day_delta;
pcre_get_substring(bufor + index, ovector, rc, 1, (const char** )&name);
pcre_get_substring(bufor + index, ovector, rc, 2, (const char** )&price);
pcre_get_substring(bufor + index, ovector, rc, 3, (const char** )&day_delta);
if ((pozycja = strchr(day_delta, ',')))
*pozycja = '.';
if ((pozycja = strchr(price, ',')))
*pozycja = '.';
char* price_replaced = Replace_all(price, " ", "");
TSpolka spolka(name,
price_replaced ? price_replaced : price,
day_delta, "", "", "", "", "");
my_companies.push_back(spolka);
pcre_free_substring(name);
pcre_free_substring(price);
pcre_free_substring(day_delta);
index += ovector[1];
}
while (true);
my_last_update = time(NULL);
delete[] bufor;
}
示例2: DetectPayloadLenFieldParse
static int DetectPayloadLenFieldParse(DetectPayloadLenFieldData *dt, const char * sig) {
char *args[3] = {NULL,NULL,NULL};
#define MAX_SUBSTRINGS 30
int ret = 0, res = 0;
int ov[MAX_SUBSTRINGS];
dt->offset = 0;
ret = pcre_exec(parse_regex, parse_regex_study, sig, strlen(sig), 0, 0, ov, MAX_SUBSTRINGS);
if (ret < 3) goto error;
const char *str_ptr;
pcre_get_substring(sig, ov, MAX_SUBSTRINGS, 1, &str_ptr);
if (strlen(str_ptr)) {
dt->offset = atoi(str_ptr);
}
pcre_get_substring(sig, ov, MAX_SUBSTRINGS, 2, &str_ptr);
if (strlen(str_ptr)) {
dt->len = atoi(str_ptr);
}
return 1;
error:
return -1;
}
示例3: ccze_squid_cache_log_process
static char *
ccze_squid_cache_log_process (const char *str, int *offsets, int match)
{
char *date, *other;
pcre_get_substring (str, offsets, match, 1, (const char **)&date);
pcre_get_substring (str, offsets, match, 3, (const char **)&other);
ccze_addstr (CCZE_COLOR_DATE, date);
ccze_space();
free (date);
return other;
}
示例4: DetectPrioritySetup
static int DetectPrioritySetup (DetectEngineCtx *de_ctx, Signature *s, char *rawstr)
{
const char *prio_str = NULL;
#define MAX_SUBSTRINGS 30
int ret = 0;
int ov[MAX_SUBSTRINGS];
ret = pcre_exec(regex, regex_study, rawstr, strlen(rawstr), 0, 0, ov, 30);
if (ret < 0) {
SCLogError(SC_ERR_PCRE_MATCH, "Invalid Priority in Signature "
"- %s", rawstr);
return -1;
}
ret = pcre_get_substring((char *)rawstr, ov, 30, 1, &prio_str);
if (ret < 0) {
SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
return -1;
}
/* if we have reached here, we have had a valid priority. Assign it */
s->prio = atoi(prio_str);
return 0;
}
示例5: extractHTTPClientHeaderVal
// < 0 for error. >= 0 for len of extracted string
int extractHTTPClientHeaderVal(const u_int8_t *buf, u_int32_t size, int pcreidx, int substringnum, char *valuebuf, int valuelen) {
int result;
int ovector[9];
int ovecsize = 9;
const char *tmpstring;
// printf("Searching for pcre %d (%s)\n", pcreidx, http_pcre_strings[pcreidx]);
result = pcre_exec(http_pcre_structs[pcreidx].re, http_pcre_structs[pcreidx].pe,
(const char *)buf, size, 0, 0, ovector, ovecsize);
if(result < 0 || result == PCRE_ERROR_NOMATCH) {
// printf("pcre not found\n");
return(-1); // We need to find the URL or this isn't a valid request
}
if(valuebuf) {
result = pcre_get_substring((const char *)buf, ovector, result, substringnum, &tmpstring);
if(result < 0) {
// printf("unable to extract substring\n");
return(-2);
}
strncpy(valuebuf, tmpstring, valuelen);
valuebuf[valuelen-1] = '\0';
pcre_free_substring(tmpstring);
return(strlen(valuebuf));
}
return(0);
}
示例6: pcre_exec
char *Regexp_Get_Substring_From_Buffer(pcre *regexp, char *buffer, int substring)
{
char *file;
int rc, ovector[30];
char *viewstate;
if (regexp == NULL)
return NULL;
if (buffer == NULL)
return NULL;
rc = pcre_exec(regexp, NULL, buffer, strlen(file), 0, 0, ovector, 30);
if (rc != -1)
{
rc = pcre_get_substring(buffer, ovector, 30, substring, (const char **)&viewstate);
if (rc != -1)
{
return viewstate;
}
else
printf("Get_Regexp_From_File: could not get substring.\n");
}
else
printf("Get_Regexp_From_File: regexp didnt match.\n");
return NULL;
}
示例7: pcre_get_substring
std::string Pattern::group (int groupNumber)
{
const char * stringPtr;
int rc = pcre_get_substring (
_subject.substr (_offset[0]).c_str(),
_ovector,
_count,
groupNumber,
&stringPtr);
if (rc < 0) {
switch (rc) {
case PCRE_ERROR_NOSUBSTRING:
throw std::out_of_range ("Invalid group reference.");
case PCRE_ERROR_NOMEMORY:
throw match_error ("Memory exhausted.");
default:
throw match_error ("Failed to get named substring.");
}
}
std::string matchedStr (stringPtr);
pcre_free_substring (stringPtr);
return matchedStr;
}
示例8: nvmRegExpCoproTestPattern
static uint32_t nvmRegExpCoproTestPattern (uint16_t pattern_id, uint8_t *haystack, uint32_t haylen,
uint32_t start_offset, nvmRegExpCoproInternalData *redata) {
nvmRegExpCoproPattern *rcp;
int ovector[OVECTSIZE], m = 0, matchoffset = 0; //, matchlen = 0;
#ifdef COPRO_REGEXP_DEBUG
const char *tmp;
#endif
redata -> matched = 0;
/* Do the actual search */
if (pattern_id < redata -> patterns_no) {
rcp = &(redata -> patterns[pattern_id]);
redebug ("Looking for RegExp: \"%s\"\n", rcp -> pattern);
m = pcre_exec (rcp -> re, rcp -> re_extra, (char*) haystack + start_offset, haylen, 0, 0, ovector, OVECTSIZE);
if (m > 0) {
(redata -> match).rcp = rcp;
(redata -> match).offset = matchoffset = ovector[0];
(redata -> match).len = ovector[1] - ovector[0];
redata -> matched = 1;
#ifdef COPRO_REGEXP_DEBUG
pcre_get_substring (haystack + start_offset, ovector, m, 0, &tmp);
redebug ("RegExp match at offset %d, len = %d: \"%s\"\n", matchoffset, (redata -> match).len, tmp);
pcre_free_substring (tmp);
#endif
}
} else {
printf ("RegExp coprocessor: tried to use inexistent pattern: %u\n", pattern_id);
}
return (redata -> matched);
}
示例9: pcre_compile
char *execute_regex(char *pattern, char *subject, int desired_match)
{
pcre *re;
const char *einfo;
int eoffset;
int stringcount = 0;
int ovector[desired_match * 3];
int match_len;
const char *match;
char *match_returned;
re = pcre_compile(pattern, 0, &einfo, &eoffset, NULL);
if (!re) {
fprintf(stderr, "%s\n", einfo);
return NULL;
}
stringcount = pcre_exec(re, NULL, subject, strlen(subject),
0, 0, ovector, 30);
match_len = pcre_get_substring(subject, ovector,
stringcount, desired_match, &match);
if (match_len <= 0) {
return NULL;
}
match_returned = (char *) malloc(match_len);
strncpy(match_returned, match, match_len);
pcre_free_substring(match);
return match_returned;
}
示例10: get_einvoice_recipient
/** Funkcja pobiera pierwszy czlon adresu email - tytulowy adresat w tresci maila
@param email - adres email z którego pobrany zostanie człon adresu przed znakiem '@'
@param out_recipient - nazwa konta email pobrana z adresu - wartość zwracana przez funkcję
@retval 0 - ok
@retval -1 - bład wywołania funkcji pcre_compile
@retval -2 - bład wywołania funkcji pcre_exec
*/
long get_einvoice_recipient(char *email,char **out_recipient)
{
pcre *rc = NULL;
long re = 0;
const char *error = NULL;
int erroroffset = 0;
int ovector[6];
long len = 0;
memset(ovector,0,6);
rc=pcre_compile(EINVOICE_RECP_REGEXP,0,&error, &erroroffset,NULL);
if(rc==NULL)
{
PRINT_DEBUG("LIBBMDMAILERR Error. Error=%i\n",-1);
return -1;
}
re = pcre_exec(rc,NULL,email,(int)strlen(email),0,0,ovector,6);
if(re<0)
{
PRINT_DEBUG("LIBBMDMAILERR Error. Error=%i\n",-2);
return -2;
}
len=pcre_get_substring(email,ovector,re,1,(const char **)out_recipient);
pcre_free(rc);
rc=NULL;
return 0;
}
示例11: pcre_exec
/**
* \brief This function is used to parse icmp_seq option passed via icmp_seq: keyword
*
* \param icmpseqstr Pointer to the user provided icmp_seq options
*
* \retval iseq pointer to DetectIcmpSeqData on success
* \retval NULL on failure
*/
DetectIcmpSeqData *DetectIcmpSeqParse (char *icmpseqstr) {
DetectIcmpSeqData *iseq = NULL;
char *substr[3] = {NULL, NULL, NULL};
#define MAX_SUBSTRINGS 30
int ret = 0, res = 0;
int ov[MAX_SUBSTRINGS];
int i;
const char *str_ptr;
ret = pcre_exec(parse_regex, parse_regex_study, icmpseqstr, strlen(icmpseqstr), 0, 0, ov, MAX_SUBSTRINGS);
if (ret < 1 || ret > 4) {
SCLogError(SC_ERR_PCRE_MATCH,"Parse error %s", icmpseqstr);
goto error;
}
for (i = 1; i < ret; i++) {
res = pcre_get_substring((char *)icmpseqstr, ov, MAX_SUBSTRINGS, i, &str_ptr);
if (res < 0) {
SCLogError(SC_ERR_PCRE_GET_SUBSTRING,"pcre_get_substring failed");
goto error;
}
substr[i-1] = (char *)str_ptr;
}
iseq = SCMalloc(sizeof(DetectIcmpSeqData));
if (iseq == NULL)
goto error;
iseq->seq = 0;
if (substr[0] != NULL && strlen(substr[0]) != 0) {
if (substr[2] == NULL) {
SCLogError(SC_ERR_MISSING_QUOTE,"Missing quote in input");
goto error;
}
} else {
if (substr[2] != NULL) {
SCLogError(SC_ERR_MISSING_QUOTE,"Missing quote in input");
goto error;
}
}
uint16_t seq = 0;
ByteExtractStringUint16(&seq, 10, 0, substr[1]);
iseq->seq = htons(seq);
for (i = 0; i < 3; i++) {
if (substr[i] != NULL) SCFree(substr[i]);
}
return iseq;
error:
for (i = 0; i < 3; i++) {
if (substr[i] != NULL) SCFree(substr[i]);
}
if (iseq != NULL) DetectIcmpSeqFree(iseq);
return NULL;
}
示例12: pcre_exec
/**
* \brief This function is used to parse icmp_id option passed via icmp_id: keyword
*
* \param icmpidstr Pointer to the user provided icmp_id options
*
* \retval iid pointer to DetectIcmpIdData on success
* \retval NULL on failure
*/
DetectIcmpIdData *DetectIcmpIdParse (char *icmpidstr) {
DetectIcmpIdData *iid = NULL;
char *substr[3] = {NULL, NULL, NULL};
#define MAX_SUBSTRINGS 30
int ret = 0, res = 0;
int ov[MAX_SUBSTRINGS];
ret = pcre_exec(parse_regex, parse_regex_study, icmpidstr, strlen(icmpidstr), 0, 0, ov, MAX_SUBSTRINGS);
if (ret < 1 || ret > 4) {
SCLogError(SC_ERR_PCRE_MATCH, "Parse error %s", icmpidstr);
goto error;
}
int i;
const char *str_ptr;
for (i = 1; i < ret; i++) {
res = pcre_get_substring((char *)icmpidstr, ov, MAX_SUBSTRINGS, i, &str_ptr);
if (res < 0) {
SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
goto error;
}
substr[i-1] = (char *)str_ptr;
}
iid = SCMalloc(sizeof(DetectIcmpIdData));
if (iid == NULL)
goto error;
iid->id = 0;
if (substr[0]!= NULL && strlen(substr[0]) != 0) {
if (substr[2] == NULL) {
SCLogError(SC_ERR_INVALID_ARGUMENT, "Missing close quote in input");
goto error;
}
} else {
if (substr[2] != NULL) {
SCLogError(SC_ERR_INVALID_ARGUMENT, "Missing open quote in input");
goto error;
}
}
/** \todo can ByteExtractStringUint16 do this? */
uint16_t id = 0;
ByteExtractStringUint16(&id, 10, 0, substr[1]);
iid->id = htons(id);
for (i = 0; i < 3; i++) {
if (substr[i] != NULL) SCFree(substr[i]);
}
return iid;
error:
for (i = 0; i < 3; i++) {
if (substr[i] != NULL) SCFree(substr[i]);
}
if (iid != NULL) DetectIcmpIdFree(iid);
return NULL;
}
示例13: pcre_get_named_substring
int
pcre_get_named_substring(const pcre *code, const pcre_char *subject, int *ovector,
int stringcount, const pcre_char *stringname, const pcre_char **stringptr)
{
int n = pcre_get_stringnumber(code, stringname);
if (n <= 0) return n;
return pcre_get_substring(subject, ovector, stringcount, n, stringptr);
}
示例14: pcre_get_named_substring
int
pcre_get_named_substring(const pcre *code, const char *subject, int *ovector,
int stringcount, const char *stringname, const char **stringptr)
{
int n = get_first_set(code, stringname, ovector);
if (n <= 0) return n;
return pcre_get_substring(subject, ovector, stringcount, n, stringptr);
}
示例15: regex_request_to_sub
/** Extract a subcapture value from the request
*
* @note This is the PCRE variant of the function.
*
* @param[in] ctx To allocate subcapture buffer in.
* @param[out] out Where to write the subcapture string.
* @param[in] request to extract.
* @param[in] num Subcapture index (0 for entire match).
* @return
* - 0 on success.
* - -1 on notfound.
*/
int regex_request_to_sub(TALLOC_CTX *ctx, char **out, REQUEST *request, uint32_t num)
{
fr_regcapture_t *rc;
char const *p;
int ret;
rc = request_data_reference(request, request, REQUEST_DATA_REGEX);
if (!rc) {
RDEBUG4("No subcapture data found");
*out = NULL;
return 1;
}
ret = pcre_get_substring(rc->regmatch->subject,
(int *)rc->regmatch->match_data, (int)rc->regmatch->used, num, &p);
switch (ret) {
case PCRE_ERROR_NOMEMORY:
MEM(NULL);
/*
* We can't really fall through, but GCC 7.3 is
* too stupid to realise that we can never get
* here despite _fr_exit_now being marked as
* NEVER_RETURNS.
*
* If we did anything else, compilers and static
* analysis tools would probably complain about
* code that could never be executed *sigh*.
*/
/* FALL-THROUGH */
/*
* Not finding a substring is fine
*/
case PCRE_ERROR_NOSUBSTRING:
RDEBUG4("%i/%zu Not found", num + 1, rc->regmatch->used);
*out = NULL;
return -1;
default:
if (ret < 0) {
*out = NULL;
return -1;
}
talloc_set_type(p, char);
p = talloc_steal(ctx, p);
RDEBUG4("%i/%zu Found: %pV (%zu)", num + 1, rc->regmatch->used,
fr_box_strvalue_buffer(p), talloc_array_length(p) - 1);
memcpy(out, &p, sizeof(*out));
break;
}
return 0;
}