Commit 626a38b5 authored by Dmitry Kislyuk's avatar Dmitry Kislyuk Committed by Alexandre Julliard

vbscript: Support conversion to string in InStr.

parent a58b7d38
......@@ -1624,7 +1624,7 @@ static HRESULT Global_InStr(BuiltinDisp *This, VARIANT *args, unsigned args_cnt,
{
VARIANT *startv, *str1v, *str2v;
BSTR str1, str2;
int ret, start = 0, mode = 0;
int ret = -1, start = 0, mode = 0;
HRESULT hres;
TRACE("args_cnt=%u\n", args_cnt);
......@@ -1673,23 +1673,33 @@ static HRESULT Global_InStr(BuiltinDisp *This, VARIANT *args, unsigned args_cnt,
return return_null(res);
if(V_VT(str1v) != VT_BSTR) {
FIXME("Unsupported str1 type %s\n", debugstr_variant(str1v));
return E_NOTIMPL;
hres = to_string(str1v, &str1);
if(FAILED(hres))
return hres;
}
str1 = V_BSTR(str1v);
else
str1 = V_BSTR(str1v);
if(V_VT(str2v) != VT_BSTR) {
FIXME("Unsupported str2 type %s\n", debugstr_variant(str2v));
return E_NOTIMPL;
hres = to_string(str2v, &str2);
if(FAILED(hres)){
if(V_VT(str1v) != VT_BSTR)
SysFreeString(str1);
return hres;
}
}
str2 = V_BSTR(str2v);
if(start >= SysStringLen(str1))
return return_int(res, 0);
else
str2 = V_BSTR(str2v);
ret = FindStringOrdinal(FIND_FROMSTART, str1 + start, SysStringLen(str1)-start,
str2, SysStringLen(str2), mode);
if(start < SysStringLen(str1)) {
ret = FindStringOrdinal(FIND_FROMSTART, str1 + start, SysStringLen(str1)-start,
str2, SysStringLen(str2), mode);
}
if(V_VT(str1v) != VT_BSTR)
SysFreeString(str1);
if(V_VT(str2v) != VT_BSTR)
SysFreeString(str2);
return return_int(res, ++ret ? ret+start : 0);
}
......
......@@ -429,6 +429,12 @@ Call ok(x = 8, "InStr returned " & x)
x = InStr(1, "abc" & Chr(0) & "ABC", Chr(0) & "a", 1)
Call ok(x = 4, "InStr returned " & x)
x = InStr(1, 23456, 45, 0)
Call ok(x = 3, "InStr returned " & x)
x = InStr(1, "23456", 34, 1)
Call ok(x = 2, "InStr returned " & x)
x = InStrRev("bcabcd", "bc")
Call ok(x = 4, "InStrRev returned " & x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment