vbscript: Implement String function.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2019-10-22 15:54:13 +02:00 committed by Alexandre Julliard
parent bd7132e312
commit ea5dbc1329
2 changed files with 59 additions and 3 deletions

View File

@ -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)

View File

@ -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