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
cb76ed8e
Commit
cb76ed8e
authored
9 years ago
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2971 from mattn/utf8-chop
chop with utf-8. fix #2967
parents
74457868
7ad75a4a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
src/string.c
src/string.c
+11
-0
test/t/string.rb
test/t/string.rb
+25
-0
No files found.
src/string.c
View file @
cb76ed8e
...
...
@@ -1318,7 +1318,18 @@ mrb_str_chop_bang(mrb_state *mrb, mrb_value str)
mrb_str_modify
(
mrb
,
s
);
if
(
RSTR_LEN
(
s
)
>
0
)
{
mrb_int
len
;
#ifdef MRB_UTF8_STRING
const
char
*
t
=
RSTR_PTR
(
s
),
*
p
=
t
;
const
char
*
e
=
p
+
RSTR_LEN
(
s
);
while
(
p
<
e
)
{
mrb_int
clen
=
utf8len
(
p
,
e
);
if
(
p
+
clen
>=
e
)
break
;
p
+=
clen
;
}
len
=
p
-
t
;
#else
len
=
RSTR_LEN
(
s
)
-
1
;
#endif
if
(
RSTR_PTR
(
s
)[
len
]
==
'\n'
)
{
if
(
len
>
0
&&
RSTR_PTR
(
s
)[
len
-
1
]
==
'\r'
)
{
...
...
This diff is collapsed.
Click to expand it.
test/t/string.rb
View file @
cb76ed8e
...
...
@@ -262,6 +262,16 @@ assert('String#chop', '15.2.10.5.11') do
assert_equal
'abc'
,
c
end
assert
(
'String#chop'
,
'15.2.10.5.11'
)
do
a
=
''
.
chop
b
=
'あいう'
.
chop
c
=
"あ
\n
い"
.
chop
.
chop
assert_equal
''
,
a
assert_equal
'あい'
,
b
assert_equal
'あ'
,
c
end
if
UTF8STRING
assert
(
'String#chop!'
,
'15.2.10.5.12'
)
do
a
=
''
b
=
'abc'
...
...
@@ -273,6 +283,21 @@ assert('String#chop!', '15.2.10.5.12') do
assert_equal
b
,
'ab'
end
assert
(
'String#chop!'
,
'15.2.10.5.12'
)
do
a
=
''
b
=
"あいうえ
\n
"
c
=
"あいうえ
\n
"
a
.
chop!
b
.
chop!
c
.
chop!
c
.
chop!
assert_equal
a
,
''
assert_equal
b
,
'あいうえ'
assert_equal
c
,
'あいう'
end
if
UTF8STRING
assert
(
'String#downcase'
,
'15.2.10.5.13'
)
do
a
=
'ABC'
.
downcase
b
=
'ABC'
...
...
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