vbscript: Added InStrRev implementation.

This commit is contained in:
Jacek Caban 2015-02-10 18:46:25 +01:00 committed by Alexandre Julliard
parent ac3df5e1f1
commit 9b0ebaeb78
2 changed files with 113 additions and 3 deletions

View File

@ -1777,10 +1777,62 @@ static HRESULT Global_StrReverse(vbdisp_t *This, VARIANT *arg, unsigned args_cnt
return return_bstr(res, ret);
}
static HRESULT Global_InStrRev(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)
static HRESULT Global_InStrRev(vbdisp_t *This, VARIANT *args, unsigned args_cnt, VARIANT *res)
{
FIXME("\n");
return E_NOTIMPL;
int start, ret = 0;
BSTR str1, str2;
HRESULT hres;
TRACE("%s %s arg_cnt=%u\n", debugstr_variant(args), debugstr_variant(args+1), args_cnt);
if(args_cnt > 3) {
FIXME("Unsupported args\n");
return E_NOTIMPL;
}
assert(2 <= args_cnt && args_cnt <= 4);
if(V_VT(args) == VT_NULL || V_VT(args+1) == VT_NULL || V_VT(args+2) == VT_NULL)
return MAKE_VBSERROR(VBSE_ILLEGAL_NULL_USE);
hres = to_string(args, &str1);
if(FAILED(hres))
return hres;
hres = to_string(args+1, &str2);
if(SUCCEEDED(hres)) {
if(args_cnt > 2) {
hres = to_int(args+2, &start);
if(SUCCEEDED(hres) && start <= 0) {
FIXME("Unsupported start %d\n", start);
hres = E_NOTIMPL;
}
}else {
start = SysStringLen(str1);
}
}
if(SUCCEEDED(hres)) {
const WCHAR *ptr;
size_t len;
len = SysStringLen(str2);
if(start >= len && start <= SysStringLen(str1)) {
for(ptr = str1+start-SysStringLen(str2); ptr >= str1; ptr--) {
if(!memcmp(ptr, str2, len*sizeof(WCHAR))) {
ret = ptr-str1+1;
break;
}
}
}
}
SysFreeString(str1);
SysFreeString(str2);
if(FAILED(hres))
return hres;
return return_int(res, ret);
}
static HRESULT Global_LoadPicture(vbdisp_t *This, VARIANT *arg, unsigned args_cnt, VARIANT *res)

View File

@ -282,6 +282,64 @@ Call ok(x = 2, "InStr returned " & x)
x = InStr(2.6, "abcd", "bc")
Call ok(x = 0, "InStr returned " & x)
x = InStrRev("bcabcd", "bc")
Call ok(x = 4, "InStrRev returned " & x)
Call ok(getVT(x) = "VT_I4*", "getVT(InStrRev) returned " & getVT(x))
x = InStrRev("bcabcd", "bc", 6)
Call ok(x = 4, "InStrRev returned " & x)
x = InStrRev("abcd", "bcx")
Call ok(x = 0, "InStrRev returned " & x)
x = InStrRev("abcd", "bc", 3)
Call ok(x = 2, "InStrRev returned " & x)
x = InStrRev("abcd", "bc", 2)
Call ok(x = 0, "InStrRev returned " & x)
x = InStrRev("abcd", "b", 2)
Call ok(x = 2, "InStrRev returned " & x)
x = InStrRev("abcd", "bc", 5)
Call ok(x = 0, "InStrRev returned " & x)
x = InStrRev("abcd", "bc", 15)
Call ok(x = 0, "InStrRev returned " & x)
x = "abcd"
x = InStrRev(x, "bc")
Call ok(x = 2, "InStrRev returned " & x)
x = InStrRev("abcd", "bc", 1.3)
Call ok(x = 0, "InStrRev returned " & x)
x = InStrRev("abcd", "bc", 2.3)
Call ok(x = 0, "InStrRev returned " & x)
x = InStrRev("abcd", "bc", 2.6)
Call ok(x = 2, "InStrRev returned " & x)
x = InStrRev("1234", 34)
Call ok(x = 3, "InStrRev returned " & x)
x = InStrRev(1234, 34)
Call ok(x = 3, "InStrRev returned " & x)
Sub testInStrRevError(arg1, arg2, arg3, error_num)
on error resume next
Dim x
Call Err.clear()
x = InStrRev(arg1, arg2, arg3)
Call ok(Err.number = error_num, "Err.number = " & Err.number)
End Sub
call testInStrRevError("abcd", null, 2, 94)
call testInStrRevError(null, "abcd", 2, 94)
call testInStrRevError("abcd", "abcd", null, 94)
Sub TestMid(str, start, len, ex)
x = Mid(str, start, len)
Call ok(x = ex, "Mid(" & str & ", " & start & ", " & len & ") = " & x & " expected " & ex)