Dmitry Kislyuk : vbscript: Support conversion to string in InStr.
Alexandre Julliard
julliard at winehq.org
Tue Aug 4 15:26:36 CDT 2020
Module: wine
Branch: master
Commit: 626a38b570188e5c12c86ab628c9b1e576f25e62
URL: https://source.winehq.org/git/wine.git/?a=commit;h=626a38b570188e5c12c86ab628c9b1e576f25e62
Author: Dmitry Kislyuk <dimaki at rocketmail.com>
Date: Tue Aug 4 12:14:52 2020 -0500
vbscript: Support conversion to string in InStr.
Signed-off-by: Dmitry Kislyuk <dimaki at rocketmail.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/vbscript/global.c | 34 ++++++++++++++++++++++------------
dlls/vbscript/tests/api.vbs | 6 ++++++
2 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c
index e41c2ff7b3..abb4b7933b 100644
--- a/dlls/vbscript/global.c
+++ b/dlls/vbscript/global.c
@@ -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);
}
diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs
index 3f50195bdc..0c37c3c843 100644
--- a/dlls/vbscript/tests/api.vbs
+++ b/dlls/vbscript/tests/api.vbs
@@ -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)
More information about the wine-cvs
mailing list