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
dc25f85b
Commit
dc25f85b
authored
Jan 07, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mruby-string-utf8: UTF-8 string may contail NUL; #1646
parent
0f7d771a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
9 deletions
+13
-9
mrbgems/mruby-string-ext/test/string.rb
mrbgems/mruby-string-ext/test/string.rb
+1
-2
mrbgems/mruby-string-utf8/src/string.c
mrbgems/mruby-string-utf8/src/string.c
+12
-7
No files found.
mrbgems/mruby-string-ext/test/string.rb
View file @
dc25f85b
...
@@ -21,7 +21,6 @@ end
...
@@ -21,7 +21,6 @@ end
assert
(
'String#strip'
)
do
assert
(
'String#strip'
)
do
s
=
" abc "
s
=
" abc "
s
.
strip
""
.
strip
==
""
and
"
\t\r\n\f\v
"
.
strip
==
""
and
""
.
strip
==
""
and
"
\t\r\n\f\v
"
.
strip
==
""
and
"
\0
a
\0
"
.
strip
==
"
\0
a"
and
"
\0
a
\0
"
.
strip
==
"
\0
a"
and
"abc"
.
strip
==
"abc"
and
"abc"
.
strip
==
"abc"
and
...
...
mrbgems/mruby-string-utf8/src/string.c
View file @
dc25f85b
...
@@ -26,7 +26,7 @@ utf8len(unsigned char* p)
...
@@ -26,7 +26,7 @@ utf8len(unsigned char* p)
int
i
;
int
i
;
if
(
*
p
==
0
)
if
(
*
p
==
0
)
return
0
;
return
1
;
len
=
utf8len_tab
[
*
p
];
len
=
utf8len_tab
[
*
p
];
for
(
i
=
1
;
i
<
len
;
++
i
)
for
(
i
=
1
;
i
<
len
;
++
i
)
if
((
p
[
i
]
&
0xc0
)
!=
0x80
)
if
((
p
[
i
]
&
0xc0
)
!=
0x80
)
...
@@ -39,7 +39,8 @@ mrb_utf8_strlen(mrb_value str)
...
@@ -39,7 +39,8 @@ mrb_utf8_strlen(mrb_value str)
{
{
size_t
total
=
0
;
size_t
total
=
0
;
unsigned
char
*
p
=
(
unsigned
char
*
)
RSTRING_PTR
(
str
);
unsigned
char
*
p
=
(
unsigned
char
*
)
RSTRING_PTR
(
str
);
while
(
*
p
)
{
unsigned
char
*
e
=
p
+
RSTRING_LEN
(
str
);
while
(
p
<
e
)
{
p
+=
utf8len
(
p
);
p
+=
utf8len
(
p
);
total
++
;
total
++
;
}
}
...
@@ -110,11 +111,14 @@ str_subseq(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
...
@@ -110,11 +111,14 @@ str_subseq(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
{
{
int
i
;
int
i
;
unsigned
char
*
p
=
(
unsigned
char
*
)
RSTRING_PTR
(
str
),
*
t
;
unsigned
char
*
p
=
(
unsigned
char
*
)
RSTRING_PTR
(
str
),
*
t
;
for
(
i
=
0
;
i
<
beg
&&
*
p
;
i
++
)
{
unsigned
char
*
e
=
p
+
RSTRING_LEN
(
str
);
for
(
i
=
0
;
i
<
beg
&&
p
<
e
;
i
++
)
{
p
+=
utf8len
(
p
);
p
+=
utf8len
(
p
);
}
}
t
=
p
;
t
=
p
;
for
(
i
=
0
;
i
<
len
&&
*
p
;
i
++
)
{
for
(
i
=
0
;
i
<
len
&&
t
<
e
;
i
++
)
{
t
+=
utf8len
(
t
);
t
+=
utf8len
(
t
);
}
}
return
mrb_str_new
(
mrb
,
(
const
char
*
)
p
,
(
int
)(
t
-
p
));
return
mrb_str_new
(
mrb
,
(
const
char
*
)
p
,
(
int
)(
t
-
p
));
...
@@ -129,7 +133,8 @@ str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
...
@@ -129,7 +133,8 @@ str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len)
if
(
len
<
0
)
return
mrb_nil_value
();
if
(
len
<
0
)
return
mrb_nil_value
();
if
(
len8
==
0
)
{
if
(
len8
==
0
)
{
len
=
0
;
len
=
0
;
}
else
if
(
beg
<
0
)
{
}
else
if
(
beg
<
0
)
{
beg
=
len8
+
beg
;
beg
=
len8
+
beg
;
}
}
if
(
beg
>
len8
)
return
mrb_nil_value
();
if
(
beg
>
len8
)
return
mrb_nil_value
();
...
...
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