From 3fa78601453abe7813a0b0d67bf5854cd39ddc3e Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 18 Sep 2012 12:25:26 +0200 Subject: [PATCH] vbscript: Added Len implementation. --- dlls/vbscript/global.c | 24 ++++++++++++++++++++++-- dlls/vbscript/tests/api.vbs | 6 ++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 3c28e9608d5..051366474b4 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -468,8 +468,28 @@ static HRESULT Global_RGB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIA static HRESULT Global_Len(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + DWORD len; + HRESULT hres; + + TRACE("%s\n", debugstr_variant(arg)); + + if(V_VT(arg) == VT_NULL) + return return_null(res); + + if(V_VT(arg) != VT_BSTR) { + BSTR str; + + hres = to_string(arg, &str); + if(FAILED(hres)) + return hres; + + len = SysStringLen(str); + SysFreeString(str); + }else { + len = SysStringLen(V_BSTR(arg)); + } + + return return_int(res, len); } static HRESULT Global_LenB(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 fd339dd9be7..c17c5b4a798 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -173,4 +173,10 @@ TestLCase 0.123, doubleAsString(0.123) TestLCase Empty, "" Call ok(getVT(LCase(Null)) = "VT_NULL", "getVT(LCase(Null)) = " & getVT(LCase(Null))) +Call ok(Len("abc") = 3, "Len(abc) = " & Len("abc")) +Call ok(Len("") = 0, "Len() = " & Len("")) +Call ok(Len(1) = 1, "Len(1) = " & Len(1)) +Call ok(isNull(Len(null)), "Len(null) = " & Len(null)) +Call ok(Len(empty) = 0, "Len(empty) = " & Len(empty)) + Call reportSuccess()