sbgECom Library  5.6.2730-stable
Interface SBG Systems IMU/AHRS/INS
Loading...
Searching...
No Matches
tinyRegex.h
1/*
2 *
3 * Mini regex-module inspired by Rob Pike's regex code described in:
4 *
5 * http://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html
6 *
7 *
8 *
9 * Supports:
10 * ---------
11 * '.' Dot, matches any character
12 * '^' Start anchor, matches beginning of string
13 * '$' End anchor, matches end of string
14 * '*' Asterisk, match zero or more (greedy)
15 * '+' Plus, match one or more (greedy)
16 * '?' Question, match zero or one (non-greedy)
17 * '[abc]' Character class, match if one of {'a', 'b', 'c'}
18 * '[^abc]' Inverted class, match if NOT one of {'a', 'b', 'c'} -- NOTE: feature is currently broken!
19 * '[a-zA-Z]' Character ranges, the character set of the ranges { a-z | A-Z }
20 * '\s' Whitespace, \t \f \r \n \v and spaces
21 * '\S' Non-whitespace
22 * '\w' Alphanumeric, [a-zA-Z0-9_]
23 * '\W' Non-alphanumeric
24 * '\d' Digits, [0-9]
25 * '\D' Non-digits
26 *
27 *
28 */
29
30#ifndef _TINY_REGEX_C
31#define _TINY_REGEX_C
32
33#include <sbgCommon.h>
34
35//----------------------------------------------------------------------//
36//- Header (open extern C block) -//
37//----------------------------------------------------------------------//
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42//----------------------------------------------------------------------//
43//- Public definitions -//
44//----------------------------------------------------------------------//
45
49#ifndef RE_DOT_MATCHES_NEWLINE
50 #define RE_DOT_MATCHES_NEWLINE 1
51#endif
52
56#define MAX_REGEXP_OBJECTS 30
57
61#define MAX_CHAR_CLASS_LEN 40
62
66typedef struct _sbgRegexItem
67{
68 unsigned char type; /* CHAR, STAR, etc. */
69 union
70 {
71 unsigned char ch; /* the character itself */
72 unsigned char* ccl; /* OR a pointer to characters in class */
73 } u;
74} sbgRegexItem;
75
79typedef struct _SbgRegex
80{
81 sbgRegexItem re_compiled[MAX_REGEXP_OBJECTS];
82 unsigned char ccl_buf[MAX_CHAR_CLASS_LEN];
83} SbgRegex;
84
85//----------------------------------------------------------------------//
86//- Public methods -//
87//----------------------------------------------------------------------//
88
98SBG_COMMON_LIB_API bool sbgRegexCompile(SbgRegex *pRegex, const char *pPattern);
99
105SBG_COMMON_LIB_API void sbgRegexPrint(const SbgRegex *pRegex);
106
116SBG_COMMON_LIB_API int32_t sbgRegexMatchp(const SbgRegex *pRegex, const char *pText, size_t *pMatchLength);
117
127SBG_COMMON_LIB_API int32_t sbgRegexMatch(const char *pPattern, const char *pText, size_t *pMatchLength);
128
129//----------------------------------------------------------------------//
130//- Footer (close extern C block) -//
131//----------------------------------------------------------------------//
132#ifdef __cplusplus
133}
134#endif
135
136#endif // _TINY_REGEX_C
Main header for the SBG Systems common C library.
#define SBG_COMMON_LIB_API
Definition sbgDefines.h:79
Definition tinyRegex.h:80
sbgRegexItem re_compiled[MAX_REGEXP_OBJECTS]
Definition tinyRegex.h:81
unsigned char ccl_buf[MAX_CHAR_CLASS_LEN]
Definition tinyRegex.h:82
Definition tinyRegex.h:67