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
c845798b
Commit
c845798b
authored
Dec 30, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1625 from iij/pr-string-partition
add String#partition and String#rpartition.
parents
70d6d04c
120a02c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
mrbgems/mruby-string-ext/mrblib/string.rb
mrbgems/mruby-string-ext/mrblib/string.rb
+22
-0
mrbgems/mruby-string-ext/test/string.rb
mrbgems/mruby-string-ext/test/string.rb
+20
-0
No files found.
mrbgems/mruby-string-ext/mrblib/string.rb
View file @
c845798b
...
@@ -49,4 +49,26 @@ class String
...
@@ -49,4 +49,26 @@ class String
def
casecmp
(
str
)
def
casecmp
(
str
)
self
.
downcase
<=>
str
.
downcase
self
.
downcase
<=>
str
.
downcase
end
end
def
partition
(
sep
)
raise
TypeError
,
"type mismatch:
#{
sep
.
class
}
given"
unless
sep
.
is_a?
String
n
=
index
(
sep
)
unless
n
.
nil?
m
=
n
+
sep
.
size
[
slice
(
0
,
n
),
sep
,
slice
(
m
,
size
-
m
)
]
else
[
self
,
""
,
""
]
end
end
def
rpartition
(
sep
)
raise
TypeError
,
"type mismatch:
#{
sep
.
class
}
given"
unless
sep
.
is_a?
String
n
=
rindex
(
sep
)
unless
n
.
nil?
m
=
n
+
sep
.
size
[
slice
(
0
,
n
),
sep
,
slice
(
m
,
size
-
m
)
]
else
[
""
,
""
,
self
]
end
end
end
end
mrbgems/mruby-string-ext/test/string.rb
View file @
c845798b
...
@@ -114,3 +114,23 @@ assert('String#end_with?') do
...
@@ -114,3 +114,23 @@ assert('String#end_with?') do
assert_true
!
"ng"
.
end_with?
(
"ing"
,
"mng"
)
assert_true
!
"ng"
.
end_with?
(
"ing"
,
"mng"
)
assert_raise
TypeError
do
"hello"
.
end_with?
(
true
)
end
assert_raise
TypeError
do
"hello"
.
end_with?
(
true
)
end
end
end
assert
(
'String#partition'
)
do
assert_equal
[
"a"
,
"x"
,
"axa"
],
"axaxa"
.
partition
(
"x"
)
assert_equal
[
"aaaaa"
,
""
,
""
],
"aaaaa"
.
partition
(
"x"
)
assert_equal
[
""
,
""
,
"aaaaa"
],
"aaaaa"
.
partition
(
""
)
assert_equal
[
""
,
"a"
,
"aaaa"
],
"aaaaa"
.
partition
(
"a"
)
assert_equal
[
"aaaa"
,
"b"
,
""
],
"aaaab"
.
partition
(
"b"
)
assert_equal
[
""
,
"b"
,
"aaaa"
],
"baaaa"
.
partition
(
"b"
)
assert_equal
[
""
,
""
,
""
],
""
.
partition
(
"a"
)
end
assert
(
'String#rpartition'
)
do
assert_equal
[
"axa"
,
"x"
,
"a"
],
"axaxa"
.
rpartition
(
"x"
)
assert_equal
[
""
,
""
,
"aaaaa"
],
"aaaaa"
.
rpartition
(
"x"
)
assert_equal
[
"aaaaa"
,
""
,
""
],
"aaaaa"
.
rpartition
(
""
)
assert_equal
[
"aaaa"
,
"a"
,
""
],
"aaaaa"
.
rpartition
(
"a"
)
assert_equal
[
"aaaa"
,
"b"
,
""
],
"aaaab"
.
rpartition
(
"b"
)
assert_equal
[
""
,
"b"
,
"aaaa"
],
"baaaa"
.
rpartition
(
"b"
)
assert_equal
[
""
,
""
,
""
],
""
.
rpartition
(
"a"
)
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