LibC: Implement posix regex
This is an almost complete implementation, it does not support alternations or collating elements and it is restricted to the ASCII character set
This commit is contained in:
@@ -10,9 +10,47 @@ __BEGIN_DECLS
|
||||
#define __need_size_t
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
_re_literal,
|
||||
_re_group,
|
||||
_re_anchor_begin,
|
||||
_re_anchor_end,
|
||||
_re_group_tag1,
|
||||
_re_group_tag2,
|
||||
} _regex_elem_e;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int min;
|
||||
int max;
|
||||
} _regex_qualifier_t;
|
||||
|
||||
typedef struct _regex_elem_t
|
||||
{
|
||||
_regex_elem_e type;
|
||||
_regex_qualifier_t qualifier;
|
||||
union
|
||||
{
|
||||
uint32_t literal[0x100 / 32];
|
||||
size_t group_tag;
|
||||
struct {
|
||||
struct _regex_elem_t* elements;
|
||||
size_t elements_len;
|
||||
size_t index;
|
||||
} group;
|
||||
} as;
|
||||
} _regex_elem_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t re_nsub;
|
||||
_regex_elem_t* _compiled;
|
||||
size_t _compiled_len;
|
||||
int _cflags;
|
||||
} regex_t;
|
||||
|
||||
typedef __PTRDIFF_TYPE__ regoff_t;
|
||||
@@ -23,30 +61,31 @@ typedef struct
|
||||
regoff_t rm_eo; /* Byte offset from start of string of the first character after the end of substring. */
|
||||
} regmatch_t;
|
||||
|
||||
#define REG_EXTENDED 0x01
|
||||
#define REG_ICASE 0x02
|
||||
#define REG_NOSUB 0x04
|
||||
#define REG_NEWLINE 0x80
|
||||
#define REG_EXTENDED 0x1
|
||||
#define REG_ICASE 0x2
|
||||
#define REG_NOSUB 0x4
|
||||
#define REG_NEWLINE 0x8
|
||||
|
||||
#define REG_NOTBOL 0x0001
|
||||
#define REG_NOTEOL 0x0002
|
||||
#define REG_NOMATCH 0x0004
|
||||
#define REG_BADPAT 0x0008
|
||||
#define REG_ECOLLATE 0x0010
|
||||
#define REG_ECTYPE 0x0020
|
||||
#define REG_EESCAPE 0x0040
|
||||
#define REG_ESUBREG 0x0080
|
||||
#define REG_EBRACK 0x0100
|
||||
#define REG_EPAREN 0x0200
|
||||
#define REG_EBRACE 0x0400
|
||||
#define REG_BADBR 0x0800
|
||||
#define REG_ERANGE 0x1000
|
||||
#define REG_ESPACE 0x2000
|
||||
#define REG_BADRPT 0x4000
|
||||
#define REG_NOTBOL 0x1
|
||||
#define REG_NOTEOL 0x2
|
||||
|
||||
#define REG_NOMATCH 1
|
||||
#define REG_BADPAT 2
|
||||
#define REG_ECOLLATE 3
|
||||
#define REG_ECTYPE 4
|
||||
#define REG_EESCAPE 5
|
||||
#define REG_ESUBREG 6
|
||||
#define REG_EBRACK 7
|
||||
#define REG_EPAREN 8
|
||||
#define REG_EBRACE 9
|
||||
#define REG_BADBR 10
|
||||
#define REG_ERANGE 11
|
||||
#define REG_ESPACE 12
|
||||
#define REG_BADRPT 13
|
||||
|
||||
int regcomp(regex_t* __restrict preg, const char* __restrict pattern, int cflags);
|
||||
size_t regerror(int errcode, const regex_t* __restrict preg, char* __restrict errbuf, size_t errbuf_size);
|
||||
int regexec(const regex_t* __restrict preg, const char* __restrict string, size_t nmatch, regmatch_t pmatch[__restrict], int eflags);
|
||||
int regexec(const regex_t* __restrict preg, const char* __restrict string, size_t nmatch, regmatch_t pmatch[], int eflags);
|
||||
void regfree(regex_t* preg);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
Reference in New Issue
Block a user