Commit 77c3dc54 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added support for limit argument in String.split.

parent 79ea850e
......@@ -25,6 +25,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
#define UINT32_MAX 0xffffffff
typedef struct {
jsdisp_t dispex;
......@@ -1082,6 +1084,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
match_result_t *match_result = NULL;
DWORD length, match_cnt, i, match_len = 0;
const WCHAR *str, *ptr, *ptr2;
unsigned limit = UINT32_MAX;
BOOL use_regexp = FALSE;
jsdisp_t *array;
BSTR val_str, match_str = NULL, tmp_str;
......@@ -1089,8 +1092,8 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
TRACE("\n");
if(argc != 1) {
FIXME("unsupported args\n");
if(argc != 1 && argc != 2) {
FIXME("unsupported argc %u\n", argc);
return E_NOTIMPL;
}
......@@ -1098,6 +1101,14 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(FAILED(hres))
return hres;
if(argc > 1 && !is_undefined(argv[1])) {
hres = to_uint32(ctx, argv[1], &limit);
if(FAILED(hres)) {
SysFreeString(val_str);
return hres;
}
}
if(is_object_instance(argv[0])) {
jsdisp_t *regexp;
......@@ -1133,7 +1144,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
if(SUCCEEDED(hres)) {
ptr = str;
for(i=0;; i++) {
for(i=0; i<limit; i++) {
if(use_regexp) {
if(i == match_cnt)
break;
......@@ -1168,7 +1179,7 @@ static HRESULT String_split(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsi
}
}
if(SUCCEEDED(hres) && (match_str || use_regexp)) {
if(SUCCEEDED(hres) && (match_str || use_regexp) && i<limit) {
DWORD len = (str+length) - ptr;
if(len || match_str) {
......
......@@ -512,6 +512,23 @@ ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(r[2] === "", "r[2] = " + r[2]);
r = "1,2,3".split(",", 2);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 2, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
r = "1,2,3".split(",", 0);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 0, "r.length = " + r.length);
r = "1,2,3".split(",", -1);
ok(typeof(r) === "object", "typeof(r) = " + typeof(r));
ok(r.length === 3, "r.length = " + r.length);
ok(r[0] === "1", "r[0] = " + r[0]);
ok(r[1] === "2", "r[1] = " + r[1]);
ok(r[2] === "3", "r[1] = " + r[1]);
tmp = "abcd".indexOf("bc",0);
ok(tmp === 1, "indexOf = " + tmp);
tmp = "abcd".indexOf("bc",1);
......
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