Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
7ce9cc3b
Commit
7ce9cc3b
authored
Feb 18, 2013
by
Yukihiro Matz Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
String#split should honor limit arg
parent
c9176abe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
12 deletions
+15
-12
src/string.c
src/string.c
+15
-12
No files found.
src/string.c
View file @
7ce9cc3b
...
...
@@ -1868,11 +1868,12 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
int
argc
;
mrb_value
spat
=
mrb_nil_value
();
enum
{
awk
,
string
,
regexp
}
split_type
=
string
;
long
beg
,
end
,
i
=
0
;
mrb_int
lim
=
-
1
;
long
beg
,
end
,
i
=
0
,
lim_p
;
mrb_int
lim
=
0
;
mrb_value
result
,
tmp
;
argc
=
mrb_get_args
(
mrb
,
"|oi"
,
&
spat
,
&
lim
);
lim_p
=
(
lim
>
0
&&
argc
==
2
);
if
(
argc
==
2
)
{
if
(
lim
==
1
)
{
if
(
RSTRING_LEN
(
str
)
==
0
)
...
...
@@ -1917,7 +1918,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
else
{
end
=
ptr
-
bptr
;
skip
=
0
;
if
(
lim
>=
0
&&
lim
<=
i
)
break
;
if
(
lim
_p
&&
lim
<=
i
)
break
;
}
}
else
if
(
ascii_isspace
(
c
))
{
...
...
@@ -1925,7 +1926,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
mrb_gc_arena_restore
(
mrb
,
ai
);
skip
=
1
;
beg
=
ptr
-
bptr
;
if
(
lim
>=
0
)
++
i
;
if
(
lim
_p
)
++
i
;
}
else
{
end
=
ptr
-
bptr
;
...
...
@@ -1944,7 +1945,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
mrb_ary_push
(
mrb
,
result
,
mrb_str_subseq
(
mrb
,
str
,
ptr
-
temp
,
1
));
mrb_gc_arena_restore
(
mrb
,
ai
);
ptr
++
;
if
(
lim
>=
0
&&
lim
<=
++
i
)
break
;
if
(
lim
_p
&&
lim
<=
++
i
)
break
;
}
}
else
{
...
...
@@ -1956,7 +1957,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
mrb_ary_push
(
mrb
,
result
,
mrb_str_subseq
(
mrb
,
str
,
ptr
-
temp
,
end
));
mrb_gc_arena_restore
(
mrb
,
ai
);
ptr
+=
end
+
slen
;
if
(
lim
>=
0
&&
lim
<=
++
i
)
break
;
if
(
lim
_p
&&
lim
<=
++
i
)
break
;
}
}
beg
=
ptr
-
temp
;
...
...
@@ -1964,14 +1965,16 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
else
{
mrb_raise
(
mrb
,
E_NOTIMP_ERROR
,
"Regexp Class not implemented"
);
}
if
(
RSTRING_LEN
(
str
)
>
0
&&
(
lim
>=
0
||
RSTRING_LEN
(
str
)
>
beg
||
lim
<
0
))
{
if
(
RSTRING_LEN
(
str
)
==
beg
)
tmp
=
mrb_str_new_empty
(
mrb
,
str
);
else
tmp
=
mrb_str_subseq
(
mrb
,
str
,
beg
,
RSTRING_LEN
(
str
)
-
beg
);
if
(
RSTRING_LEN
(
str
)
>
0
&&
(
lim_p
||
RSTRING_LEN
(
str
)
>
beg
||
lim
<
0
))
{
if
(
RSTRING_LEN
(
str
)
==
beg
)
{
tmp
=
mrb_str_new_empty
(
mrb
,
str
);
}
else
{
tmp
=
mrb_str_subseq
(
mrb
,
str
,
beg
,
RSTRING_LEN
(
str
)
-
beg
);
}
mrb_ary_push
(
mrb
,
result
,
tmp
);
}
if
(
lim
<
0
)
{
if
(
!
lim_p
&&
lim
==
0
)
{
long
len
;
while
((
len
=
RARRAY_LEN
(
result
))
>
0
&&
(
tmp
=
RARRAY_PTR
(
result
)[
len
-
1
],
RSTRING_LEN
(
tmp
)
==
0
))
...
...
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