From: Shuai Meng Subject: [PATCH] vbscript: Implemented IsNumeric Message-Id: <53570746.0@gmail.com> Date: Wed, 23 Apr 2014 08:20:22 +0800 --- dlls/vbscript/global.c | 37 +++++++++++++++++++++++++++++++++++-- dlls/vbscript/tests/api.vbs | 19 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 2ab9377..f95401f 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -557,8 +557,41 @@ static HRESULT Global_IsNull(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VA static HRESULT Global_IsNumeric(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + TRACE("(%s)\n", debugstr_variant(arg)); + + assert(args_cnt == 1); + + if(res) { + V_VT(res) = VT_BOOL; + switch(V_VT(arg)) { + case VT_UI1: + case VT_I2: + case VT_I4: + case VT_I8: + case VT_R4: + case VT_R8: + case VT_BOOL: + case VT_EMPTY: + case VT_CY: + V_BOOL(res) = VARIANT_TRUE; + break; + case VT_BSTR: { + HRESULT hRet; + double d; + + hRet = VarR8FromStr(V_BSTR(arg), LOCALE_USER_DEFAULT, 0, &d); + if(SUCCEEDED(hRet)) + V_BOOL(res) = VARIANT_TRUE; + else + V_BOOL(res) = VARIANT_FALSE; + break; + } + default: + V_BOOL(res) = VARIANT_FALSE; + break; + } + } + return S_OK; } static HRESULT Global_IsArray(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index beee4d4..cf63fb9 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -170,6 +170,25 @@ Call ok(not isNull(4), "isNull(4) is true?") Call ok(not isNull("x"), "isNull(""x"") is true?") Call ok(isNull(Null), "isNull(Null) is not true?") +Call ok(isNumeric(empty), "isNumeric(empty) is not true?") +Call ok(not isNumeric(Null), "isNumeric(Null) is not true?") +Call ok(isNumeric(32767), "isNumeric(32767) is true?") +Call ok(isNumeric(32768), "isNumeric(32768) is true?") +Call ok(isNumeric(CSng(3242.4)), "isNumeric(CSng(3242.4)) is true?") +Call ok(isNumeric(32768.4), "isNumeric(32768.4) is true?") +Call ok(isNumeric(CCur(32768.4)), "isNumeric(CCur(32768.4)) is true?") +Call ok(not isNumeric(CDate(32)), "isNumeric(CDate(32)) is true?") +Call ok(isNumeric("44"), "isNumeric(""44"") is true?") +Call ok(not isNumeric("rwrf"), "isNumeric(""rwrf"") is not true?") +Call ok(not isNumeric(Nothing), "isNumeric(Nothing) is not true?") +Call ok(not isNumeric(New EmptyClass), "isNumeric(New EmptyClass) is not true?") +Call ok(isNumeric(true), "isNumeric(true) is true?") +Call ok(isNumeric(CByte(32)), "isNumeric(CByte(32)) is true?") +Dim arr(2) +arr(0) = 2 +arr(1) = 3 +Call ok(not isNumeric(arr), "isNumeric(arr) is not true?") + Call ok(getVT(err) = "VT_DISPATCH", "getVT(err) = " & getVT(err)) Sub TestHex(x, ex)