ReactOS  0.4.14-dev-342-gdc047f9
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) DECLSPEC_HIDDEN
 
void regexp_destroy (regexp_t *) DECLSPEC_HIDDEN
 
HRESULT regexp_execute (regexp_t *, void *, heap_pool_t *, const WCHAR *, DWORD, match_state_t *) DECLSPEC_HIDDEN
 
HRESULT regexp_set_flags (regexp_t **, void *, heap_pool_t *, WORD) DECLSPEC_HIDDEN
 
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 72 of file regexp.h.

74 {
75  size_t size = offsetof(match_state_t, parens) + regexp->parenCount*sizeof(RECapture);
77 
79  if(!ret)
80  return NULL;
81 
82  ret->cp = pos;
83  return ret;
84 }
struct RECapture RECapture
void * heap_pool_alloc(heap_pool_t *, DWORD) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN
Definition: jsutils.c:77
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
size_t parenCount
Definition: regexp.h:58
smooth NULL
Definition: ftsmooth.c:416
#define offsetof(TYPE, MEMBER)
GLsizeiptr size
Definition: glext.h:5919
int ret

◆ regexp_destroy()

void regexp_destroy ( regexp_t )

Definition at line 3181 of file regexp.c.

3182 {
3183  if (re->classList) {
3184  UINT i;
3185  for (i = 0; i < re->classCount; i++) {
3186  if (re->classList[i].converted)
3187  heap_free(re->classList[i].u.bits);
3188  re->classList[i].u.bits = NULL;
3189  }
3190  heap_free(re->classList);
3191  }
3192  heap_free(re);
3193 }
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
smooth NULL
Definition: ftsmooth.c:416
unsigned int UINT
Definition: ndis.h:50
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by RegExp2_put_Pattern(), RegExp2_Release(), RegExp_destructor(), regexp_new(), and regexp_set_flags().

◆ regexp_execute()

HRESULT regexp_execute ( regexp_t ,
void ,
heap_pool_t ,
const WCHAR ,
DWORD  ,
match_state_t  
)

Definition at line 3140 of file regexp.c.

