The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
regex.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file regex.h
5 * @brief POSIX regular expressions, basic (BRE) and extended (ERE). The
6 * matcher is musl's (from TRE): see src/libc/src/regex/README.md.
7 */
8
9#include <stddef.h>
10#include <sys/types.h>
11
13
14/** a compiled expression (the layout is musl's) */
15typedef struct re_pattern_buffer
16{
17 size_t re_nsub; // the parenthesised parts
18 void *__opaque;
19 void *__padding[4];
20 size_t __nsub2;
23
24/** where a match (or a part of it) starts and ends; -1 when it did not match */
25typedef struct
26{
30
31// regcomp flags
32#define REG_EXTENDED 1 // extended syntax (ERE), not basic
33#define REG_ICASE 2 // upper and lower case match each other
34#define REG_NEWLINE 4 // a newline ends a line for ^, $ and .
35#define REG_NOSUB 8 // only if it matches, not where
36
37// regexec flags
38#define REG_NOTBOL 1 // the text does not start a line
39#define REG_NOTEOL 2 // the text does not end a line
40
41// results
42#define REG_OK 0
43#define REG_NOMATCH 1
44#define REG_BADPAT 2
45#define REG_ECOLLATE 3
46#define REG_ECTYPE 4
47#define REG_EESCAPE 5
48#define REG_ESUBREG 6
49#define REG_EBRACK 7
50#define REG_EPAREN 8
51#define REG_EBRACE 9
52#define REG_BADBR 10
53#define REG_ERANGE 11
54#define REG_ESPACE 12
55#define REG_BADRPT 13
56#define REG_ENOSYS -1
57
58/** compile pattern into preg: REG_OK, or an error for regerror */
59int regcomp(regex_t *restrict preg, const char *restrict pattern, int cflags);
60/**
61 * match text against preg: REG_OK or REG_NOMATCH. pmatch gets where the
62 * match and the first nmatch - 1 parts are.
63 */
64int regexec(const regex_t *restrict preg, const char *restrict text, size_t nmatch,
65 regmatch_t *restrict pmatch, int eflags);
66void regfree(regex_t *preg);
67/**
68 * the message for an error into buffer (size bytes, cut if it is longer).
69 * @return the size the whole message needs, with its null byte.
70 */
71size_t regerror(int error, const regex_t *restrict preg, char *restrict buffer, size_t size);
uint32_t eflags
Definition gdt.c:9
uint32_t error
Definition isr.h:3
NULL, size_t, ptrdiff_t, offsetof.
struct re_pattern_buffer regex_t
a compiled expression (the layout is musl's)
size_t regerror(int error, const regex_t *restrict preg, char *restrict buffer, size_t size)
the message for an error into buffer (size bytes, cut if it is longer).
ssize_t regoff_t
Definition regex.h:12
int regexec(const regex_t *restrict preg, const char *restrict text, size_t nmatch, regmatch_t *restrict pmatch, int eflags)
match text against preg: REG_OK or REG_NOMATCH.
int regcomp(regex_t *restrict preg, const char *restrict pattern, int cflags)
compile pattern into preg: REG_OK, or an error for regerror
void regfree(regex_t *preg)
a compiled expression (the layout is musl's)
Definition regex.h:16
void * __padding[4]
Definition regex.h:19
size_t re_nsub
Definition regex.h:17
size_t __nsub2
Definition regex.h:20
char __padding2
Definition regex.h:21
void * __opaque
Definition regex.h:18
where a match (or a part of it) starts and ends; -1 when it did not match
Definition regex.h:26
regoff_t rm_eo
Definition regex.h:28
regoff_t rm_so
Definition regex.h:27
basic system types.
__PTRDIFF_TYPE__ ssize_t
Definition types.h:15