1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
16 const char *OSPcre2_Execute(const char *str, OSPcre2 *reg)
18 /* Check for references not initialized */
20 reg->error = OS_REGEX_STR_NULL;
24 return reg->exec_function(str, reg);
27 const char *OSPcre2_Execute_pcre2_match(const char *str, OSPcre2 *reg)
29 int rc = 0, nbs = 0, i = 0;
30 PCRE2_SIZE *ov = NULL;
34 rc = pcre2_jit_match(reg->regex, (PCRE2_SPTR)str, strlen(str), 0, 0, reg->match_data, NULL);
36 rc = pcre2_match(reg->regex, (PCRE2_SPTR)str, strlen(str), 0, 0, reg->match_data, NULL);
39 /* Check execution result */
44 /* get the offsets informations for the match */
45 ov = pcre2_get_ovector_pointer(reg->match_data);
47 /* get the substrings if required */
48 for (i = 1; i < rc; i++) {
49 PCRE2_SIZE sub_string_start = ov[2 * i];
50 PCRE2_SIZE sub_string_end = ov[2 * i + 1];
51 PCRE2_SIZE sub_string_len = sub_string_end - sub_string_start;
52 if (sub_string_end > sub_string_start) {
53 reg->sub_strings[nbs] = (char *)calloc(sub_string_len + 1, sizeof(char));
54 strncpy(reg->sub_strings[nbs], &str[sub_string_start], sub_string_len);
58 reg->sub_strings[nbs] = NULL;
63 const char *OSPcre2_Execute_strcmp(const char *subject, OSPcre2 *reg)
65 if (!strcmp(reg->pattern, subject)) {
66 return &subject[reg->pattern_len];
71 const char *OSPcre2_Execute_strncmp(const char *subject, OSPcre2 *reg)
73 if (!strncmp(reg->pattern, subject, reg->pattern_len)) {
74 return &subject[reg->pattern_len];
79 const char *OSPcre2_Execute_strrcmp(const char *subject, OSPcre2 *reg)
81 size_t len = strlen(subject);
82 if (len >= reg->pattern_len && !strcmp(reg->pattern, &subject[len - reg->pattern_len])) {
88 const char *OSPcre2_Execute_strcasecmp(const char *subject, OSPcre2 *reg)
90 if (!strcasecmp(reg->pattern, subject)) {
91 return &subject[reg->pattern_len];
96 const char *OSPcre2_Execute_strncasecmp(const char *subject, OSPcre2 *reg)
98 if (!strncasecmp(reg->pattern, subject, reg->pattern_len)) {
99 return &subject[reg->pattern_len];
104 const char *OSPcre2_Execute_strrcasecmp(const char *subject, OSPcre2 *reg)
106 size_t len = strlen(subject);
107 if (len >= reg->pattern_len &&
108 !strcasecmp(reg->pattern, &subject[len - reg->pattern_len])) {
109 return &subject[len];