The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
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
12
typedef
ssize_t
regoff_t
;
13
14
/** a compiled expression (the layout is musl's) */
15
typedef
struct
re_pattern_buffer
16
{
17
size_t
re_nsub
;
// the parenthesised parts
18
void
*
__opaque
;
19
void
*
__padding
[4];
20
size_t
__nsub2
;
21
char
__padding2
;
22
}
regex_t
;
23
24
/** where a match (or a part of it) starts and ends; -1 when it did not match */
25
typedef
struct
26
{
27
regoff_t
rm_so
;
28
regoff_t
rm_eo
;
29
}
regmatch_t
;
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 */
59
int
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
*/
64
int
regexec
(
const
regex_t
*restrict preg,
const
char
*restrict text,
size_t
nmatch,
65
regmatch_t
*restrict pmatch,
int
eflags
);
66
void
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
*/
71
size_t
regerror
(
int
error
,
const
regex_t
*restrict preg,
char
*restrict buffer,
size_t
size);
eflags
uint32_t eflags
Definition
gdt.c:9
error
uint32_t error
Definition
isr.h:3
stddef.h
NULL, size_t, ptrdiff_t, offsetof.
regex_t
struct re_pattern_buffer regex_t
a compiled expression (the layout is musl's)
regerror
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).
regoff_t
ssize_t regoff_t
Definition
regex.h:12
regexec
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.
regcomp
int regcomp(regex_t *restrict preg, const char *restrict pattern, int cflags)
compile pattern into preg: REG_OK, or an error for regerror
regfree
void regfree(regex_t *preg)
re_pattern_buffer
a compiled expression (the layout is musl's)
Definition
regex.h:16
re_pattern_buffer::__padding
void * __padding[4]
Definition
regex.h:19
re_pattern_buffer::re_nsub
size_t re_nsub
Definition
regex.h:17
re_pattern_buffer::__nsub2
size_t __nsub2
Definition
regex.h:20
re_pattern_buffer::__padding2
char __padding2
Definition
regex.h:21
re_pattern_buffer::__opaque
void * __opaque
Definition
regex.h:18
regmatch_t
where a match (or a part of it) starts and ends; -1 when it did not match
Definition
regex.h:26
regmatch_t::rm_eo
regoff_t rm_eo
Definition
regex.h:28
regmatch_t::rm_so
regoff_t rm_so
Definition
regex.h:27
types.h
basic system types.
ssize_t
__PTRDIFF_TYPE__ ssize_t
Definition
types.h:15
src
libc
include
regex.h
Generated by
1.18.0