Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
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
fmt
Commits
eeca2235
Commit
eeca2235
authored
Jul 30, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle 'h' length specifier in printf.
parent
e4c4e4e9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
format.cc
format.cc
+25
-2
test/printf-test.cc
test/printf-test.cc
+6
-0
No files found.
format.cc
View file @
eeca2235
...
@@ -207,6 +207,27 @@ class PrecisionHandler :
...
@@ -207,6 +207,27 @@ class PrecisionHandler :
}
}
};
};
// Converts an integer argument to type T.
template
<
typename
T
>
class
ArgConverter
:
public
fmt
::
internal
::
ArgVisitor
<
ArgConverter
<
T
>
,
void
>
{
private:
fmt
::
internal
::
Arg
&
arg_
;
public:
explicit
ArgConverter
(
fmt
::
internal
::
Arg
&
arg
)
:
arg_
(
arg
)
{}
template
<
typename
U
>
void
visit_any_int
(
U
value
)
{
if
(
std
::
numeric_limits
<
U
>::
is_signed
)
{
arg_
.
type
=
fmt
::
internal
::
Arg
::
INT
;
arg_
.
int_value
=
static_cast
<
T
>
(
value
);
}
else
{
arg_
.
type
=
fmt
::
internal
::
Arg
::
UINT
;
arg_
.
uint_value
=
static_cast
<
T
>
(
value
);
}
}
};
// This function template is used to prevent compile errors when handling
// This function template is used to prevent compile errors when handling
// incompatible string arguments, e.g. handling a wide string in a narrow
// incompatible string arguments, e.g. handling a wide string in a narrow
// string formatter.
// string formatter.
...
@@ -859,7 +880,7 @@ void fmt::internal::PrintfFormatter<Char>::format(
...
@@ -859,7 +880,7 @@ void fmt::internal::PrintfFormatter<Char>::format(
}
}
}
}
const
Arg
&
arg
=
handle_arg_index
(
arg_index
);
Arg
arg
=
handle_arg_index
(
arg_index
);
if
(
spec
.
flag
(
HASH_FLAG
)
&&
IsZeroInt
().
visit
(
arg
))
if
(
spec
.
flag
(
HASH_FLAG
)
&&
IsZeroInt
().
visit
(
arg
))
spec
.
flags_
&=
~
HASH_FLAG
;
spec
.
flags_
&=
~
HASH_FLAG
;
if
(
spec
.
fill_
==
'0'
)
{
if
(
spec
.
fill_
==
'0'
)
{
...
@@ -872,7 +893,9 @@ void fmt::internal::PrintfFormatter<Char>::format(
...
@@ -872,7 +893,9 @@ void fmt::internal::PrintfFormatter<Char>::format(
// Parse length.
// Parse length.
switch
(
*
s
)
{
switch
(
*
s
)
{
case
'h'
:
case
'h'
:
// TODO: convert to short
++
s
;
ArgConverter
<
short
>
(
arg
).
visit
(
arg
);
break
;
case
'l'
:
case
'l'
:
case
'j'
:
case
'j'
:
case
'z'
:
case
'z'
:
...
...
test/printf-test.cc
View file @
eeca2235
...
@@ -273,6 +273,12 @@ TEST(PrintfTest, DynamicPrecision) {
...
@@ -273,6 +273,12 @@ TEST(PrintfTest, DynamicPrecision) {
}
}
TEST
(
PrintfTest
,
Length
)
{
TEST
(
PrintfTest
,
Length
)
{
EXPECT_PRINTF
(
"42"
,
"%hd"
,
42
);
char
buffer
[
BUFFER_SIZE
];
safe_sprintf
(
buffer
,
"%hd"
,
SHRT_MAX
+
1
);
EXPECT_PRINTF
(
buffer
,
"%hd"
,
SHRT_MAX
+
1
);
safe_sprintf
(
buffer
,
"%hd"
,
fmt
::
LongLong
(
SHRT_MAX
)
+
1
);
EXPECT_PRINTF
(
buffer
,
"%hd"
,
fmt
::
LongLong
(
SHRT_MAX
)
+
1
);
// TODO
// TODO
}
}
...
...
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