Commit beb9e113 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

vbscript: Handle CP_UTF8 in Chr()/Asc().

parent 393f740b
...@@ -1842,10 +1842,12 @@ static HRESULT Global_Asc(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VA ...@@ -1842,10 +1842,12 @@ static HRESULT Global_Asc(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VA
if(!SysStringLen(str)) if(!SysStringLen(str))
hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); hres = MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
else if (This->ctx->codepage == CP_UTF8)
hres = return_short(res, *str);
else { else {
unsigned char buf[2]; unsigned char buf[2];
short val = 0; short val = 0;
int n = WideCharToMultiByte(CP_ACP, 0, str, 1, (char*)buf, sizeof(buf), NULL, NULL); int n = WideCharToMultiByte(This->ctx->codepage, 0, str, 1, (char*)buf, sizeof(buf), NULL, NULL);
switch(n) { switch(n) {
case 1: case 1:
val = buf[0]; val = buf[0];
...@@ -1865,9 +1867,6 @@ static HRESULT Global_Asc(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VA ...@@ -1865,9 +1867,6 @@ static HRESULT Global_Asc(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VA
return hres; return hres;
} }
/* The function supports only single-byte and double-byte character sets. It
* ignores language specified by IActiveScriptSite::GetLCID. The argument needs
* to be in range of short or unsigned short. */
static HRESULT Global_Chr(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) static HRESULT Global_Chr(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
{ {
int cp, c, len = 0; int cp, c, len = 0;
...@@ -1882,7 +1881,7 @@ static HRESULT Global_Chr(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VA ...@@ -1882,7 +1881,7 @@ static HRESULT Global_Chr(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VA
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
cp = GetACP(); cp = This->ctx->codepage;
if(!GetCPInfo(cp, &cpi)) if(!GetCPInfo(cp, &cpi))
cpi.MaxCharSize = 1; cpi.MaxCharSize = 1;
...@@ -1892,13 +1891,20 @@ static HRESULT Global_Chr(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VA ...@@ -1892,13 +1891,20 @@ static HRESULT Global_Chr(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VA
return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL); return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
} }
if(c>>8) if (cp == CP_UTF8)
buf[len++] = c>>8; {
if(!len || IsDBCSLeadByteEx(cp, buf[0])) ch = c;
buf[len++] = c; }
if(!MultiByteToWideChar(CP_ACP, 0, buf, len, &ch, 1)) { else
WARN("invalid arg %d, cp %d\n", c, cp); {
return E_FAIL; if(c>>8)
buf[len++] = c>>8;
if(!len || IsDBCSLeadByteEx(cp, buf[0]))
buf[len++] = c;
if(!MultiByteToWideChar(cp, 0, buf, len, &ch, 1)) {
WARN("invalid arg %d, cp %d\n", c, cp);
return E_FAIL;
}
} }
if(res) { if(res) {
......
...@@ -555,8 +555,8 @@ static ULONG WINAPI VBScript_Release(IActiveScript *iface) ...@@ -555,8 +555,8 @@ static ULONG WINAPI VBScript_Release(IActiveScript *iface)
static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass) static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
{ {
VBScript *This = impl_from_IActiveScript(iface); VBScript *This = impl_from_IActiveScript(iface);
LCID lcid = LOCALE_USER_DEFAULT;
named_item_t *item; named_item_t *item;
LCID lcid;
HRESULT hres; HRESULT hres;
TRACE("(%p)->(%p)\n", This, pass); TRACE("(%p)->(%p)\n", This, pass);
...@@ -590,9 +590,12 @@ static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScript ...@@ -590,9 +590,12 @@ static HRESULT WINAPI VBScript_SetScriptSite(IActiveScript *iface, IActiveScript
This->ctx->site = pass; This->ctx->site = pass;
IActiveScriptSite_AddRef(This->ctx->site); IActiveScriptSite_AddRef(This->ctx->site);
hres = IActiveScriptSite_GetLCID(This->ctx->site, &lcid); IActiveScriptSite_GetLCID(This->ctx->site, &lcid);
if(hres == S_OK) This->ctx->lcid = IsValidLocale(lcid, 0) ? lcid : GetUserDefaultLCID();
This->ctx->lcid = lcid; GetLocaleInfoW(lcid, LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER, (WCHAR *)&This->ctx->codepage,
sizeof(This->ctx->codepage)/sizeof(WCHAR));
if (!This->ctx->codepage)
This->ctx->codepage = CP_UTF8;
if(This->is_initialized) if(This->is_initialized)
change_state(This, SCRIPTSTATE_INITIALIZED); change_state(This, SCRIPTSTATE_INITIALIZED);
......
...@@ -183,6 +183,7 @@ static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i) ...@@ -183,6 +183,7 @@ static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
struct _script_ctx_t { struct _script_ctx_t {
IActiveScriptSite *site; IActiveScriptSite *site;
LCID lcid; LCID lcid;
UINT codepage;
IInternetHostSecurityManager *secmgr; IInternetHostSecurityManager *secmgr;
DWORD safeopt; DWORD safeopt;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment