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
be20e999
Commit
be20e999
authored
May 03, 2012
by
Daniel Bovensiepen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add documentation to String
parent
1032e9ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
9 deletions
+55
-9
mrblib/string.rb
mrblib/string.rb
+55
-9
No files found.
mrblib/string.rb
View file @
be20e999
##
# String
#
#
# String
# ISO 15.2.10
#
class
String
class
String
# 15.2.10.5.15
##
# Calls the given block for each line
# and pass the respective line.
#
# ISO 15.2.10.5.15
def
each_line
(
&
block
)
def
each_line
(
&
block
)
# expect that str.index accepts an Integer for 1st argument as a byte data
# expect that str.index accepts an Integer for 1st argument as a byte data
offset
=
0
offset
=
0
...
@@ -14,7 +20,13 @@ class String
...
@@ -14,7 +20,13 @@ class String
self
self
end
end
# 15.2.10.5.18
##
# Replace all matches of +pattern+ with +replacement+.
# Call block (if given) for each match and replace
# +pattern+ with the value of the block. Return the
# final value.
#
# ISO 15.2.10.5.18
def
gsub
(
*
args
,
&
block
)
def
gsub
(
*
args
,
&
block
)
unless
(
args
.
size
==
1
&&
block
)
||
args
.
size
==
2
unless
(
args
.
size
==
1
&&
block
)
||
args
.
size
==
2
raise
ArgumentError
,
"wrong number of arguments"
raise
ArgumentError
,
"wrong number of arguments"
...
@@ -23,7 +35,13 @@ class String
...
@@ -23,7 +35,13 @@ class String
### *** TODO *** ###
### *** TODO *** ###
end
end
# 15.2.10.5.19
##
# Replace all matches of +pattern+ with +replacement+.
# Call block (if given) for each match and replace
# +pattern+ with the value of the block. Modify
# +self+ with the final value.
#
# ISO 15.2.10.5.19
def
gsub!
(
*
args
,
&
block
)
def
gsub!
(
*
args
,
&
block
)
str
=
self
.
gsub
(
*
args
,
&
block
)
str
=
self
.
gsub
(
*
args
,
&
block
)
if
str
!=
self
if
str
!=
self
...
@@ -34,12 +52,23 @@ class String
...
@@ -34,12 +52,23 @@ class String
end
end
end
end
# 15.2.10.5.32
##
# Calls the given block for each match of +pattern+
# If no block is given return an array with all
# matches of +pattern+.
#
# ISO 15.2.10.5.32
def
scan
(
reg
,
&
block
)
def
scan
(
reg
,
&
block
)
### *** TODO *** ###
### *** TODO *** ###
end
end
# 15.2.10.5.36
##
# Replace only the first match of +pattern+ with
# +replacement+. Call block (if given) for each
# match and replace +pattern+ with the value of the
# block. Return the final value.
#
# ISO 15.2.10.5.36
def
sub
(
*
args
,
&
block
)
def
sub
(
*
args
,
&
block
)
unless
(
args
.
size
==
1
&&
block
)
||
args
.
size
==
2
unless
(
args
.
size
==
1
&&
block
)
||
args
.
size
==
2
raise
ArgumentError
,
"wrong number of arguments"
raise
ArgumentError
,
"wrong number of arguments"
...
@@ -48,7 +77,13 @@ class String
...
@@ -48,7 +77,13 @@ class String
### *** TODO *** ###
### *** TODO *** ###
end
end
# 15.2.10.5.37
##
# Replace only the first match of +pattern+ with
# +replacement+. Call block (if given) for each
# match and replace +pattern+ with the value of the
# block. Modify +self+ with the final value.
#
# ISO 15.2.10.5.37
def
sub!
(
*
args
,
&
block
)
def
sub!
(
*
args
,
&
block
)
str
=
self
.
sub
(
*
args
,
&
block
)
str
=
self
.
sub
(
*
args
,
&
block
)
if
str
!=
self
if
str
!=
self
...
@@ -59,6 +94,9 @@ class String
...
@@ -59,6 +94,9 @@ class String
end
end
end
end
##
# Call the given block for each character of
# +self+.
def
each_char
(
&
block
)
def
each_char
(
&
block
)
pos
=
0
pos
=
0
while
(
pos
<
self
.
size
)
while
(
pos
<
self
.
size
)
...
@@ -68,6 +106,8 @@ class String
...
@@ -68,6 +106,8 @@ class String
self
self
end
end
##
# Call the given block for each byte of +self+.
def
each_byte
(
&
block
)
def
each_byte
(
&
block
)
bytes
=
self
.
unpack
(
"C*"
)
bytes
=
self
.
unpack
(
"C*"
)
pos
=
0
pos
=
0
...
@@ -78,6 +118,9 @@ class String
...
@@ -78,6 +118,9 @@ class String
self
self
end
end
##
# Modify +self+ by replacing the content of +self+
# at the position +pos+ with +value+.
def
[]=
(
pos
,
value
)
def
[]=
(
pos
,
value
)
b
=
self
[
0
,
pos
]
b
=
self
[
0
,
pos
]
a
=
self
[
pos
+
1
..-
1
]
a
=
self
[
pos
+
1
..-
1
]
...
@@ -86,7 +129,10 @@ class String
...
@@ -86,7 +129,10 @@ class String
end
end
end
end
# include modules
##
# String is comparable
#
# ISO 15.2.10.3
module
Comparable
;
end
module
Comparable
;
end
class
String
class
String
include
Comparable
include
Comparable
...
...
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