ReactOS 0.4.17-dev-301-g9127a53
regexp.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  RECapture
 
struct  match_state_t
 
struct  regexp_t
 

Macros

#define REG_FOLD   0x01 /* fold uppercase to lowercase */
 
#define REG_GLOB   0x02 /* global exec, creates array of matches */
 
#define REG_MULTILINE   0x04 /* treat ^ and $ as begin and end of line */
 
#define REG_STICKY   0x08 /* only match starting at lastIndex */
 

Typedefs

typedef struct RECapture RECapture
 
typedef struct match_state_t match_state_t
 
typedef BYTE jsbytecode
 
typedef struct regexp_t regexp_t
 

Functions

regexp_tregexp_new (void *, heap_pool_t *, const WCHAR *, DWORD, WORD, BOOL)
 
void regexp_destroy (regexp_t *)
 
HRESULT regexp_execute (regexp_t *, void *, heap_pool_t *, const WCHAR *, DWORD, match_state_t *)
 
static match_state_talloc_match_state (regexp_t *regexp, heap_pool_t *pool, const WCHAR *pos)
 

Macro Definition Documentation

◆ REG_FOLD

#define REG_FOLD   0x01 /* fold uppercase to lowercase */

Definition at line 36 of file regexp.h.

◆ REG_GLOB

#define REG_GLOB   0x02 /* global exec, creates array of matches */

Definition at line 37 of file regexp.h.

◆ REG_MULTILINE

#define REG_MULTILINE   0x04 /* treat ^ and $ as begin and end of line */

Definition at line 38 of file regexp.h.

◆ REG_STICKY

#define REG_STICKY   0x08 /* only match starting at lastIndex */

Definition at line 39 of file regexp.h.

Typedef Documentation

◆ jsbytecode

typedef BYTE jsbytecode

Definition at line 54 of file regexp.h.

◆ match_state_t

◆ RECapture

◆ regexp_t

Function Documentation

◆ alloc_match_state()

static match_state_t * alloc_match_state ( regexp_t regexp,
heap_pool_t pool,
const WCHAR pos 
)
inlinestatic

Definition at line 71 of file regexp.h.

73{
74 size_t size = offsetof(match_state_t, parens) + regexp->parenCount*sizeof(RECapture);
76
78 if(!ret)
79 return NULL;
80
81 ret->cp = pos;
82 return ret;
83}
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
struct RECapture RECapture
return ret
Definition: mutex.c:146
GLsizeiptr size
Definition: glext.h:5919
void * heap_pool_alloc(heap_pool_t *, DWORD) __WINE_ALLOC_SIZE(2)
Definition: jsutils.c:72
#define offsetof(TYPE, MEMBER)
size_t parenCount
Definition: regexp.h:58

Referenced by RegExp2_Execute(), RegExp2_Test(), regexp_match(), regexp_match_next(), regexp_string_match(), and run_exec().

◆ regexp_destroy()

void regexp_destroy ( regexp_t re)

Definition at line 3177 of file regexp.c.

3178{
3179 if (re->classList) {
3180 UINT i;
3181 for (i = 0; i < re->classCount; i++) {
3182 if (re->classList[i].converted)
3183 free(re->classList[i].u.bits);
3184 re->classList[i].u.bits = NULL;
3185 }
3186 free(re->classList);
3187 }
3188 free(re);
3189}
#define free
Definition: debug_ros.c:5
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
struct RECharSet * classList
Definition: regexp.h:60
size_t classCount
Definition: regexp.h:59

◆ regexp_execute()

HRESULT regexp_execute ( regexp_t regexp,
void cx,
heap_pool_t pool,
const WCHAR str,
DWORD  str_len,
match_state_t result 
)

Definition at line 3136 of file regexp.c.

3138{
3140 REGlobalData gData;
3142 const WCHAR *str_beg = result->cp;
3143 HRESULT hres;
3144
3145 assert(result->cp != NULL);
3146
3147 gData.cpbegin = str;
3148 gData.cpend = str+str_len;
3149 gData.start = result->cp-str;
3150 gData.skipped = 0;
3151 gData.pool = pool;
3152
3153 hres = InitMatch(regexp, cx, pool, &gData);
3154 if(FAILED(hres)) {
3155 WARN("InitMatch failed\n");
3156 heap_pool_clear(mark);
3157 return hres;
3158 }
3159
3160 res = MatchRegExp(&gData, result);
3161 heap_pool_clear(mark);
3162 if(!gData.ok) {
3163 WARN("MatchRegExp failed\n");
3164 return E_FAIL;
3165 }
3166
3167 if(!res) {
3168 result->match_len = 0;
3169 return S_FALSE;
3170 }
3171
3172 result->match_len = (result->cp-str_beg) - gData.skipped;
3173 result->paren_count = regexp->parenCount;
3174 return S_OK;
3175}
#define WARN(fmt,...)
Definition: precomp.h:61
#define E_FAIL
Definition: ddrawi.h:102
#define assert(_expr)
Definition: assert.h:32
GLuint res
Definition: glext.h:9613
GLuint64EXT * result
Definition: glext.h:11304
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
static HRESULT InitMatch(regexp_t *re, void *cx, heap_pool_t *pool, REGlobalData *gData)
Definition: regexp.c:3097
static match_state_t * MatchRegExp(REGlobalData *gData, match_state_t *x)
Definition: regexp.c:3070
void heap_pool_clear(heap_pool_t *)
Definition: jsutils.c:141
heap_pool_t * heap_pool_mark(heap_pool_t *)
Definition: jsutils.c:177
HRESULT hres
Definition: protocol.c:465
short WCHAR
Definition: pedump.c:58
_Out_opt_ int * cx
Definition: commctrl.h:585
const WCHAR * str
size_t start
Definition: regexp.c:236
const WCHAR * cpbegin
Definition: regexp.c:238
const WCHAR * cpend
Definition: regexp.c:239
BOOL ok
Definition: regexp.c:235
heap_pool_t * pool
Definition: regexp.c:252
ptrdiff_t skipped
Definition: regexp.c:237
#define str_len
Definition: treelist.c:89
#define S_FALSE
Definition: winerror.h:3451

