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
2d5943b6
Commit
2d5943b6
authored
Aug 11, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2524 from mattn/fix-succ
Fix String#succ. "-".succ should be "."
parents
4c0f40f6
4ece1e3e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
12 deletions
+44
-12
mrbgems/mruby-string-ext/src/string.c
mrbgems/mruby-string-ext/src/string.c
+30
-8
mrbgems/mruby-string-ext/test/string.rb
mrbgems/mruby-string-ext/test/string.rb
+14
-4
No files found.
mrbgems/mruby-string-ext/src/string.c
View file @
2d5943b6
...
...
@@ -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,20 +262,41 @@ 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
;
while
(
b
<
e
)
{
if
(
ISALNUM
(
*
b
))
// find trailing ascii/number
while
(
e
>=
b
)
{
if
(
ISALNUM
(
*
e
))
break
;
b
++
;
e
--
;
}
if
(
e
<
b
)
{
e
=
p
+
l
-
1
;
result
=
mrb_str_new_lit
(
mrb
,
""
);
}
else
{
// find leading letter of the ascii/number
b
=
e
;
while
(
b
>
p
)
{
if
(
!
ISALNUM
(
*
b
)
||
(
ISALNUM
(
*
b
)
&&
*
b
!=
'9'
&&
*
b
!=
'z'
&&
*
b
!=
'Z'
))
break
;
b
--
;
}
if
(
!
ISALNUM
(
*
b
))
b
++
;
result
=
mrb_str_new
(
mrb
,
(
char
*
)
p
,
b
-
p
);
}
result
=
mrb_str_new
(
mrb
,
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 +314,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 @
2d5943b6
...
...
@@ -281,9 +281,13 @@ 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
"-a-b-"
,
"-a-a-"
.
succ
assert_equal
"-b-"
,
"-a-"
.
succ
assert_equal
"-aa-"
,
"-z-"
.
succ
assert_equal
"あb"
,
"あa"
.
succ
assert_equal
"あba"
,
"あaz"
.
succ
...
...
@@ -341,13 +345,19 @@ 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-"
;
a
.
succ!
assert_equal
"-a-b-"
,
a
a
=
"-a-"
;
a
.
succ!
assert_equal
"-b-"
,
a
a
=
"-z-"
;
a
.
succ!
assert_equal
"-aa-"
,
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