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
29246221
Commit
29246221
authored
Oct 17, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix naming of basic_format_specs members
parent
bda5f9a5
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
146 additions
and
159 deletions
+146
-159
include/fmt/format-inl.h
include/fmt/format-inl.h
+48
-4
include/fmt/format.h
include/fmt/format.h
+60
-116
include/fmt/printf.h
include/fmt/printf.h
+20
-20
test/custom-formatter-test.cc
test/custom-formatter-test.cc
+2
-2
test/format-impl-test.cc
test/format-impl-test.cc
+0
-1
test/format-test.cc
test/format-test.cc
+16
-16
No files found.
include/fmt/format-inl.h
View file @
29246221
...
...
@@ -569,17 +569,17 @@ struct gen_digits_params {
// Creates digit generation parameters from format specifiers for a number in
// the range [pow(10, exp - 1), pow(10, exp) or 0 if exp == 1.
gen_digits_params
(
const
core_format_specs
&
specs
,
int
exp
)
:
min_digits
(
specs
.
precision
_
>=
0
?
to_unsigned
(
specs
.
precision_
)
:
6
),
:
min_digits
(
specs
.
precision
>=
0
?
to_unsigned
(
specs
.
precision
)
:
6
),
fixed
(
false
),
upper
(
false
),
trailing_zeros
(
false
)
{
switch
(
specs
.
type
_
)
{
switch
(
specs
.
type
)
{
case
'G'
:
upper
=
true
;
FMT_FALLTHROUGH
case
'\0'
:
case
'g'
:
trailing_zeros
=
(
specs
.
flags
_
&
HASH_FLAG
)
!=
0
;
trailing_zeros
=
(
specs
.
flags
&
HASH_FLAG
)
!=
0
;
if
(
-
4
<=
exp
&&
exp
<
static_cast
<
int
>
(
min_digits
)
+
1
)
{
fixed
=
true
;
if
(
!
specs
.
type
_
&&
trailing_zeros
&&
exp
>=
0
)
if
(
!
specs
.
type
&&
trailing_zeros
&&
exp
>=
0
)
min_digits
=
to_unsigned
(
exp
)
+
1
;
}
break
;
...
...
@@ -718,6 +718,50 @@ FMT_FUNC typename std::enable_if<sizeof(Double) == sizeof(uint64_t), bool>::type
buf
.
resize
(
size
);
return
true
;
}
template
<
typename
Double
>
void
sprintf_format
(
Double
value
,
internal
::
buffer
&
buffer
,
core_format_specs
spec
)
{
// Buffer capacity must be non-zero, otherwise MSVC's vsnprintf_s will fail.
FMT_ASSERT
(
buffer
.
capacity
()
!=
0
,
"empty buffer"
);
// Build format string.
enum
{
MAX_FORMAT_SIZE
=
10
};
// longest format: %#-*.*Lg
char
format
[
MAX_FORMAT_SIZE
];
char
*
format_ptr
=
format
;
*
format_ptr
++
=
'%'
;
if
(
spec
.
has
(
HASH_FLAG
))
*
format_ptr
++
=
'#'
;
if
(
spec
.
precision
>=
0
)
{
*
format_ptr
++
=
'.'
;
*
format_ptr
++
=
'*'
;
}
if
(
std
::
is_same
<
Double
,
long
double
>::
value
)
*
format_ptr
++
=
'L'
;
*
format_ptr
++
=
spec
.
type
;
*
format_ptr
=
'\0'
;
// Format using snprintf.
char
*
start
=
FMT_NULL
;
for
(;;)
{
std
::
size_t
buffer_size
=
buffer
.
capacity
();
start
=
&
buffer
[
0
];
int
result
=
internal
::
char_traits
<
char
>::
format_float
(
start
,
buffer_size
,
format
,
spec
.
precision
,
value
);
if
(
result
>=
0
)
{
unsigned
n
=
internal
::
to_unsigned
(
result
);
if
(
n
<
buffer
.
capacity
())
{
buffer
.
resize
(
n
);
break
;
// The buffer is large enough - continue with formatting.
}
buffer
.
reserve
(
n
+
1
);
}
else
{
// If result is negative we ask to increase the capacity by at least 1,
// but as std::vector, the buffer grows exponentially.
buffer
.
reserve
(
buffer
.
capacity
()
+
1
);
}
}
}
}
// namespace internal
#if FMT_USE_WINDOWS_H
...
...
include/fmt/format.h
View file @
29246221
This diff is collapsed.
Click to expand it.
include/fmt/printf.h
View file @
29246221
...
...
@@ -222,12 +222,12 @@ class printf_arg_formatter:
context_type
&
context_
;
void
write_null_pointer
(
char
)
{
this
->
spec
()
->
type
_
=
0
;
this
->
spec
()
->
type
=
0
;
this
->
write
(
"(nil)"
);
}
void
write_null_pointer
(
wchar_t
)
{
this
->
spec
()
->
type
_
=
0
;
this
->
spec
()
->
type
=
0
;
this
->
write
(
L"(nil)"
);
}
...
...
@@ -253,15 +253,15 @@ class printf_arg_formatter:
// use std::is_same instead.
if
(
std
::
is_same
<
T
,
bool
>::
value
)
{
format_specs
&
fmt_spec
=
*
this
->
spec
();
if
(
fmt_spec
.
type
_
!=
's'
)
if
(
fmt_spec
.
type
!=
's'
)
return
base
::
operator
()(
value
?
1
:
0
);
fmt_spec
.
type
_
=
0
;
fmt_spec
.
type
=
0
;
this
->
write
(
value
!=
0
);
}
else
if
(
std
::
is_same
<
T
,
char_type
>::
value
)
{
format_specs
&
fmt_spec
=
*
this
->
spec
();
if
(
fmt_spec
.
type
_
&&
fmt_spec
.
type_
!=
'c'
)
if
(
fmt_spec
.
type
&&
fmt_spec
.
type
!=
'c'
)
return
(
*
this
)(
static_cast
<
int
>
(
value
));
fmt_spec
.
flags
_
=
0
;
fmt_spec
.
flags
=
0
;
fmt_spec
.
align_
=
ALIGN_RIGHT
;
return
base
::
operator
()(
value
);
}
else
{
...
...
@@ -280,7 +280,7 @@ class printf_arg_formatter:
iterator
operator
()(
const
char
*
value
)
{
if
(
value
)
base
::
operator
()(
value
);
else
if
(
this
->
spec
()
->
type
_
==
'p'
)
else
if
(
this
->
spec
()
->
type
==
'p'
)
write_null_pointer
(
char_type
());
else
this
->
write
(
"(null)"
);
...
...
@@ -291,7 +291,7 @@ class printf_arg_formatter:
iterator
operator
()(
const
wchar_t
*
value
)
{
if
(
value
)
base
::
operator
()(
value
);
else
if
(
this
->
spec
()
->
type
_
==
'p'
)
else
if
(
this
->
spec
()
->
type
==
'p'
)
write_null_pointer
(
char_type
());
else
this
->
write
(
L"(null)"
);
...
...
@@ -310,7 +310,7 @@ class printf_arg_formatter:
iterator
operator
()(
const
void
*
value
)
{
if
(
value
)
return
base
::
operator
()(
value
);
this
->
spec
()
->
type
_
=
0
;
this
->
spec
()
->
type
=
0
;
write_null_pointer
(
char_type
());
return
this
->
out
();
}
...
...
@@ -394,16 +394,16 @@ void basic_printf_context<OutputIt, Char, AF>::parse_flags(
spec
.
align_
=
ALIGN_LEFT
;
break
;
case
'+'
:
spec
.
flags
_
|=
SIGN_FLAG
|
PLUS_FLAG
;
spec
.
flags
|=
SIGN_FLAG
|
PLUS_FLAG
;
break
;
case
'0'
:
spec
.
fill_
=
'0'
;
break
;
case
' '
:
spec
.
flags
_
|=
SIGN_FLAG
;
spec
.
flags
|=
SIGN_FLAG
;
break
;
case
'#'
:
spec
.
flags
_
|=
HASH_FLAG
;
spec
.
flags
|=
HASH_FLAG
;
break
;
default:
--
it
;
...
...
@@ -486,19 +486,19 @@ void basic_printf_context<OutputIt, Char, AF>::format() {
++
it
;
if
(
'0'
<=
*
it
&&
*
it
<=
'9'
)
{
internal
::
error_handler
eh
;
spec
.
precision
_
=
static_cast
<
int
>
(
parse_nonnegative_int
(
it
,
eh
));
spec
.
precision
=
static_cast
<
int
>
(
parse_nonnegative_int
(
it
,
eh
));
}
else
if
(
*
it
==
'*'
)
{
++
it
;
spec
.
precision
_
=
spec
.
precision
=
visit_format_arg
(
internal
::
printf_precision_handler
(),
get_arg
(
it
));
}
else
{
spec
.
precision
_
=
0
;
spec
.
precision
=
0
;
}
}
format_arg
arg
=
get_arg
(
it
,
arg_index
);
if
(
spec
.
flag
(
HASH_FLAG
)
&&
visit_format_arg
(
internal
::
is_zero_int
(),
arg
))
spec
.
flags
_
&=
~
internal
::
to_unsigned
<
int
>
(
HASH_FLAG
);
if
(
spec
.
has
(
HASH_FLAG
)
&&
visit_format_arg
(
internal
::
is_zero_int
(),
arg
))
spec
.
flags
&=
~
internal
::
to_unsigned
<
int
>
(
HASH_FLAG
);
if
(
spec
.
fill_
==
'0'
)
{
if
(
arg
.
is_arithmetic
())
spec
.
align_
=
ALIGN_NUMERIC
;
...
...
@@ -542,12 +542,12 @@ void basic_printf_context<OutputIt, Char, AF>::format() {
// Parse type.
if
(
!*
it
)
FMT_THROW
(
format_error
(
"invalid format string"
));
spec
.
type
_
=
static_cast
<
char
>
(
*
it
++
);
spec
.
type
=
static_cast
<
char
>
(
*
it
++
);
if
(
arg
.
is_integral
())
{
// Normalize type.
switch
(
spec
.
type
_
)
{
switch
(
spec
.
type
)
{
case
'i'
:
case
'u'
:
spec
.
type
_
=
'd'
;
spec
.
type
=
'd'
;
break
;
case
'c'
:
// TODO: handle wchar_t better?
...
...
test/custom-formatter-test.cc
View file @
29246221
...
...
@@ -26,8 +26,8 @@ class custom_arg_formatter :
using
base
::
operator
();
iterator
operator
()(
double
value
)
{
// Comparing a float to 0.0 is safe
if
(
round
(
value
*
pow
(
10
,
spec
()
->
precision
()
))
==
0.0
)
// Comparing a float to 0.0 is safe
.
if
(
round
(
value
*
pow
(
10
,
spec
()
->
precision
))
==
0.0
)
value
=
0
;
return
base
::
operator
()(
value
);
}
...
...
test/format-impl-test.cc
View file @
29246221
...
...
@@ -103,7 +103,6 @@ TEST(FPTest, GetCachedPower) {
}
TEST
(
FPTest
,
Grisu2FormatCompilesWithNonIEEEDouble
)
{
size_t
size
=
0
;
fmt
::
memory_buffer
buf
;
grisu2_format
(
4.2
f
,
buf
,
fmt
::
core_format_specs
());
}
...
...
test/format-test.cc
View file @
29246221
...
...
@@ -2182,19 +2182,19 @@ FMT_CONSTEXPR fmt::format_specs parse_specs(const char *s) {
}
TEST
(
FormatTest
,
ConstexprSpecsHandler
)
{
static_assert
(
parse_specs
(
"<"
).
align
()
==
fmt
::
ALIGN_LEFT
,
""
);
static_assert
(
parse_specs
(
"<"
).
align
==
fmt
::
ALIGN_LEFT
,
""
);
static_assert
(
parse_specs
(
"*^"
).
fill
()
==
'*'
,
""
);
static_assert
(
parse_specs
(
"+"
).
flag
(
fmt
::
PLUS_FLAG
),
""
);
static_assert
(
parse_specs
(
"-"
).
flag
(
fmt
::
MINUS_FLAG
),
""
);
static_assert
(
parse_specs
(
" "
).
flag
(
fmt
::
SIGN_FLAG
),
""
);
static_assert
(
parse_specs
(
"#"
).
flag
(
fmt
::
HASH_FLAG
),
""
);
static_assert
(
parse_specs
(
"0"
).
align
()
==
fmt
::
ALIGN_NUMERIC
,
""
);
static_assert
(
parse_specs
(
"+"
).
has
(
fmt
::
PLUS_FLAG
),
""
);
static_assert
(
parse_specs
(
"-"
).
has
(
fmt
::
MINUS_FLAG
),
""
);
static_assert
(
parse_specs
(
" "
).
has
(
fmt
::
SIGN_FLAG
),
""
);
static_assert
(
parse_specs
(
"#"
).
has
(
fmt
::
HASH_FLAG
),
""
);
static_assert
(
parse_specs
(
"0"
).
align
==
fmt
::
ALIGN_NUMERIC
,
""
);
static_assert
(
parse_specs
(
"42"
).
width
()
==
42
,
""
);
static_assert
(
parse_specs
(
"{}"
).
width
()
==
11
,
""
);
static_assert
(
parse_specs
(
"{0}"
).
width
()
==
22
,
""
);
static_assert
(
parse_specs
(
".42"
).
precision
()
==
42
,
""
);
static_assert
(
parse_specs
(
".{}"
).
precision
()
==
11
,
""
);
static_assert
(
parse_specs
(
".{0}"
).
precision
()
==
22
,
""
);
static_assert
(
parse_specs
(
".42"
).
precision
==
42
,
""
);
static_assert
(
parse_specs
(
".{}"
).
precision
==
11
,
""
);
static_assert
(
parse_specs
(
".{0}"
).
precision
==
22
,
""
);
static_assert
(
parse_specs
(
"d"
).
type
()
==
'd'
,
""
);
}
...
...
@@ -2208,17 +2208,17 @@ FMT_CONSTEXPR fmt::internal::dynamic_format_specs<char>
}
TEST
(
FormatTest
,
ConstexprDynamicSpecsHandler
)
{
static_assert
(
parse_dynamic_specs
(
"<"
).
align
()
==
fmt
::
ALIGN_LEFT
,
""
);
static_assert
(
parse_dynamic_specs
(
"<"
).
align
==
fmt
::
ALIGN_LEFT
,
""
);
static_assert
(
parse_dynamic_specs
(
"*^"
).
fill
()
==
'*'
,
""
);
static_assert
(
parse_dynamic_specs
(
"+"
).
flag
(
fmt
::
PLUS_FLAG
),
""
);
static_assert
(
parse_dynamic_specs
(
"-"
).
flag
(
fmt
::
MINUS_FLAG
),
""
);
static_assert
(
parse_dynamic_specs
(
" "
).
flag
(
fmt
::
SIGN_FLAG
),
""
);
static_assert
(
parse_dynamic_specs
(
"#"
).
flag
(
fmt
::
HASH_FLAG
),
""
);
static_assert
(
parse_dynamic_specs
(
"0"
).
align
()
==
fmt
::
ALIGN_NUMERIC
,
""
);
static_assert
(
parse_dynamic_specs
(
"+"
).
has
(
fmt
::
PLUS_FLAG
),
""
);
static_assert
(
parse_dynamic_specs
(
"-"
).
has
(
fmt
::
MINUS_FLAG
),
""
);
static_assert
(
parse_dynamic_specs
(
" "
).
has
(
fmt
::
SIGN_FLAG
),
""
);
static_assert
(
parse_dynamic_specs
(
"#"
).
has
(
fmt
::
HASH_FLAG
),
""
);
static_assert
(
parse_dynamic_specs
(
"0"
).
align
==
fmt
::
ALIGN_NUMERIC
,
""
);
static_assert
(
parse_dynamic_specs
(
"42"
).
width
()
==
42
,
""
);
static_assert
(
parse_dynamic_specs
(
"{}"
).
width_ref
.
index
==
33
,
""
);
static_assert
(
parse_dynamic_specs
(
"{42}"
).
width_ref
.
index
==
42
,
""
);
static_assert
(
parse_dynamic_specs
(
".42"
).
precision
()
==
42
,
""
);
static_assert
(
parse_dynamic_specs
(
".42"
).
precision
==
42
,
""
);
static_assert
(
parse_dynamic_specs
(
".{}"
).
precision_ref
.
index
==
33
,
""
);
static_assert
(
parse_dynamic_specs
(
".{42}"
).
precision_ref
.
index
==
42
,
""
);
static_assert
(
parse_dynamic_specs
(
"d"
).
type
()
==
'd'
,
""
);
...
...
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