◆ regexp_new()

regexp_t * regexp_new ( void cx,
heap_pool_t pool,
const WCHAR str,
DWORD  str_len,
WORD  flags,
BOOL  flat 
)

Definition at line 3191 of file regexp.c.

3193{
3194 regexp_t *re;
3195 heap_pool_t *mark;
3197 size_t resize;
3198 jsbytecode *endPC;
3199 UINT i;
3200 size_t len;
3201
3202 re = NULL;
3203 mark = heap_pool_mark(pool);
3204 len = str_len;
3205
3206 state.context = cx;
3207 state.pool = pool;
3208 state.cp = str;
3209 if (!state.cp)
3210 goto out;
3211 state.cpbegin = state.cp;
3212 state.cpend = state.cp + len;
3213 state.flags = flags;
3214 state.parenCount = 0;
3215 state.classCount = 0;
3216 state.progLength = 0;
3217 state.treeDepth = 0;
3218 state.classBitmapsMem = 0;
3219 for (i = 0; i < CLASS_CACHE_SIZE; i++)
3220 state.classCache[i].start = NULL;
3221
3222 if (len != 0 && flat) {
3223 state.result = NewRENode(&state, REOP_FLAT);
3224 if (!state.result)
3225 goto out;
3226 state.result->u.flat.chr = *state.cpbegin;
3227 state.result->u.flat.length = len;
3228 state.result->kid = (void *) state.cpbegin;
3229 /* Flat bytecode: REOP_FLAT compact(string_offset) compact(len). */
3230 state.progLength += 1 + GetCompactIndexWidth(0)
3232 } else {
3233 if (!ParseRegExp(&state))
3234 goto out;
3235 }
3236 resize = offsetof(regexp_t, program) + state.progLength + 1;
3237 re = malloc(resize);
3238 if (!re)
3239 goto out;
3240
3241 assert(state.classBitmapsMem <= CLASS_BITMAPS_MEM_LIMIT);
3242 re->classCount = state.classCount;
3243 if (re->classCount) {
3244 re->classList = malloc(re->classCount * sizeof(RECharSet));
3245 if (!re->classList) {
3246 regexp_destroy(re);
3247 re = NULL;
3248 goto out;
3249 }
3250 for (i = 0; i < re->classCount; i++)
3251 re->classList[i].converted = FALSE;
3252 } else {
3253 re->classList = NULL;
3254 }
3255 endPC = EmitREBytecode(&state, re, state.treeDepth, re->program, state.result);
3256 if (!endPC) {
3257 regexp_destroy(re);
3258 re = NULL;
3259 goto out;
3260 }
3261 *endPC++ = REOP_END;
3262 /*
3263 * Check whether size was overestimated and shrink using realloc.
3264 * This is safe since no pointers to newly parsed regexp or its parts
3265 * besides re exist here.
3266 */
3267 if ((size_t)(endPC - re->program) != state.progLength + 1) {
3268 regexp_t *tmp;
3269 assert((size_t)(endPC - re->program) < state.progLength + 1);
3270 resize = offsetof(regexp_t, program) + (endPC - re->program);
3271 tmp = realloc(re, resize);
3272 if (tmp)
3273 re = tmp;
3274 }
3275
3276 re->flags = flags;
3277 re->parenCount = state.parenCount;
3278 re->source = str;
3279 re->source_len = str_len;
3280
3281out:
3282 heap_pool_clear(mark);
3283 return re;
3284}
static int state
Definition: maze.c:121
#define realloc
Definition: debug_ros.c:6
#define FALSE
Definition: types.h:117
BYTE jsbytecode
Definition: regexp.h:54
GLuint program
Definition: glext.h:6723
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
static size_t GetCompactIndexWidth(size_t index)
Definition: regexp.c:361
static BOOL ParseRegExp(CompilerState *)
Definition: regexp.c:1648
static jsbytecode * EmitREBytecode(CompilerState *state, regexp_t *re, size_t treeDepth, jsbytecode *pc, RENode *t)
Definition: regexp.c:473
#define CLASS_BITMAPS_MEM_LIMIT
Definition: regexp.c:351
void regexp_destroy(regexp_t *re)
Definition: regexp.c:3177
@ REOP_END
Definition: regexp.c:141
@ REOP_FLAT
Definition: regexp.c:106
#define CLASS_CACHE_SIZE
Definition: regexp.c:290
static RENode * NewRENode(CompilerState *state, REOp op)
Definition: regexp.c:407
if(dx< 0)
Definition: linetemp.h:194
jsbytecode program[1]
Definition: regexp.h:63
const WCHAR * source
Definition: regexp.h:61
DWORD source_len
Definition: regexp.h:62
WORD flags
Definition: regexp.h:57
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383