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
90d0c50e
Commit
90d0c50e
authored
Feb 20, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix formatting of integer types smaller than int in FormatDec.
parent
2f423d8b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
8 deletions
+13
-8
format-test.cc
format-test.cc
+5
-0
format.h
format.h
+8
-8
No files found.
format-test.cc
View file @
90d0c50e
...
@@ -1454,6 +1454,11 @@ std::string FormatDec(T value) {
...
@@ -1454,6 +1454,11 @@ std::string FormatDec(T value) {
}
}
TEST
(
FormatIntTest
,
FormatDec
)
{
TEST
(
FormatIntTest
,
FormatDec
)
{
EXPECT_EQ
(
"-42"
,
FormatDec
(
static_cast
<
char
>
(
-
42
)));
EXPECT_EQ
(
"-42"
,
FormatDec
(
static_cast
<
short
>
(
-
42
)));
std
::
ostringstream
os
;
os
<<
std
::
numeric_limits
<
unsigned
short
>::
max
();
EXPECT_EQ
(
os
.
str
(),
FormatDec
(
std
::
numeric_limits
<
unsigned
short
>::
max
()));
EXPECT_EQ
(
"42"
,
FormatDec
(
42
));
EXPECT_EQ
(
"42"
,
FormatDec
(
42
));
EXPECT_EQ
(
"-42"
,
FormatDec
(
-
42
));
EXPECT_EQ
(
"-42"
,
FormatDec
(
-
42
));
EXPECT_EQ
(
"42"
,
FormatDec
(
42l
));
EXPECT_EQ
(
"42"
,
FormatDec
(
42l
));
...
...
format.h
View file @
90d0c50e
...
@@ -229,8 +229,6 @@ struct IntTraitsBase {
...
@@ -229,8 +229,6 @@ struct IntTraitsBase {
};
};
// Information about an integer type.
// Information about an integer type.
// IntTraits is not specialized for integer types smaller than int,
// since these are promoted to int.
template
<
typename
T
>
template
<
typename
T
>
struct
IntTraits
:
IntTraitsBase
<
T
>
{
struct
IntTraits
:
IntTraitsBase
<
T
>
{
typedef
T
UnsignedType
;
typedef
T
UnsignedType
;
...
@@ -243,11 +241,14 @@ struct SignedIntTraits : IntTraitsBase<T> {
...
@@ -243,11 +241,14 @@ struct SignedIntTraits : IntTraitsBase<T> {
static
bool
IsNegative
(
T
value
)
{
return
value
<
0
;
}
static
bool
IsNegative
(
T
value
)
{
return
value
<
0
;
}
};
};
template
<
>
#define FMT_INT_TRAIT(Type) \
struct
IntTraits
<
int
>
:
SignedIntTraits
<
int
,
unsigned
>
{};
template <> \
struct IntTraits<Type> : SignedIntTraits<Type, unsigned Type> {};
template
<
>
FMT_INT_TRAIT
(
char
)
struct
IntTraits
<
long
>
:
SignedIntTraits
<
long
,
unsigned
long
>
{};
FMT_INT_TRAIT
(
short
)
FMT_INT_TRAIT
(
int
)
FMT_INT_TRAIT
(
long
)
template
<
>
template
<
>
struct
IntTraits
<
LongLong
>
:
SignedIntTraits
<
LongLong
,
ULongLong
>
{};
struct
IntTraits
<
LongLong
>
:
SignedIntTraits
<
LongLong
,
ULongLong
>
{};
...
@@ -1407,8 +1408,7 @@ class FormatInt {
...
@@ -1407,8 +1408,7 @@ class FormatInt {
// write a terminating null character.
// write a terminating null character.
template
<
typename
T
>
template
<
typename
T
>
inline
void
FormatDec
(
char
*&
buffer
,
T
value
)
{
inline
void
FormatDec
(
char
*&
buffer
,
T
value
)
{
typedef
typename
internal
::
IntTraits
<
T
>::
MainType
UnsignedType
;
typename
internal
::
IntTraits
<
T
>::
MainType
abs_value
=
value
;
UnsignedType
abs_value
=
value
;
if
(
internal
::
IntTraits
<
T
>::
IsNegative
(
value
))
{
if
(
internal
::
IntTraits
<
T
>::
IsNegative
(
value
))
{
*
buffer
++
=
'-'
;
*
buffer
++
=
'-'
;
abs_value
=
0
-
abs_value
;
abs_value
=
0
-
abs_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