Jacek Caban : jscript: Added String.split implementation.

Alexandre Julliard julliard at winehq.org
Thu Sep 25 07:13:29 CDT 2008


Module: wine
Branch: master
Commit: 6906c2f1baf039dc7069d179a3e5d5c2f9e9b2c7
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=6906c2f1baf039dc7069d179a3e5d5c2f9e9b2c7

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Sep 25 00:54:09 2008 +0200

jscript: Added String.split implementation.

---

 dlls/jscript/string.c |   88 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c
index eb50624..fc40462 100644
--- a/dlls/jscript/string.c
+++ b/dlls/jscript/string.c
@@ -785,8 +785,92 @@ static HRESULT String_small(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
 static HRESULT String_split(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    StringInstance *string;
+    match_result_t *match_result;
+    DWORD match_cnt, i, len;
+    const WCHAR *ptr;
+    VARIANT *arg, var;
+    DispatchEx *array;
+    HRESULT hres;
+
+    TRACE("\n");
+
+    if(!is_class(dispex, JSCLASS_STRING)) {
+        FIXME("not String this\n");
+        return E_NOTIMPL;
+    }
+
+    string = (StringInstance*)dispex;
+
+    if(arg_cnt(dp) != 1) {
+        FIXME("unsupported args\n");
+        return E_NOTIMPL;
+    }
+
+    arg = get_arg(dp, 0);
+    switch(V_VT(arg)) {
+    case VT_DISPATCH: {
+        DispatchEx *regexp;
+
+        regexp = iface_to_jsdisp((IUnknown*)V_DISPATCH(arg));
+        if(regexp) {
+            if(is_class(regexp, JSCLASS_REGEXP)) {
+                hres = regexp_match(regexp, string->str, string->length, TRUE, &match_result, &match_cnt);
+                jsdisp_release(regexp);
+                if(FAILED(hres))
+                    return hres;
+                break;
+            }
+            jsdisp_release(regexp);
+        }
+    }
+    default:
+        FIXME("unsupported vt %d\n", V_VT(arg));
+        return E_NOTIMPL;
+    }
+
+    hres = create_array(dispex->ctx, match_cnt+1, &array);
+
+    if(SUCCEEDED(hres)) {
+        ptr = string->str;
+        for(i=0; i < match_cnt; i++) {
+            len = match_result[i].str-ptr;
+            V_VT(&var) = VT_BSTR;
+            V_BSTR(&var) = SysAllocStringLen(ptr, len);
+            if(!V_BSTR(&var)) {
+                hres = E_OUTOFMEMORY;
+                break;
+            }
+
+            hres = jsdisp_propput_idx(array, i, lcid, &var, ei, sp);
+            SysFreeString(V_BSTR(&var));
+            if(FAILED(hres))
+                break;
+
+            ptr = match_result[i].str + match_result[i].len;
+        }
+    }
+
+    if(SUCCEEDED(hres)) {
+        len = (string->str+string->length) - ptr;
+
+        V_VT(&var) = VT_BSTR;
+        V_BSTR(&var) = SysAllocStringLen(ptr, len);
+
+        hres = jsdisp_propput_idx(array, i, lcid, &var, ei, sp);
+        SysFreeString(V_BSTR(&var));
+    }
+
+    heap_free(match_result);
+
+    if(SUCCEEDED(hres) && retv) {
+        V_VT(retv) = VT_DISPATCH;
+        V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(array);
+    }else {
+        jsdisp_release(array);
+    }
+
+    return hres;
 }
 
 static HRESULT String_strike(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,




More information about the wine-cvs mailing list