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
d9ebc4e8
Commit
d9ebc4e8
authored
Sep 11, 2021
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a function to get sign char
parent
c00eb4f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
9 deletions
+15
-9
include/fmt/format-inl.h
include/fmt/format-inl.h
+0
-1
include/fmt/format.h
include/fmt/format.h
+15
-8
No files found.
include/fmt/format-inl.h
View file @
d9ebc4e8
...
@@ -152,7 +152,6 @@ template <> FMT_FUNC int count_digits<4>(detail::fallback_uintptr n) {
...
@@ -152,7 +152,6 @@ template <> FMT_FUNC int count_digits<4>(detail::fallback_uintptr n) {
#if __cplusplus < 201703L
#if __cplusplus < 201703L
template
<
typename
T
>
constexpr
const
char
basic_data
<
T
>::
digits
[][
2
];
template
<
typename
T
>
constexpr
const
char
basic_data
<
T
>::
digits
[][
2
];
template
<
typename
T
>
constexpr
const
char
basic_data
<
T
>::
hex_digits
[];
template
<
typename
T
>
constexpr
const
char
basic_data
<
T
>::
hex_digits
[];
template
<
typename
T
>
constexpr
const
char
basic_data
<
T
>::
signs
[];
template
<
typename
T
>
constexpr
const
unsigned
basic_data
<
T
>::
prefixes
[];
template
<
typename
T
>
constexpr
const
unsigned
basic_data
<
T
>::
prefixes
[];
#endif
#endif
...
...
include/fmt/format.h
View file @
d9ebc4e8
...
@@ -909,7 +909,6 @@ template <typename T = void> struct basic_data {
...
@@ -909,7 +909,6 @@ template <typename T = void> struct basic_data {
{
'9'
,
'6'
},
{
'9'
,
'7'
},
{
'9'
,
'8'
},
{
'9'
,
'9'
}};
{
'9'
,
'6'
},
{
'9'
,
'7'
},
{
'9'
,
'8'
},
{
'9'
,
'9'
}};
FMT_API
static
constexpr
const
char
hex_digits
[]
=
"0123456789abcdef"
;
FMT_API
static
constexpr
const
char
hex_digits
[]
=
"0123456789abcdef"
;
FMT_API
static
constexpr
const
char
signs
[
4
]
=
{
0
,
'-'
,
'+'
,
' '
};
FMT_API
static
constexpr
const
unsigned
prefixes
[
4
]
=
{
0
,
0
,
0x1000000u
|
'+'
,
FMT_API
static
constexpr
const
unsigned
prefixes
[
4
]
=
{
0
,
0
,
0x1000000u
|
'+'
,
0x1000000u
|
' '
};
0x1000000u
|
' '
};
};
};
...
@@ -922,6 +921,14 @@ extern template struct basic_data<void>;
...
@@ -922,6 +921,14 @@ extern template struct basic_data<void>;
// This is a struct rather than an alias to avoid shadowing warnings in gcc.
// This is a struct rather than an alias to avoid shadowing warnings in gcc.
struct
data
:
basic_data
<>
{};
struct
data
:
basic_data
<>
{};
// Sign is a template parameter to workaround a bug in gcc 4.8.
template
<
typename
Char
,
typename
Sign
>
constexpr
Char
sign
(
Sign
s
)
{
#if !FMT_GCC_VERSION || FMT_GCC_VERSION > 408
static_assert
(
std
::
is_same
<
Sign
,
sign_t
>::
value
,
""
);
#endif
return
static_cast
<
Char
>
(
"
\0
-+ "
[
s
]);
}
template
<
typename
T
>
FMT_CONSTEXPR
auto
count_digits_fallback
(
T
n
)
->
int
{
template
<
typename
T
>
FMT_CONSTEXPR
auto
count_digits_fallback
(
T
n
)
->
int
{
int
count
=
1
;
int
count
=
1
;
for
(;;)
{
for
(;;)
{
...
@@ -1676,7 +1683,7 @@ auto write_nonfinite(OutputIt out, bool isinf, basic_format_specs<Char> specs,
...
@@ -1676,7 +1683,7 @@ auto write_nonfinite(OutputIt out, bool isinf, basic_format_specs<Char> specs,
specs
.
fill
.
size
()
==
1
&&
*
specs
.
fill
.
data
()
==
static_cast
<
Char
>
(
'0'
);
specs
.
fill
.
size
()
==
1
&&
*
specs
.
fill
.
data
()
==
static_cast
<
Char
>
(
'0'
);
if
(
is_zero_fill
)
specs
.
fill
[
0
]
=
static_cast
<
Char
>
(
' '
);
if
(
is_zero_fill
)
specs
.
fill
[
0
]
=
static_cast
<
Char
>
(
' '
);
return
write_padded
(
out
,
specs
,
size
,
[
=
](
reserve_iterator
<
OutputIt
>
it
)
{
return
write_padded
(
out
,
specs
,
size
,
[
=
](
reserve_iterator
<
OutputIt
>
it
)
{
if
(
sign
)
*
it
++
=
static_cast
<
Char
>
(
data
::
signs
[
sign
]
);
if
(
sign
)
*
it
++
=
detail
::
sign
<
Char
>
(
sign
);
return
copy_str
<
Char
>
(
str
,
str
+
str_size
,
it
);
return
copy_str
<
Char
>
(
str
,
str
+
str_size
,
it
);
});
});
}
}
...
@@ -1820,7 +1827,7 @@ auto write_float(OutputIt out, const DecimalFP& fp,
...
@@ -1820,7 +1827,7 @@ auto write_float(OutputIt out, const DecimalFP& fp,
size
+=
to_unsigned
((
decimal_point
?
1
:
0
)
+
2
+
exp_digits
);
size
+=
to_unsigned
((
decimal_point
?
1
:
0
)
+
2
+
exp_digits
);
char
exp_char
=
fspecs
.
upper
?
'E'
:
'e'
;
char
exp_char
=
fspecs
.
upper
?
'E'
:
'e'
;
auto
write
=
[
=
](
iterator
it
)
{
auto
write
=
[
=
](
iterator
it
)
{
if
(
sign
)
*
it
++
=
static_cast
<
Char
>
(
data
::
signs
[
sign
]
);
if
(
sign
)
*
it
++
=
detail
::
sign
<
Char
>
(
sign
);
// Insert a decimal point after the first digit and add an exponent.
// Insert a decimal point after the first digit and add an exponent.
it
=
write_significand
(
it
,
significand
,
significand_size
,
1
,
it
=
write_significand
(
it
,
significand
,
significand_size
,
1
,
decimal_point
);
decimal_point
);
...
@@ -1848,7 +1855,7 @@ auto write_float(OutputIt out, const DecimalFP& fp,
...
@@ -1848,7 +1855,7 @@ auto write_float(OutputIt out, const DecimalFP& fp,
auto
grouping
=
digit_grouping
<
Char
>
(
loc
,
fspecs
.
locale
);
auto
grouping
=
digit_grouping
<
Char
>
(
loc
,
fspecs
.
locale
);
size
+=
to_unsigned
(
grouping
.
count_separators
(
significand_size
));
size
+=
to_unsigned
(
grouping
.
count_separators
(
significand_size
));
return
write_padded
<
align
::
right
>
(
out
,
specs
,
size
,
[
&
](
iterator
it
)
{
return
write_padded
<
align
::
right
>
(
out
,
specs
,
size
,
[
&
](
iterator
it
)
{
if
(
sign
)
*
it
++
=
static_cast
<
Char
>
(
data
::
signs
[
sign
]
);
if
(
sign
)
*
it
++
=
detail
::
sign
<
Char
>
(
sign
);
it
=
write_significand
<
Char
>
(
it
,
significand
,
significand_size
,
it
=
write_significand
<
Char
>
(
it
,
significand
,
significand_size
,
fp
.
exponent
,
grouping
);
fp
.
exponent
,
grouping
);
if
(
!
fspecs
.
showpoint
)
return
it
;
if
(
!
fspecs
.
showpoint
)
return
it
;
...
@@ -1862,7 +1869,7 @@ auto write_float(OutputIt out, const DecimalFP& fp,
...
@@ -1862,7 +1869,7 @@ auto write_float(OutputIt out, const DecimalFP& fp,
auto
grouping
=
digit_grouping
<
Char
>
(
loc
,
fspecs
.
locale
);
auto
grouping
=
digit_grouping
<
Char
>
(
loc
,
fspecs
.
locale
);
size
+=
to_unsigned
(
grouping
.
count_separators
(
significand_size
));
size
+=
to_unsigned
(
grouping
.
count_separators
(
significand_size
));
return
write_padded
<
align
::
right
>
(
out
,
specs
,
size
,
[
&
](
iterator
it
)
{
return
write_padded
<
align
::
right
>
(
out
,
specs
,
size
,
[
&
](
iterator
it
)
{
if
(
sign
)
*
it
++
=
static_cast
<
Char
>
(
data
::
signs
[
sign
]
);
if
(
sign
)
*
it
++
=
detail
::
sign
<
Char
>
(
sign
);
it
=
write_significand
(
it
,
significand
,
significand_size
,
exp
,
it
=
write_significand
(
it
,
significand
,
significand_size
,
exp
,
decimal_point
,
grouping
);
decimal_point
,
grouping
);
return
num_zeros
>
0
?
detail
::
fill_n
(
it
,
num_zeros
,
zero
)
:
it
;
return
num_zeros
>
0
?
detail
::
fill_n
(
it
,
num_zeros
,
zero
)
:
it
;
...
@@ -1877,7 +1884,7 @@ auto write_float(OutputIt out, const DecimalFP& fp,
...
@@ -1877,7 +1884,7 @@ auto write_float(OutputIt out, const DecimalFP& fp,
bool
pointy
=
num_zeros
!=
0
||
significand_size
!=
0
||
fspecs
.
showpoint
;
bool
pointy
=
num_zeros
!=
0
||
significand_size
!=
0
||
fspecs
.
showpoint
;
size
+=
1
+
(
pointy
?
1
:
0
)
+
to_unsigned
(
num_zeros
);
size
+=
1
+
(
pointy
?
1
:
0
)
+
to_unsigned
(
num_zeros
);
return
write_padded
<
align
::
right
>
(
out
,
specs
,
size
,
[
&
](
iterator
it
)
{
return
write_padded
<
align
::
right
>
(
out
,
specs
,
size
,
[
&
](
iterator
it
)
{
if
(
sign
)
*
it
++
=
static_cast
<
Char
>
(
data
::
signs
[
sign
]
);
if
(
sign
)
*
it
++
=
detail
::
sign
<
Char
>
(
sign
);
*
it
++
=
zero
;
*
it
++
=
zero
;
if
(
!
pointy
)
return
it
;
if
(
!
pointy
)
return
it
;
*
it
++
=
decimal_point
;
*
it
++
=
decimal_point
;
...
@@ -1905,7 +1912,7 @@ auto write(OutputIt out, T value, basic_format_specs<Char> specs,
...
@@ -1905,7 +1912,7 @@ auto write(OutputIt out, T value, basic_format_specs<Char> specs,
if
(
specs
.
align
==
align
::
numeric
&&
fspecs
.
sign
)
{
if
(
specs
.
align
==
align
::
numeric
&&
fspecs
.
sign
)
{
auto
it
=
reserve
(
out
,
1
);
auto
it
=
reserve
(
out
,
1
);
*
it
++
=
static_cast
<
Char
>
(
data
::
signs
[
fspecs
.
sign
]
);
*
it
++
=
detail
::
sign
<
Char
>
(
fspecs
.
sign
);
out
=
base_iterator
(
out
,
it
);
out
=
base_iterator
(
out
,
it
);
fspecs
.
sign
=
sign
::
none
;
fspecs
.
sign
=
sign
::
none
;
if
(
specs
.
width
!=
0
)
--
specs
.
width
;
if
(
specs
.
width
!=
0
)
--
specs
.
width
;
...
@@ -1913,7 +1920,7 @@ auto write(OutputIt out, T value, basic_format_specs<Char> specs,
...
@@ -1913,7 +1920,7 @@ auto write(OutputIt out, T value, basic_format_specs<Char> specs,
memory_buffer
buffer
;
memory_buffer
buffer
;
if
(
fspecs
.
format
==
float_format
::
hex
)
{
if
(
fspecs
.
format
==
float_format
::
hex
)
{
if
(
fspecs
.
sign
)
buffer
.
push_back
(
d
ata
::
signs
[
fspecs
.
sign
]
);
if
(
fspecs
.
sign
)
buffer
.
push_back
(
d
etail
::
sign
<
char
>
(
fspecs
.
sign
)
);
snprintf_float
(
promote_float
(
value
),
specs
.
precision
,
fspecs
,
buffer
);
snprintf_float
(
promote_float
(
value
),
specs
.
precision
,
fspecs
,
buffer
);
return
write_bytes
<
align
::
right
>
(
out
,
{
buffer
.
data
(),
buffer
.
size
()},
return
write_bytes
<
align
::
right
>
(
out
,
{
buffer
.
data
(),
buffer
.
size
()},
specs
);
specs
);
...
...
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