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
6bbdb97e
Unverified
Commit
6bbdb97e
authored
Sep 12, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Sep 12, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4527 from lopopolo/string-each-line-paragraph-mode
Add paragraph mode to String#each_line in mrblib
parents
b98bf36a
46c972f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
11 deletions
+36
-11
mrblib/string.rb
mrblib/string.rb
+36
-11
No files found.
mrblib/string.rb
View file @
6bbdb97e
...
...
@@ -11,18 +11,43 @@ class String
# and pass the respective line.
#
# ISO 15.2.10.5.15
def
each_line
(
rs
=
"
\n
"
,
&
block
)
return
to_enum
(
:each_line
,
rs
,
&
block
)
unless
block
return
block
.
call
(
self
)
if
rs
.
nil?
rs
.
__to_str
offset
=
0
rs_len
=
rs
.
length
this
=
dup
while
pos
=
this
.
index
(
rs
,
offset
)
block
.
call
(
this
[
offset
,
pos
+
rs_len
-
offset
])
offset
=
pos
+
rs_len
def
each_line
(
separator
=
"
\n
"
,
&
block
)
return
to_enum
(
:each_line
,
separator
)
unless
block
if
separator
.
nil?
block
.
call
(
self
)
return
self
end
raise
TypeError
unless
separator
.
is_a?
(
String
)
paragraph_mode
=
false
if
separator
.
empty?
paragraph_mode
=
true
separator
=
"
\n\n
"
end
start
=
0
string
=
dup
self_len
=
length
sep_len
=
separator
.
length
should_yield_subclass_instances
=
self
.
class
!=
String
while
(
pointer
=
string
.
index
(
separator
,
start
))
pointer
+=
sep_len
pointer
+=
1
while
paragraph_mode
&&
string
[
pointer
]
==
"
\n
"
if
should_yield_subclass_instances
block
.
call
(
self
.
class
.
new
(
string
[
start
,
pointer
-
start
]))
else
block
.
call
(
string
[
start
,
pointer
-
start
])
end
start
=
pointer
end
return
self
if
start
==
self_len
if
should_yield_subclass_instances
block
.
call
(
self
.
class
.
new
(
string
[
start
,
self_len
-
start
]))
else
block
.
call
(
string
[
start
,
self_len
-
start
])
end
block
.
call
(
this
[
offset
,
this
.
size
-
offset
])
if
this
.
size
>
offset
self
end
...
...
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