diff --git a/lib/re1.5/charclass.c b/lib/re1.5/charclass.c index 7f6388c93d..2553b40530 100644 --- a/lib/re1.5/charclass.c +++ b/lib/re1.5/charclass.c @@ -6,7 +6,15 @@ int _re1_5_classmatch(const char *pc, const char *sp) int is_positive = (pc[-1] == Class); int cnt = *pc++; while (cnt--) { - if (*sp >= *pc && *sp <= pc[1]) return is_positive; + if (*pc == RE15_CLASS_NAMED_CLASS_INDICATOR) { + if (_re1_5_namedclassmatch(pc + 1, sp)) { + return is_positive; + } + } else { + if (*sp >= *pc && *sp <= pc[1]) { + return is_positive; + } + } pc += 2; } return !is_positive; diff --git a/lib/re1.5/compilecode.c b/lib/re1.5/compilecode.c index d4fc2a2895..513a155970 100644 --- a/lib/re1.5/compilecode.c +++ b/lib/re1.5/compilecode.c @@ -66,14 +66,21 @@ static const char *_compilecode(const char *re, ByteProg *prog, int sizecode) PC++; // Skip # of pair byte prog->len++; for (cnt = 0; *re != ']'; re++, cnt++) { - if (*re == '\\') { + char c = *re; + if (c == '\\') { ++re; + c = *re; + if (MATCH_NAMED_CLASS_CHAR(c)) { + c = RE15_CLASS_NAMED_CLASS_INDICATOR; + goto emit_char_pair; + } } - if (!*re) return NULL; - EMIT(PC++, *re); + if (!c) return NULL; if (re[1] == '-' && re[2] != ']') { re += 2; } + emit_char_pair: + EMIT(PC++, c); EMIT(PC++, *re); } EMIT_CHECKED(term + 1, cnt); diff --git a/lib/re1.5/re1.5.h b/lib/re1.5/re1.5.h index 81f43ed7f5..b1ec01cbc5 100644 --- a/lib/re1.5/re1.5.h +++ b/lib/re1.5/re1.5.h @@ -138,6 +138,7 @@ struct Subject { #define NON_ANCHORED_PREFIX 5 #define HANDLE_ANCHORED(bytecode, is_anchored) ((is_anchored) ? (bytecode) + NON_ANCHORED_PREFIX : (bytecode)) +#define RE15_CLASS_NAMED_CLASS_INDICATOR 0 int re1_5_backtrack(ByteProg*, Subject*, const char**, int, int); int re1_5_pikevm(ByteProg*, Subject*, const char**, int, int);