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
34f40b0a
Commit
34f40b0a
authored
Aug 11, 2014
by
mattn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix String#succ. "-".succ should be "."
parent
2b74fa54
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
9 deletions
+17
-9
mrbgems/mruby-string-ext/src/string.c
mrbgems/mruby-string-ext/src/string.c
+12
-5
mrbgems/mruby-string-ext/test/string.rb
mrbgems/mruby-string-ext/test/string.rb
+5
-4
No files found.
mrbgems/mruby-string-ext/src/string.c
View file @
34f40b0a
...
...
@@ -252,7 +252,8 @@ static mrb_value
mrb_str_succ_bang
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
result
;
char
*
p
,
*
e
,
*
b
,
*
t
,
*
prepend
;
unsigned
char
*
p
,
*
e
,
*
b
,
*
t
;
char
*
prepend
;
struct
RString
*
s
=
mrb_str_ptr
(
self
);
size_t
l
;
...
...
@@ -261,7 +262,7 @@ mrb_str_succ_bang(mrb_state *mrb, mrb_value self)
mrb_str_modify
(
mrb
,
s
);
l
=
RSTRING_LEN
(
self
);
b
=
p
=
RSTRING_PTR
(
self
);
b
=
p
=
(
unsigned
char
*
)
RSTRING_PTR
(
self
);
t
=
e
=
p
+
l
;
*
(
e
--
)
=
0
;
...
...
@@ -270,11 +271,17 @@ mrb_str_succ_bang(mrb_state *mrb, mrb_value self)
break
;
b
++
;
}
result
=
mrb_str_new
(
mrb
,
p
,
b
-
p
);
result
=
mrb_str_new
(
mrb
,
(
char
*
)
p
,
b
-
p
);
while
(
e
>=
b
)
{
if
(
!
ISALNUM
(
*
e
))
if
(
!
ISALNUM
(
*
e
))
{
if
(
*
e
==
0xff
)
{
mrb_str_cat_cstr
(
mrb
,
result
,
"
\x01
"
);
(
*
e
)
=
0
;
}
else
(
*
e
)
++
;
break
;
}
prepend
=
NULL
;
if
(
*
e
==
'9'
)
{
if
(
e
==
b
)
prepend
=
"1"
;
...
...
@@ -292,7 +299,7 @@ mrb_str_succ_bang(mrb_state *mrb, mrb_value self)
if
(
prepend
)
mrb_str_cat_cstr
(
mrb
,
result
,
prepend
);
e
--
;
}
result
=
mrb_str_cat
(
mrb
,
result
,
b
,
t
-
b
);
result
=
mrb_str_cat
(
mrb
,
result
,
(
char
*
)
b
,
t
-
b
);
l
=
RSTRING_LEN
(
result
);
mrb_str_resize
(
mrb
,
self
,
l
);
memcpy
(
RSTRING_PTR
(
self
),
RSTRING_PTR
(
result
),
l
);
...
...
mrbgems/mruby-string-ext/test/string.rb
View file @
34f40b0a
...
...
@@ -281,7 +281,8 @@ assert('String#succ') do
assert_equal
"bA"
,
"aZ"
.
succ
assert_equal
"1A"
,
"0Z"
.
succ
assert_equal
"-"
,
"-"
.
succ
assert_equal
"."
,
"-"
.
succ
assert_equal
"
\x01\x00
"
,
"
\xff
"
.
succ
assert_equal
"-b"
,
"-a"
.
succ
assert_equal
"-aa"
,
"-z"
.
succ
assert_equal
"あb"
,
"あa"
.
succ
...
...
@@ -341,13 +342,13 @@ assert('String#succ') do
assert_equal
"1A"
,
a
a
=
"-"
;
a
.
succ!
assert_equal
"-"
,
a
assert_equal
"."
,
a
a
=
"
\xff
"
;
a
.
succ!
assert_equal
"
\x01\x00
"
,
a
a
=
"-a"
;
a
.
succ!
assert_equal
"-b"
,
a
a
=
"-z"
;
a
.
succ!
assert_equal
"-aa"
,
a
a
=
"あ"
;
a
.
succ!
assert_equal
"あ"
,
a
a
=
"あa"
;
a
.
succ!
assert_equal
"あb"
,
a
a
=
"あaz"
;
a
.
succ!
...
...
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