3142 {
3143  match_state_t *res;
3144  REGlobalData gData;
3145  heap_pool_t *mark = heap_pool_mark(pool);
3146  const WCHAR *str_beg = result->cp;
3147  HRESULT hres;
3148 
3149  assert(result->cp != NULL);
3150 
3151  gData.cpbegin = str;
3152  gData.cpend = str+str_len;
3153  gData.start = result->cp-str;
3154  gData.skipped = 0;
3155  gData.pool = pool;
3156 
3157  hres = InitMatch(regexp, cx, pool, &gData);
3158  if(FAILED(hres)) {
3159  WARN("InitMatch failed\n");
3160  heap_pool_clear(mark);
3161  return hres;
3162  }
3163 
3164  res = MatchRegExp(&gData, result);
3165  heap_pool_clear(mark);
3166  if(!gData.ok) {
3167  WARN("MatchRegExp failed\n");
3168  return E_FAIL;
3169  }
3170 
3171  if(!res) {
3172  result->match_len = 0;
3173  return S_FALSE;
3174  }
3175 
3176  result->match_len = (result->cp-str_beg) - gData.skipped;
3177  result->paren_count = regexp->parenCount;
3178  return S_OK;
3179 }
BOOL ok
Definition: regexp.c:237
const WCHAR * cpbegin
Definition: regexp.c:240
#define WARN(fmt,...)
Definition: debug.h:111
#define str_len
Definition: treelist.c:89
#define assert(x)
Definition: debug.h:53
#define E_FAIL
Definition: ddrawi.h:102
size_t start
Definition: regexp.c:238
#define S_FALSE
Definition: winerror.h:2357
const WCHAR * cpend
Definition: regexp.c:241
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
static match_state_t * MatchRegExp(REGlobalData *gData, match_state_t *x)
Definition: regexp.c:3073
HRESULT hres
Definition: protocol.c:465
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
ptrdiff_t skipped
Definition: regexp.c:239
#define S_OK
Definition: intsafe.h:59
_Out_opt_ int * cx
Definition: commctrl.h:581
GLuint res
Definition: glext.h:9613
static HRESULT InitMatch(regexp_t *re, void *cx, heap_pool_t *pool, REGlobalData *gData)
Definition: regexp.c:3100
heap_pool_t * heap_pool_mark(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:182
GLuint64EXT * result
Definition: glext.h:11304
heap_pool_t * pool
Definition: regexp.c:254
void heap_pool_clear(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:146

Referenced by do_regexp_match_next(), RegExp2_Execute(), and RegExp2_Test().

◆ regexp_new()

regexp_t* regexp_new ( void ,
heap_pool_t ,
const WCHAR ,
DWORD  ,
WORD  ,
BOOL   
)

Definition at line 3195 of file regexp.c.

3197 {
3198  regexp_t *re;
3199  heap_pool_t *mark;
3201  size_t resize;
3202  jsbytecode *endPC;
3203  UINT i;
3204  size_t len;
3205 
3206  re = NULL;
3207  mark = heap_pool_mark(pool);
3208  len = str_len;
3209 
3210  state.context = cx;
3211  state.pool = pool;
3212  state.cp = str;
3213  if (!state.cp)
3214  goto out;
3215  state.cpbegin = state.cp;
3216  state.cpend = state.cp + len;
3217  state.flags = flags;
3218  state.parenCount = 0;
3219  state.classCount = 0;
3220  state.progLength = 0;
3221  state.treeDepth = 0;
3222  state.classBitmapsMem = 0;
3223  for (i = 0; i < CLASS_CACHE_SIZE; i++)
3224  state.classCache[i].start = NULL;
3225 
3226  if (len != 0 && flat) {
3227  state.result = NewRENode(&state, REOP_FLAT);
3228  if (!state.result)
3229  goto out;
3230  state.result->u.flat.chr = *state.cpbegin;
3231  state.result->u.flat.length = len;
3232  state.result->kid = (void *) state.cpbegin;
3233  /* Flat bytecode: REOP_FLAT compact(string_offset) compact(len). */
3234  state.progLength += 1 + GetCompactIndexWidth(0)
3236  } else {
3237  if (!ParseRegExp(&state))
3238  goto out;
3239  }
3240  resize = offsetof(regexp_t, program) + state.progLength + 1;
3241  re = heap_alloc(resize);
3242  if (!re)
3243  goto out;
3244 
3245  assert(state.classBitmapsMem <= CLASS_BITMAPS_MEM_LIMIT);
3246  re->classCount = state.classCount;
3247  if (re->classCount) {
3248  re->classList = heap_alloc(re->classCount * sizeof(RECharSet));
3249  if (!re->classList) {
3250  regexp_destroy(re);
3251  re = NULL;
3252  goto out;
3253  }
3254  for (i = 0; i < re->classCount; i++)
3255  re->classList[i].converted = FALSE;
3256  } else {
3257  re->classList = NULL;
3258  }
3259  endPC = EmitREBytecode(&state, re, state.treeDepth, re->program, state.result);
3260  if (!endPC) {
3261  regexp_destroy(re);
3262  re = NULL;
3263  goto out;
3264  }
3265  *endPC++ = REOP_END;
3266  /*
3267  * Check whether size was overestimated and shrink using realloc.
3268  * This is safe since no pointers to newly parsed regexp or its parts
3269  * besides re exist here.
3270  */
3271  if ((size_t)(endPC - re->program) != state.progLength + 1) {
3272  regexp_t *tmp;
3273  assert((size_t)(endPC - re->program) < state.progLength + 1);
3274  resize = offsetof(regexp_t, program) + (endPC - re->program);
3275  tmp = heap_realloc(re, resize);
3276  if (tmp)
3277  re = tmp;
3278  }
3279 
3280  re->flags = flags;
3281  re->parenCount = state.parenCount;
3282  re->source = str;
3283  re->source_len = str_len;
3284 
3285 out:
3286  heap_pool_clear(mark);
3287  return re;
3288 }
void regexp_destroy(regexp_t *re)
Definition: regexp.c:3181
BYTE jsbytecode
Definition: regexp.h:54
static jsbytecode * EmitREBytecode(CompilerState *state, regexp_t *re, size_t treeDepth, jsbytecode *pc, RENode *t)
Definition: regexp.c:475
#define str_len
Definition: treelist.c:89
#define assert(x)
Definition: debug.h:53
WORD flags
Definition: regexp.h:57
DWORD source_len
Definition: regexp.h:62
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:70
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define CLASS_BITMAPS_MEM_LIMIT
Definition: regexp.c:353
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
size_t parenCount
Definition: regexp.h:58
#define CLASS_CACHE_SIZE
Definition: regexp.c:292
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
#define offsetof(TYPE, MEMBER)
if(!(yy_init))
Definition: macro.lex.yy.c:714
static FILE * out
Definition: regtests2xml.c:44
GLbitfield flags
Definition: glext.h:7161
jsbytecode program[1]
Definition: regexp.h:63
static int state
Definition: maze.c:121
const WCHAR * source
Definition: regexp.h:61
GLenum GLsizei len
Definition: glext.h:6722
static RENode * NewRENode(CompilerState *state, REOp op)
Definition: regexp.c:409
GLuint program
Definition: glext.h:6723
unsigned int UINT
Definition: ndis.h:50
_Out_opt_ int * cx
Definition: commctrl.h:581
static size_t GetCompactIndexWidth(size_t index)
Definition: regexp.c:363
static BOOL ParseRegExp(CompilerState *)
Definition: regexp.c:1651
heap_pool_t * heap_pool_mark(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:182
size_t classCount
Definition: regexp.h:59
struct RECharSet * classList
Definition: regexp.h:60
void heap_pool_clear(heap_pool_t *) DECLSPEC_HIDDEN
Definition: jsutils.c:146

Referenced by create_regexp(), RegExp2_Execute(), RegExp2_Test(), and regexp_set_flags().

◆ regexp_set_flags()

HRESULT regexp_set_flags ( regexp_t **  ,
void ,
heap_pool_t ,
WORD   
)

Definition at line 3290 of file regexp.c.

3291 {
3292  if(((*regexp)->flags & REG_FOLD) != (flags & REG_FOLD)) {
3293  regexp_t *new_regexp = regexp_new(cx, pool, (*regexp)->source,
3294  (*regexp)->source_len, flags, FALSE);
3295 
3296  if(!new_regexp)
3297  return E_FAIL;
3298 
3299  regexp_destroy(*regexp);
3300  *regexp = new_regexp;
3301  }else {
3302  (*regexp)->flags = flags;
3303  }
3304 
3305  return S_OK;
3306 }
void regexp_destroy(regexp_t *re)
Definition: regexp.c:3181
WORD flags
Definition: regexp.h:57
#define E_FAIL
Definition: ddrawi.h:102
#define REG_FOLD
Definition: regexp.h:36
regexp_t * regexp_new(void *cx, heap_pool_t *pool, const WCHAR *str, DWORD str_len, WORD flags, BOOL flat)
Definition: regexp.c:3195
GLbitfield flags
Definition: glext.h:7161
#define S_OK
Definition: intsafe.h:59
_Out_opt_ int * cx
Definition: commctrl.h:581

Referenced by RegExp2_Execute(), and RegExp2_Test().