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
27013125
Commit
27013125
authored
Apr 27, 2019
by
KOBAYASHI Shuji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplicated `String#each_char`
parent
2b0135e8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
24 deletions
+16
-24
mrbgems/mruby-io/test/io.rb
mrbgems/mruby-io/test/io.rb
+2
-2
mrbgems/mruby-method/test/method.rb
mrbgems/mruby-method/test/method.rb
+1
-1
mrbgems/mruby-string-ext/mrblib/string.rb
mrbgems/mruby-string-ext/mrblib/string.rb
+7
-3
mrbgems/mruby-string-ext/test/string.rb
mrbgems/mruby-string-ext/test/string.rb
+6
-6
mrblib/string.rb
mrblib/string.rb
+0
-12
No files found.
mrbgems/mruby-io/test/io.rb
View file @
27013125
...
...
@@ -84,7 +84,7 @@ end
assert
(
'IO#getc'
,
'15.2.20.5.8'
)
do
io
=
IO
.
new
(
IO
.
sysopen
(
$mrbtest_io_rfname
))
$mrbtest_io_msg
.
each_char
{
|
ch
|
$mrbtest_io_msg
.
split
(
""
).
each
{
|
ch
|
assert_equal
ch
,
io
.
getc
}
assert_equal
nil
,
io
.
getc
...
...
@@ -127,7 +127,7 @@ end
assert
(
'IO#readchar'
,
'15.2.20.5.15'
)
do
# almost same as IO#getc
IO
.
open
(
IO
.
sysopen
(
$mrbtest_io_rfname
))
do
|
io
|
$mrbtest_io_msg
.
each_char
{
|
ch
|
$mrbtest_io_msg
.
split
(
""
).
each
{
|
ch
|
assert_equal
ch
,
io
.
readchar
}
assert_raise
(
EOFError
)
do
...
...
mrbgems/mruby-method/test/method.rb
View file @
27013125
...
...
@@ -21,7 +21,7 @@ class Interpreter
}
def
interpret
(
string
)
@ret
=
""
string
.
each_char
{
|
b
|
Dispatcher
[
b
].
bind
(
self
).
call
}
string
.
split
(
""
).
each
{
|
b
|
Dispatcher
[
b
].
bind
(
self
).
call
}
end
end
...
...
mrbgems/mruby-string-ext/mrblib/string.rb
View file @
27013125
...
...
@@ -310,11 +310,15 @@ class String
end
end
##
# Call the given block for each character of
# +self+.
def
each_char
(
&
block
)
return
to_enum
:each_char
unless
block
split
(
''
).
each
do
|
i
|
block
.
call
(
i
)
pos
=
0
while
pos
<
self
.
size
block
.
call
(
self
[
pos
])
pos
+=
1
end
self
end
...
...
mrbgems/mruby-string-ext/test/string.rb
View file @
27013125
...
...
@@ -657,19 +657,19 @@ assert('String#chars(UTF-8)') do
end
if
UTF8STRING
assert
(
'String#each_char'
)
do
s
=
""
chars
=
[]
"hello!"
.
each_char
do
|
x
|
s
+=
x
chars
<<
x
end
assert_equal
"hello!"
,
s
assert_equal
[
"h"
,
"e"
,
"l"
,
"l"
,
"o"
,
"!"
],
char
s
end
assert
(
'String#each_char(UTF-8)'
)
do
s
=
""
chars
=
[]
"こんにちは世界!"
.
each_char
do
|
x
|
s
+=
x
chars
<<
x
end
assert_equal
"こんにちは世界!"
,
s
assert_equal
[
"こ"
,
"ん"
,
"に"
,
"ち"
,
"は"
,
"世"
,
"界"
,
"!"
],
char
s
end
if
UTF8STRING
assert
(
'String#codepoints'
)
do
...
...
mrblib/string.rb
View file @
27013125
...
...
@@ -164,18 +164,6 @@ class String
self
.
replace
(
str
)
end
##
# Call the given block for each character of
# +self+.
def
each_char
(
&
block
)
pos
=
0
while
pos
<
self
.
size
block
.
call
(
self
[
pos
])
pos
+=
1
end
self
end
##
# Call the given block for each byte of +self+.
def
each_byte
(
&
block
)
...
...
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