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
b4d50175
Commit
b4d50175
authored
8 years ago
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
8 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3288 from bouk/chomp-bang-len
Get String length after args in String#chomp!
parents
54921aa6
76a1bdfa
master
mruby2-draft
removing-y-tab-c
revert-5391-throw
stable
3.1.0-rc
3.0.0
3.0.0-rc
3.0.0-preview
2.1.2
2.1.2-rc2
2.1.2-rc
2.1.1
2.1.1-rc2
2.1.1-rc
2.1.0
2.1.0-rc
2.0.1
2.0.0
1.4.1
1.4.0
1.3.0
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
src/string.c
src/string.c
+3
-1
test/t/string.rb
test/t/string.rb
+13
-1
No files found.
src/string.c
View file @
b4d50175
...
@@ -1235,11 +1235,13 @@ mrb_str_chomp_bang(mrb_state *mrb, mrb_value str)
...
@@ -1235,11 +1235,13 @@ mrb_str_chomp_bang(mrb_state *mrb, mrb_value str)
char
*
p
,
*
pp
;
char
*
p
,
*
pp
;
mrb_int
rslen
;
mrb_int
rslen
;
mrb_int
len
;
mrb_int
len
;
mrb_int
argc
;
struct
RString
*
s
=
mrb_str_ptr
(
str
);
struct
RString
*
s
=
mrb_str_ptr
(
str
);
mrb_str_modify
(
mrb
,
s
);
mrb_str_modify
(
mrb
,
s
);
argc
=
mrb_get_args
(
mrb
,
"|S"
,
&
rs
);
len
=
RSTR_LEN
(
s
);
len
=
RSTR_LEN
(
s
);
if
(
mrb_get_args
(
mrb
,
"|S"
,
&
rs
)
==
0
)
{
if
(
argc
==
0
)
{
if
(
len
==
0
)
return
mrb_nil_value
();
if
(
len
==
0
)
return
mrb_nil_value
();
smart_chomp:
smart_chomp:
if
(
RSTR_PTR
(
s
)[
len
-
1
]
==
'\n'
)
{
if
(
RSTR_PTR
(
s
)[
len
-
1
]
==
'\n'
)
{
...
...
This diff is collapsed.
Click to expand it.
test/t/string.rb
View file @
b4d50175
...
@@ -251,6 +251,19 @@ assert('String#chomp!', '15.2.10.5.10') do
...
@@ -251,6 +251,19 @@ assert('String#chomp!', '15.2.10.5.10') do
assert_equal
'abc'
,
e
assert_equal
'abc'
,
e
end
end
assert
(
'String#chomp! uses the correct length'
)
do
class
A
def
to_str
$s
.
replace
(
"AA"
)
"A"
end
end
$s
=
"AAA"
$s
.
chomp!
(
A
.
new
)
assert_equal
$s
,
"A"
end
assert
(
'String#chop'
,
'15.2.10.5.11'
)
do
assert
(
'String#chop'
,
'15.2.10.5.11'
)
do
a
=
''
.
chop
a
=
''
.
chop
b
=
'abc'
.
chop
b
=
'abc'
.
chop
...
@@ -683,4 +696,3 @@ assert('String#freeze') do
...
@@ -683,4 +696,3 @@ assert('String#freeze') do
assert_raise
(
RuntimeError
)
{
str
.
upcase!
}
assert_raise
(
RuntimeError
)
{
str
.
upcase!
}
end
end
This diff is collapsed.
Click to expand it.
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