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
964a02f1
Commit
964a02f1
authored
Apr 29, 2017
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Apr 29, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3645 from nobu/sprintf-refactor
Sprintf refactor
parents
3c107837
ef6e14ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
36 deletions
+14
-36
mrbgems/mruby-sprintf/src/sprintf.c
mrbgems/mruby-sprintf/src/sprintf.c
+14
-36
No files found.
mrbgems/mruby-sprintf/src/sprintf.c
View file @
964a02f1
...
@@ -116,7 +116,6 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base)
...
@@ -116,7 +116,6 @@ mrb_fix2binstr(mrb_state *mrb, mrb_value x, int base)
#define CHECK(l) do {\
#define CHECK(l) do {\
/* int cr = ENC_CODERANGE(result);*/
\
/* int cr = ENC_CODERANGE(result);*/
\
if ((l) < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "illegal specifier"); \
while ((l) >= bsiz - blen) {\
while ((l) >= bsiz - blen) {\
bsiz*=2;\
bsiz*=2;\
if (bsiz < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "too big specifier"); \
if (bsiz < 0) mrb_raise(mrb, E_ARGUMENT_ERROR, "too big specifier"); \
...
@@ -716,21 +715,15 @@ retry:
...
@@ -716,21 +715,15 @@ retry:
c
=
RSTRING_PTR
(
tmp
);
c
=
RSTRING_PTR
(
tmp
);
n
=
RSTRING_LEN
(
tmp
);
n
=
RSTRING_LEN
(
tmp
);
if
(
!
(
flags
&
FWIDTH
))
{
if
(
!
(
flags
&
FWIDTH
))
{
CHECK
(
n
);
PUSH
(
c
,
n
);
memcpy
(
buf
+
blen
,
c
,
n
);
blen
+=
n
;
}
}
else
if
((
flags
&
FMINUS
))
{
else
if
((
flags
&
FMINUS
))
{
CHECK
(
n
);
PUSH
(
c
,
n
);
memcpy
(
buf
+
blen
,
c
,
n
);
blen
+=
n
;
if
(
width
>
0
)
FILL
(
' '
,
width
-
1
);
if
(
width
>
0
)
FILL
(
' '
,
width
-
1
);
}
}
else
{
else
{
if
(
width
>
0
)
FILL
(
' '
,
width
-
1
);
if
(
width
>
0
)
FILL
(
' '
,
width
-
1
);
CHECK
(
n
);
PUSH
(
c
,
n
);
memcpy
(
buf
+
blen
,
c
,
n
);
blen
+=
n
;
}
}
}
}
break
;
break
;
...
@@ -768,19 +761,11 @@ retry:
...
@@ -768,19 +761,11 @@ retry:
if
((
flags
&
FWIDTH
)
&&
(
width
>
slen
))
{
if
((
flags
&
FWIDTH
)
&&
(
width
>
slen
))
{
width
-=
(
int
)
slen
;
width
-=
(
int
)
slen
;
if
(
!
(
flags
&
FMINUS
))
{
if
(
!
(
flags
&
FMINUS
))
{
CHECK
(
width
);
FILL
(
' '
,
width
);
while
(
width
--
>
0
)
{
buf
[
blen
++
]
=
' '
;
}
}
}
CHECK
(
len
);
PUSH
(
RSTRING_PTR
(
str
),
len
);
memcpy
(
&
buf
[
blen
],
RSTRING_PTR
(
str
),
len
);
blen
+=
len
;
if
(
flags
&
FMINUS
)
{
if
(
flags
&
FMINUS
)
{
CHECK
(
width
);
FILL
(
' '
,
width
);
while
(
width
--
>
0
)
{
buf
[
blen
++
]
=
' '
;
}
}
}
break
;
break
;
}
}
...
@@ -986,10 +971,7 @@ retry:
...
@@ -986,10 +971,7 @@ retry:
}
}
if
(
!
(
flags
&
FMINUS
)
&&
width
>
0
)
{
if
(
!
(
flags
&
FMINUS
)
&&
width
>
0
)
{
CHECK
(
width
);
FILL
(
' '
,
width
);
while
(
width
--
>
0
)
{
buf
[
blen
++
]
=
' '
;
}
}
}
if
(
sc
)
PUSH
(
&
sc
,
1
);
if
(
sc
)
PUSH
(
&
sc
,
1
);
...
@@ -998,28 +980,20 @@ retry:
...
@@ -998,28 +980,20 @@ retry:
int
plen
=
(
int
)
strlen
(
prefix
);
int
plen
=
(
int
)
strlen
(
prefix
);
PUSH
(
prefix
,
plen
);
PUSH
(
prefix
,
plen
);
}
}
CHECK
(
prec
-
len
);
if
(
dots
)
PUSH
(
".."
,
2
);
if
(
dots
)
PUSH
(
".."
,
2
);
if
(
v
<
0
)
{
if
(
v
<
0
)
{
char
c
=
sign_bits
(
base
,
p
);
char
c
=
sign_bits
(
base
,
p
);
while
(
len
<
prec
--
)
{
FILL
(
c
,
prec
-
len
);
buf
[
blen
++
]
=
c
;
}
}
}
else
if
((
flags
&
(
FMINUS
|
FPREC
))
!=
FMINUS
)
{
else
if
((
flags
&
(
FMINUS
|
FPREC
))
!=
FMINUS
)
{
char
c
=
'0'
;
char
c
=
'0'
;
while
(
len
<
prec
--
)
{
FILL
(
c
,
prec
-
len
);
buf
[
blen
++
]
=
c
;
}
}
}
PUSH
(
s
,
len
);
PUSH
(
s
,
len
);
if
(
width
>
0
)
{
if
(
width
>
0
)
{
CHECK
(
width
);
FILL
(
' '
,
width
);
while
(
width
--
>
0
)
{
buf
[
blen
++
]
=
' '
;
}
}
}
}
}
break
;
break
;
...
@@ -1084,6 +1058,10 @@ retry:
...
@@ -1084,6 +1058,10 @@ retry:
if
((
flags
&
FWIDTH
)
&&
need
<
width
)
if
((
flags
&
FWIDTH
)
&&
need
<
width
)
need
=
width
;
need
=
width
;
need
+=
20
;
need
+=
20
;
if
(
need
<=
0
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
(
width
>
prec
?
"width too big"
:
"prec too big"
));
}
CHECK
(
need
);
CHECK
(
need
);
n
=
snprintf
(
&
buf
[
blen
],
need
,
fbuf
,
fval
);
n
=
snprintf
(
&
buf
[
blen
],
need
,
fbuf
,
fval
);
...
...
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