vbscript: Support multibyte characters in Global_Chr.
This commit is contained in:
parent
0e84a59d89
commit
193de805a1
|
@ -1129,9 +1129,15 @@ static HRESULT Global_Asc(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIA
|
||||||
return E_NOTIMPL;
|
return E_NOTIMPL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
|
static HRESULT Global_Chr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
|
||||||
{
|
{
|
||||||
int c;
|
int cp, c, len = 0;
|
||||||
|
CPINFO cpi;
|
||||||
|
WCHAR ch;
|
||||||
|
char buf[2];
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
TRACE("%s\n", debugstr_variant(arg));
|
TRACE("%s\n", debugstr_variant(arg));
|
||||||
|
@ -1140,14 +1146,26 @@ static HRESULT Global_Chr(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIA
|
||||||
if(FAILED(hres))
|
if(FAILED(hres))
|
||||||
return hres;
|
return hres;
|
||||||
|
|
||||||
if(c < 0 || c >= 0x100) {
|
cp = GetACP();
|
||||||
|
if(!GetCPInfo(cp, &cpi))
|
||||||
|
cpi.MaxCharSize = 1;
|
||||||
|
|
||||||
|
if((c!=(short)c && c!=(unsigned short)c) ||
|
||||||
|
(unsigned short)c>=(cpi.MaxCharSize>1 ? 0x10000 : 0x100)) {
|
||||||
WARN("invalid arg %d\n", c);
|
WARN("invalid arg %d\n", c);
|
||||||
return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
|
return MAKE_VBSERROR(VBSE_ILLEGAL_FUNC_CALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(res) {
|
if(c>>8)
|
||||||
WCHAR ch = c;
|
buf[len++] = c>>8;
|
||||||
|
if(!len || IsDBCSLeadByteEx(cp, buf[0]))
|
||||||
|
buf[len++] = c;
|
||||||
|
if(!MultiByteToWideChar(0, 0, buf, len, &ch, 1)) {
|
||||||
|
WARN("invalid arg %d, cp %d\n", c, cp);
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(res) {
|
||||||
V_VT(res) = VT_BSTR;
|
V_VT(res) = VT_BSTR;
|
||||||
V_BSTR(res) = SysAllocStringLen(&ch, 1);
|
V_BSTR(res) = SysAllocStringLen(&ch, 1);
|
||||||
if(!V_BSTR(res))
|
if(!V_BSTR(res))
|
||||||
|
|
|
@ -140,6 +140,7 @@ Call ok(Chr(119.5) = "x", "Chr(119.5) = " & Chr(119.5))
|
||||||
sub testChrError
|
sub testChrError
|
||||||
on error resume next
|
on error resume next
|
||||||
|
|
||||||
|
if isEnglishLang then
|
||||||
call Err.clear()
|
call Err.clear()
|
||||||
call Chr(-1)
|
call Chr(-1)
|
||||||
call ok(Err.number = 5, "Err.number = " & Err.number)
|
call ok(Err.number = 5, "Err.number = " & Err.number)
|
||||||
|
@ -147,6 +148,15 @@ sub testChrError
|
||||||
call Err.clear()
|
call Err.clear()
|
||||||
call Chr(256)
|
call Chr(256)
|
||||||
call ok(Err.number = 5, "Err.number = " & Err.number)
|
call ok(Err.number = 5, "Err.number = " & Err.number)
|
||||||
|
end if
|
||||||
|
|
||||||
|
call Err.clear()
|
||||||
|
call Chr(65536)
|
||||||
|
call ok(Err.number = 5, "Err.number = " & Err.number)
|
||||||
|
|
||||||
|
call Err.clear()
|
||||||
|
call Chr(-32769)
|
||||||
|
call ok(Err.number = 5, "Err.number = " & Err.number)
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
call testChrError
|
call testChrError
|
||||||
|
|
Loading…
Reference in New Issue