From ea5dbc13292102993f0d6e0e27b265b4449be5ca Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 22 Oct 2019 15:54:13 +0200 Subject: [PATCH] vbscript: Implement String function. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/vbscript/global.c | 34 +++++++++++++++++++++++++++++++--- dlls/vbscript/tests/api.vbs | 28 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c index 364ff0c02cb..0de15595929 100644 --- a/dlls/vbscript/global.c +++ b/dlls/vbscript/global.c @@ -24,6 +24,7 @@ #include "mshtmhst.h" #include "objsafe.h" +#include "wchar.h" #include "wine/debug.h" @@ -1543,10 +1544,37 @@ static HRESULT Global_Space(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, return S_OK; } -static HRESULT Global_String(BuiltinDisp *This, VARIANT *arg, unsigned args_cnt, VARIANT *res) +static HRESULT Global_String(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, VARIANT *res) { - FIXME("\n"); - return E_NOTIMPL; + WCHAR ch; + int cnt; + HRESULT hres; + + TRACE("%s %s\n", debugstr_variant(args), debugstr_variant(args + 1)); + + hres = to_int(args, &cnt); + if(FAILED(hres)) + return hres; + if(cnt < 0) + return E_INVALIDARG; + + if(V_VT(args + 1) != VT_BSTR) { + FIXME("Unsupported argument %s\n", debugstr_variant(args+1)); + return E_NOTIMPL; + } + if(!SysStringLen(V_BSTR(args + 1))) + return E_INVALIDARG; + ch = V_BSTR(args + 1)[0]; + + if(res) { + BSTR str = SysAllocStringLen(NULL, cnt); + if(!str) + return E_OUTOFMEMORY; + wmemset(str, ch, cnt); + V_VT(res) = VT_BSTR; + V_BSTR(res) = str; + } + return S_OK; } static HRESULT Global_InStr(BuiltinDisp *This, VARIANT *args, unsigned args_cnt, VARIANT *res) diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs index 49dd4959f77..5c9e219d608 100644 --- a/dlls/vbscript/tests/api.vbs +++ b/dlls/vbscript/tests/api.vbs @@ -548,6 +548,34 @@ Call ok(Space(0.5) = "", "Space(0.5) = " & Space(0.5) & """") Call ok(Space(1.5) = " ", "Space(1.5) = " & Space(1.5) & """") Call ok(Space("1") = " ", "Space(""1"") = " & Space("1") & """") +sub test_string(cnt, char, exp) + call ok(String(cnt, char) = exp, "String(" & cnt & ", """ & char & """ = """ & _ + String(cnt, char) & """ expected """ & exp & """") +end sub + +test_string 3, "x", "xxx" +test_string 3, "xy", "xxx" +test_string 1, "z", "z" +test_string 0, "z", "" +test_string "3", "xy", "xxx" +test_string 3, Chr(3), Chr(3)&Chr(3)&Chr(3) + +call ok(getVT(String(0, "z")) = "VT_BSTR", "getVT(String(0,z)) = " & getVT(String(0, "z"))) + +sub test_string_error() + on error resume next + dim x + x = String(-2, "x") + call ok(err.number = 5, "err.number = " & err.number) + err.clear + x = String(3, "") + call ok(err.number = 5, "err.number = " & err.number) + err.clear + x = String(0, "") + call ok(err.number = 5, "err.number = " & err.number) +end sub +call test_string_error + Sub TestStrReverse(str, ex) Call ok(StrReverse(str) = ex, "StrReverse(" & str & ") = " & StrReverse(str)) End Sub