Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
b67e875e
Commit
b67e875e
authored
Oct 07, 2008
by
Jacek Caban
Committed by
Alexandre Julliard
Oct 08, 2008
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jscript: Added String.split implementation for non-regexp arguments.
parent
67af45be
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
16 deletions
+96
-16
string.c
dlls/jscript/string.c
+49
-16
api.js
dlls/jscript/tests/api.js
+30
-0
regexp.js
dlls/jscript/tests/regexp.js
+17
-0
No files found.
dlls/jscript/string.c
View file @
b67e875e
...
...
@@ -846,12 +846,13 @@ 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
)
{
match_result_t
*
match_result
=
NULL
;
DWORD
match_cnt
,
i
,
match_len
=
0
;
StringInstance
*
string
;
match_result_t
*
match_result
;
DWORD
match_cnt
,
i
,
len
;
const
WCHAR
*
ptr
;
const
WCHAR
*
ptr
,
*
ptr2
;
VARIANT
*
arg
,
var
;
DispatchEx
*
array
;
BSTR
match_str
=
NULL
;
HRESULT
hres
;
TRACE
(
"
\n
"
);
...
...
@@ -886,18 +887,38 @@ static HRESULT String_split(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
}
}
default:
FIXME
(
"unsupported vt %d
\n
"
,
V_VT
(
arg
));
return
E_NOTIMPL
;
hres
=
to_string
(
dispex
->
ctx
,
arg
,
ei
,
&
match_str
);
if
(
FAILED
(
hres
))
return
hres
;
match_len
=
SysStringLen
(
match_str
);
if
(
!
match_len
)
{
SysFreeString
(
match_str
);
match_str
=
NULL
;
}
}
hres
=
create_array
(
dispex
->
ctx
,
match_cnt
+
1
,
&
array
);
hres
=
create_array
(
dispex
->
ctx
,
0
,
&
array
);
if
(
SUCCEEDED
(
hres
))
{
ptr
=
string
->
str
;
for
(
i
=
0
;
i
<
match_cnt
;
i
++
)
{
len
=
match_result
[
i
].
str
-
ptr
;
for
(
i
=
0
;;
i
++
)
{
if
(
match_result
)
{
if
(
i
==
match_cnt
)
break
;
ptr2
=
match_result
[
i
].
str
;
}
else
if
(
match_str
)
{
ptr2
=
strstrW
(
ptr
,
match_str
);
if
(
!
ptr2
)
break
;
}
else
{
if
(
!*
ptr
)
break
;
ptr2
=
ptr
+
1
;
}
V_VT
(
&
var
)
=
VT_BSTR
;
V_BSTR
(
&
var
)
=
SysAllocStringLen
(
ptr
,
len
);
V_BSTR
(
&
var
)
=
SysAllocStringLen
(
ptr
,
ptr2
-
ptr
);
if
(
!
V_BSTR
(
&
var
))
{
hres
=
E_OUTOFMEMORY
;
break
;
...
...
@@ -908,20 +929,32 @@ static HRESULT String_split(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
if
(
FAILED
(
hres
))
break
;
ptr
=
match_result
[
i
].
str
+
match_result
[
i
].
len
;
if
(
match_result
)
ptr
=
match_result
[
i
].
str
+
match_result
[
i
].
len
;
else
if
(
match_str
)
ptr
=
ptr2
+
match_len
;
else
ptr
++
;
}
}
if
(
SUCCEEDED
(
hres
))
{
len
=
(
string
->
str
+
string
->
length
)
-
ptr
;
if
(
SUCCEEDED
(
hres
)
&&
(
match_str
||
match_result
)
)
{
DWORD
len
=
(
string
->
str
+
string
->
length
)
-
ptr
;
V_VT
(
&
var
)
=
VT_BSTR
;
V_BSTR
(
&
var
)
=
SysAllocStringLen
(
ptr
,
len
);
if
(
len
||
match_str
)
{
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
));
if
(
V_BSTR
(
&
var
))
{
hres
=
jsdisp_propput_idx
(
array
,
i
,
lcid
,
&
var
,
ei
,
sp
);
SysFreeString
(
V_BSTR
(
&
var
));
}
else
{
hres
=
E_OUTOFMEMORY
;
}
}
}
SysFreeString
(
match_str
);
heap_free
(
match_result
);
if
(
SUCCEEDED
(
hres
)
&&
retv
)
{
...
...
dlls/jscript/tests/api.js
View file @
b67e875e
...
...
@@ -200,6 +200,36 @@ ok(r === "-ret-", "r = " + r + " expected '-ret-'");
r
=
"-[test]-"
.
replace
(
"[test]"
,
replaceFunc3
,
"test"
);
ok
(
r
===
"-ret-"
,
"r = "
+
r
+
" expected '-ret-'"
);
r
=
"1,2,3"
.
split
(
","
);
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[2] = "
+
r
[
2
]);
r
=
"1,2,3"
.
split
(
",*"
);
ok
(
r
.
length
===
1
,
"r.length = "
+
r
.
length
);
ok
(
r
[
0
]
===
"1,2,3"
,
"r[0] = "
+
r
[
0
]);
r
=
"123"
.
split
(
""
);
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[2] = "
+
r
[
2
]);
r
=
"123"
.
split
(
2
);
ok
(
r
.
length
===
2
,
"r.length = "
+
r
.
length
);
ok
(
r
[
0
]
===
"1"
,
"r[0] = "
+
r
[
0
]);
ok
(
r
[
1
]
===
"3"
,
"r[1] = "
+
r
[
1
]);
r
=
"1,2,"
.
split
(
","
);
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
]
===
""
,
"r[2] = "
+
r
[
2
]);
tmp
=
"abcd"
.
indexOf
(
"bc"
,
0
);
ok
(
tmp
===
1
,
"indexOf = "
+
tmp
);
tmp
=
"abcd"
.
indexOf
(
"bc"
,
1
);
...
...
dlls/jscript/tests/regexp.js
View file @
b67e875e
...
...
@@ -150,4 +150,21 @@ function replaceFunc2(m, subm, off, str) {
r
=
"[test1] [test2]"
.
replace
(
/
\[([^\[]
+
)\]
/g
,
replaceFunc2
);
ok
(
r
===
"r0 r1"
,
"r = '"
+
r
+
"' expected 'r0 r1'"
);
r
=
"1,,2,3"
.
split
(
/,+/g
);
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[2] = "
+
r
[
2
]);
r
=
"1,,2,3"
.
split
(
/,+/
);
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[2] = "
+
r
[
2
]);
r
=
"1,,2,"
.
split
(
/,+/
);
ok
(
r
.
length
===
2
,
"r.length = "
+
r
.
length
);
ok
(
r
[
0
]
===
"1"
,
"r[0] = "
+
r
[
0
]);
ok
(
r
[
1
]
===
"2"
,
"r[1] = "
+
r
[
1
]);
reportSuccess
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment