Browse Source

regexp: Import change from JimTcl.

* regexp/jimregexp.h, regexp/jimregexp.c: Fix from JimTcl.

--

Apply the change in JimTcl:

    commit ac35b8a6ec
    Author: Steve Bennett <steveb@workware.net.au>
    Date:   Mon May 4 20:43:46 2020 +1000

    regexp: Improved error message

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
cb/test
NIIBE Yutaka 11 months ago
parent
commit
91cb46d948
  1. 20
      regexp/jimregexp.c
  2. 3
      regexp/jimregexp.h

20
regexp/jimregexp.c

@ -723,7 +723,7 @@ static int regatom(regex_t *preg, int *flagp)
pattern++;
}
while (*pattern && *pattern != ']') {
while (*pattern != ']') {
/* Is this a range? a-z */
int start;
int end;
@ -735,6 +735,11 @@ static int regatom(regex_t *preg, int *flagp)
};
int cc;
if (!*pattern) {
preg->err = REG_ERR_UNMATCHED_BRACKET;
return 0;
}
pattern += reg_utf8_tounicode_case(pattern, &start, nocase);
if (start == '\\') {
/* First check for class shorthand escapes */
@ -758,6 +763,10 @@ static int regatom(regex_t *preg, int *flagp)
preg->err = REG_ERR_NULL_CHAR;
return 0;
}
if (start == '\\' && *pattern == 0) {
preg->err = REG_ERR_INVALID_ESCAPE;
return 0;
}
}
if (pattern[0] == '-' && pattern[1] && pattern[1] != ']') {
/* skip '-' */
@ -769,6 +778,10 @@ static int regatom(regex_t *preg, int *flagp)
preg->err = REG_ERR_NULL_CHAR;
return 0;
}
if (start == '\\' && *pattern == 0) {
preg->err = REG_ERR_INVALID_ESCAPE;
return 0;
}
}
reg_addrange(preg, start, end);
@ -873,7 +886,7 @@ cc_switch:
ch = *preg->regparse++;
switch (ch) {
case '\0':
preg->err = REG_ERR_TRAILING_BACKSLASH;
preg->err = REG_ERR_INVALID_ESCAPE;
return 0;
case 'A':
ret = regnode(preg, BOLX);
@ -1883,9 +1896,10 @@ size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_s
"nested count",
"internal error",
"count follows nothing",
"trailing backslash",
"invalid escape \\ sequence",
"corrupted program",
"contains null char",
"brackets [] not balanced",
};
const char *err;

3
regexp/jimregexp.h

@ -91,9 +91,10 @@ enum {
REG_ERR_NESTED_COUNT,
REG_ERR_INTERNAL,
REG_ERR_COUNT_FOLLOWS_NOTHING,
REG_ERR_TRAILING_BACKSLASH,
REG_ERR_INVALID_ESCAPE,
REG_ERR_CORRUPTED,
REG_ERR_NULL_CHAR,
REG_ERR_UNMATCHED_BRACKET,
REG_ERR_NUM
};

Loading…
Cancel
Save