vbscript: Added Left() implementation.

This commit is contained in:
Jacek Caban 2012-10-01 12:59:56 +02:00 committed by Alexandre Julliard
parent 24eee97d21
commit 3e45fbcb6b
2 changed files with 45 additions and 3 deletions

View File

@ -632,10 +632,42 @@ static HRESULT Global_LenB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARI
return E_NOTIMPL;
}
static HRESULT Global_Left(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
static HRESULT Global_Left(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
{
FIXME("\n");
return E_NOTIMPL;
BSTR str, ret, conv_str = NULL;
int len, str_len;
HRESULT hres;
TRACE("(%s %s)\n", debugstr_variant(args+1), debugstr_variant(args));
if(V_VT(args+1) == VT_BSTR) {
str = V_BSTR(args+1);
}else {
hres = to_string(args+1, &conv_str);
if(FAILED(hres))
return hres;
str = conv_str;
}
hres = to_int(args, &len);
if(FAILED(hres))
return hres;
if(len < 0) {
FIXME("len = %d\n", len);
return E_FAIL;
}
str_len = SysStringLen(str);
if(len > str_len)
len = str_len;
ret = SysAllocStringLen(str, len);
SysFreeString(conv_str);
if(!ret)
return E_OUTOFMEMORY;
return return_bstr(res, ret);
}
static HRESULT Global_LeftB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)

View File

@ -205,6 +205,16 @@ TestStrReverse "", ""
TestStrReverse 123, "321"
if isEnglishLang then TestStrReverse true, "eurT"
Sub TestLeft(str, len, ex)
Call ok(Left(str, len) = ex, "Left(" & str & ", " & len & ") = " & Left(str, len))
End Sub
TestLeft "test", 2, "te"
TestLeft "test", 5, "test"
TestLeft "test", 0, ""
TestLeft 123, 2, "12"
if isEnglishLang then TestLeft true, 2, "Tr"
Sub TestRound(val, exval, vt)
Call ok(Round(val) = exval, "Round(" & val & ") = " & Round(val))
Call ok(getVT(Round(val)) = vt, "getVT(Round(" & val & ")) = " & getVT(Round(val)))