vbscript: Added Right() implementation.

This commit is contained in:
Jacek Caban 2012-10-01 13:00:09 +02:00 committed by Alexandre Julliard
parent 3e45fbcb6b
commit 50985fa2d3
2 changed files with 45 additions and 3 deletions

View File

@ -676,10 +676,42 @@ static HRESULT Global_LeftB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VAR
return E_NOTIMPL;
}
static HRESULT Global_Right(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
static HRESULT Global_Right(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+str_len-len, len);
SysFreeString(conv_str);
if(!ret)
return E_OUTOFMEMORY;
return return_bstr(res, ret);
}
static HRESULT Global_RightB(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)

View File

@ -215,6 +215,16 @@ TestLeft "test", 0, ""
TestLeft 123, 2, "12"
if isEnglishLang then TestLeft true, 2, "Tr"
Sub TestRight(str, len, ex)
Call ok(Right(str, len) = ex, "Right(" & str & ", " & len & ") = " & Right(str, len))
End Sub
TestRight "test", 2, "st"
TestRight "test", 5, "test"
TestRight "test", 0, ""
TestRight 123, 2, "23"
if isEnglishLang then TestRight true, 2, "ue"
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)))