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
9ecebebf
Commit
9ecebebf
authored
Mar 16, 2017
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Mar 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3510 from ksss/string-each_line
Some update for `String#each_line`
parents
47cc5d66
4ee79a87
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
+16
-5
mrblib/string.rb
mrblib/string.rb
+10
-5
test/t/string.rb
test/t/string.rb
+6
-0
No files found.
mrblib/string.rb
View file @
9ecebebf
...
@@ -9,13 +9,18 @@ class String
...
@@ -9,13 +9,18 @@ class String
# and pass the respective line.
# and pass the respective line.
#
#
# ISO 15.2.10.5.15
# ISO 15.2.10.5.15
def
each_line
(
&
block
)
def
each_line
(
rs
=
"
\n
"
,
&
block
)
return
to_enum
(
:each_line
,
rs
,
&
block
)
unless
block
return
block
.
call
(
self
)
if
rs
.
nil?
rs
=
rs
.
to_str
offset
=
0
offset
=
0
while
pos
=
self
.
index
(
"
\n
"
,
offset
)
rs_len
=
rs
.
length
block
.
call
(
self
[
offset
,
pos
+
1
-
offset
])
this
=
dup
offset
=
pos
+
1
while
pos
=
this
.
index
(
rs
,
offset
)
block
.
call
(
this
[
offset
,
pos
+
rs_len
-
offset
])
offset
=
pos
+
rs_len
end
end
block
.
call
(
self
[
offset
,
self
.
size
-
offset
])
if
self
.
size
>
offset
block
.
call
(
this
[
offset
,
this
.
size
-
offset
])
if
this
.
size
>
offset
self
self
end
end
...
...
test/t/string.rb
View file @
9ecebebf
...
@@ -341,6 +341,12 @@ assert('String#each_line', '15.2.10.5.15') do
...
@@ -341,6 +341,12 @@ assert('String#each_line', '15.2.10.5.15') do
end
end
assert_equal
list
,
n_list
assert_equal
list
,
n_list
n_list
.
clear
a
.
each_line
(
"li"
)
do
|
line
|
n_list
<<
line
end
assert_equal
[
"first li"
,
"ne
\n
second li"
,
"ne
\n
third li"
,
"ne"
],
n_list
end
end
assert
(
'String#empty?'
,
'15.2.10.5.16'
)
do
assert
(
'String#empty?'
,
'15.2.10.5.16'
)
do
...
...
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