mirror of
https://github.com/fluencelabs/musl
synced 2025-05-07 04:52:14 +00:00
the main practical results of this change are 1. the regex code is no longer subject to LGPL; it's now 2-clause BSD 2. most (all?) popular nonstandard regex extensions are supported I hesitate to call this a "sync" since both the old and new code are heavily modified. in one sense, the old code was "more severely" modified, in that it was actively hostile to non-strictly-conforming expressions. on the other hand, the new code has eliminated the useless translation of the entire regex string to wchar_t prior to compiling, and now only converts multibyte character literals as needed. in the future i may use this modified TRE as a basis for writing the long-planned new regex engine that will avoid multibyte-to-wide character conversion entirely by compiling multibyte bracket expressions specific to UTF-8.
36 lines
880 B
C
36 lines
880 B
C
#include <string.h>
|
|
#include <regex.h>
|
|
#include <stdio.h>
|
|
|
|
/* Error message strings for error codes listed in `regex.h'. This list
|
|
needs to be in sync with the codes listed there, naturally. */
|
|
|
|
/* Converted to single string by Rich Felker to remove the need for
|
|
* data relocations at runtime, 27 Feb 2006. */
|
|
|
|
static const char messages[] = {
|
|
"No error\0"
|
|
"No match\0"
|
|
"Invalid regexp\0"
|
|
"Unknown collating element\0"
|
|
"Unknown character class name\0"
|
|
"Trailing backslash\0"
|
|
"Invalid back reference\0"
|
|
"Missing ']'\0"
|
|
"Missing ')'\0"
|
|
"Missing '}'\0"
|
|
"Invalid contents of {}\0"
|
|
"Invalid character range\0"
|
|
"Out of memory\0"
|
|
"XXX\0"
|
|
"\0Unknown error"
|
|
};
|
|
|
|
size_t regerror(int e, const regex_t *preg, char *buf, size_t size)
|
|
{
|
|
const char *s;
|
|
for (s=messages; e && *s; e--, e+=strlen(s)+1);
|
|
if (!*s) s++;
|
|
return 1+snprintf(buf, size, "%s", s);
|
|
}
|