jscript: Separate flags parsing from regexp creating.

This commit is contained in:
Jacek Caban 2009-10-14 14:42:30 +02:00 committed by Alexandre Julliard
parent fa3e6917b4
commit 98b5a1c6e8
4 changed files with 38 additions and 30 deletions

View File

@ -225,7 +225,7 @@ HRESULT throw_uri_error(script_ctx_t*,jsexcept_t*,UINT,const WCHAR*);
HRESULT create_object(script_ctx_t*,DispatchEx*,DispatchEx**);
HRESULT create_math(script_ctx_t*,DispatchEx**);
HRESULT create_array(script_ctx_t*,DWORD,DispatchEx**);
HRESULT create_regexp_str(script_ctx_t*,const WCHAR*,DWORD,const WCHAR*,DWORD,DispatchEx**);
HRESULT create_regexp(script_ctx_t*,const WCHAR *,int,DWORD,DispatchEx**);
HRESULT create_string(script_ctx_t*,const WCHAR*,DWORD,DispatchEx**);
HRESULT create_bool(script_ctx_t*,VARIANT_BOOL,DispatchEx**);
HRESULT create_number(script_ctx_t*,VARIANT*,DispatchEx**);
@ -319,6 +319,7 @@ typedef struct {
HRESULT regexp_match_next(script_ctx_t*,DispatchEx*,BOOL,const WCHAR*,DWORD,const WCHAR**,match_result_t**,
DWORD*,DWORD*,match_result_t*);
HRESULT regexp_match(script_ctx_t*,DispatchEx*,const WCHAR*,DWORD,BOOL,match_result_t**,DWORD*);
HRESULT parse_regexp_flags(const WCHAR*,DWORD,DWORD*);
static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
{

View File

@ -766,10 +766,10 @@ static void add_object_literal(parser_ctx_t *ctx, DispatchEx *obj)
literal_t *parse_regexp(parser_ctx_t *ctx)
{
const WCHAR *re, *flags;
const WCHAR *re, *flags_ptr;
DWORD re_len, flags;
DispatchEx *regexp;
literal_t *ret;
DWORD re_len;
HRESULT hres;
TRACE("\n");
@ -790,11 +790,15 @@ literal_t *parse_regexp(parser_ctx_t *ctx)
re_len = ctx->ptr-re;
flags = ++ctx->ptr;
flags_ptr = ++ctx->ptr;
while(ctx->ptr < ctx->end && isalnumW(*ctx->ptr))
ctx->ptr++;
hres = create_regexp_str(ctx->script, re, re_len, flags, ctx->ptr-flags, &regexp);
hres = parse_regexp_flags(flags_ptr, ctx->ptr-flags_ptr, &flags);
if(FAILED(hres))
return NULL;
hres = create_regexp(ctx->script, re, re_len, flags, &regexp);
if(FAILED(hres))
return NULL;

View File

@ -3737,7 +3737,7 @@ static HRESULT alloc_regexp(script_ctx_t *ctx, DispatchEx *object_prototype, Reg
return S_OK;
}
static HRESULT create_regexp(script_ctx_t *ctx, const WCHAR *exp, int len, DWORD flags, DispatchEx **ret)
HRESULT create_regexp(script_ctx_t *ctx, const WCHAR *exp, int len, DWORD flags, DispatchEx **ret)
{
RegExpInstance *regexp;
HRESULT hres;
@ -3773,6 +3773,7 @@ static HRESULT regexp_constructor(script_ctx_t *ctx, DISPPARAMS *dp, VARIANT *re
const WCHAR *opt = emptyW, *src;
DispatchEx *ret;
VARIANT *arg;
DWORD flags;
HRESULT hres;
if(!arg_cnt(dp)) {
@ -3820,7 +3821,11 @@ static HRESULT regexp_constructor(script_ctx_t *ctx, DISPPARAMS *dp, VARIANT *re
opt = V_BSTR(arg);
}
hres = create_regexp_str(ctx, src, -1, opt, strlenW(opt), &ret);
hres = parse_regexp_flags(opt, strlenW(opt), &flags);
if(FAILED(hres))
return hres;
hres = create_regexp(ctx, src, -1, flags, &ret);
if(FAILED(hres))
return hres;
@ -3892,33 +3897,31 @@ HRESULT create_regexp_constr(script_ctx_t *ctx, DispatchEx *object_prototype, Di
return hres;
}
HRESULT create_regexp_str(script_ctx_t *ctx, const WCHAR *exp, DWORD exp_len, const WCHAR *opt,
DWORD opt_len, DispatchEx **ret)
HRESULT parse_regexp_flags(const WCHAR *str, DWORD str_len, DWORD *ret)
{
const WCHAR *p;
DWORD flags = 0;
if(opt) {
for (p = opt; p < opt+opt_len; p++) {
switch (*p) {
case 'g':
flags |= JSREG_GLOB;
break;
case 'i':
flags |= JSREG_FOLD;
break;
case 'm':
flags |= JSREG_MULTILINE;
break;
case 'y':
flags |= JSREG_STICKY;
break;
default:
WARN("wrong flag %c\n", *p);
return E_FAIL;
}
for (p = str; p < str+str_len; p++) {
switch (*p) {
case 'g':
flags |= JSREG_GLOB;
break;
case 'i':
flags |= JSREG_FOLD;
break;
case 'm':
flags |= JSREG_MULTILINE;
break;
case 'y':
flags |= JSREG_STICKY;
break;
default:
WARN("wrong flag %c\n", *p);
return E_FAIL;
}
}
return create_regexp(ctx, exp, exp_len, flags, ret);
*ret = flags;
return S_OK;
}

View File

@ -656,7 +656,7 @@ static HRESULT String_match(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISP
if(FAILED(hres))
return hres;
hres = create_regexp_str(ctx, match_str, SysStringLen(match_str), NULL, 0, &regexp);
hres = create_regexp(ctx, match_str, SysStringLen(match_str), 0, &regexp);
SysFreeString(match_str);
if(FAILED(hres))
return hres;