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
3e1f70fe
Commit
3e1f70fe
authored
Nov 20, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge write_fp into write
parent
125fc5e5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
107 deletions
+73
-107
include/fmt/format-inl.h
include/fmt/format-inl.h
+1
-1
include/fmt/format.h
include/fmt/format.h
+71
-98
include/fmt/printf.h
include/fmt/printf.h
+1
-1
test/locale-test.cc
test/locale-test.cc
+0
-7
No files found.
include/fmt/format-inl.h
View file @
3e1f70fe
// Formatting library for C++
// Formatting library for C++
- implementation
//
//
// Copyright (c) 2012 - 2016, Victor Zverovich
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
// All rights reserved.
...
...
include/fmt/format.h
View file @
3e1f70fe
...
@@ -1690,7 +1690,6 @@ template <typename Range> class basic_writer {
...
@@ -1690,7 +1690,6 @@ template <typename Range> class basic_writer {
};
};
public:
public:
/** Constructs a ``basic_writer`` object. */
explicit
basic_writer
(
Range
out
,
explicit
basic_writer
(
Range
out
,
internal
::
locale_ref
loc
=
internal
::
locale_ref
())
internal
::
locale_ref
loc
=
internal
::
locale_ref
())
:
out_
(
out
.
begin
()),
locale_
(
loc
)
{}
:
out_
(
out
.
begin
()),
locale_
(
loc
)
{}
...
@@ -1743,29 +1742,79 @@ template <typename Range> class basic_writer {
...
@@ -1743,29 +1742,79 @@ template <typename Range> class basic_writer {
int_writer
<
T
,
Spec
>
(
*
this
,
value
,
spec
));
int_writer
<
T
,
Spec
>
(
*
this
,
value
,
spec
));
}
}
void
write
(
float
value
,
const
format_specs
&
specs
=
format_specs
())
{
template
<
typename
T
,
FMT_ENABLE_IF
(
std
::
is_floating_point
<
T
>
::
value
)
>
write_fp
(
value
,
specs
);
void
write
(
T
value
,
const
format_specs
&
specs
=
{})
{
}
auto
sign
=
specs
.
sign
;
if
(
std
::
signbit
(
value
))
{
// value < 0 is false for NaN so use signbit.
sign
=
sign
::
minus
;
value
=
-
value
;
}
else
if
(
sign
==
sign
::
minus
)
{
sign
=
sign
::
none
;
}
void
write
(
double
value
,
const
format_specs
&
specs
=
format_specs
())
{
float_spec
fspec
=
parse_float_type_spec
(
specs
.
type
);
write_fp
(
value
,
specs
);
if
(
!
std
::
isfinite
(
value
))
{
}
const
char
*
str
=
std
::
isinf
(
value
)
?
(
fspec
.
upper
?
"INF"
:
"inf"
)
:
(
fspec
.
upper
?
"NAN"
:
"nan"
);
return
write_padded
(
specs
,
inf_or_nan_writer
{
sign
,
fspec
.
percent
,
str
});
}
/**
if
(
fspec
.
percent
)
value
*=
100
;
\rst
Formats *value* using the general format for floating-point numbers
memory_buffer
buffer
;
(``'g'``) and writes it to the buffer.
int
exp
=
0
;
\endrst
int
precision
=
specs
.
precision
>=
0
||
!
specs
.
type
?
specs
.
precision
:
6
;
*/
int
num_digits
=
void
write
(
long
double
value
,
const
format_specs
&
specs
=
format_specs
())
{
fspec
.
format
==
float_format
::
exp
?
precision
+
1
:
precision
;
write_fp
(
value
,
specs
);
unsigned
options
=
0
;
if
(
fspec
.
format
==
float_format
::
fixed
)
options
|=
grisu_options
::
fixed
;
if
(
const_check
(
sizeof
(
value
)
==
sizeof
(
float
)))
options
|=
grisu_options
::
binary32
;
bool
use_grisu
=
internal
::
use_grisu
<
T
>
()
&&
(
specs
.
type
!=
'a'
&&
specs
.
type
!=
'A'
)
&&
grisu_format
(
static_cast
<
double
>
(
value
),
buffer
,
num_digits
,
options
,
exp
);
char
*
decimal_point_pos
=
nullptr
;
if
(
!
use_grisu
)
decimal_point_pos
=
sprintf_format
(
value
,
buffer
,
specs
);
if
(
fspec
.
percent
)
{
buffer
.
push_back
(
'%'
);
--
exp
;
// Adjust decimal place position.
}
format_specs
as
=
specs
;
if
(
specs
.
align
==
align
::
numeric
)
{
if
(
sign
)
{
auto
&&
it
=
reserve
(
1
);
*
it
++
=
static_cast
<
char_type
>
(
data
::
signs
[
sign
]);
sign
=
sign
::
none
;
if
(
as
.
width
)
--
as
.
width
;
}
as
.
align
=
align
::
right
;
}
else
if
(
specs
.
align
==
align
::
none
)
{
as
.
align
=
align
::
right
;
}
char_type
point
=
fspec
.
locale
?
decimal_point
<
char_type
>
(
locale_
)
:
static_cast
<
char_type
>
(
'.'
);
if
(
use_grisu
)
{
auto
params
=
gen_digits_params
();
params
.
sign
=
sign
;
params
.
format
=
fspec
.
format
;
params
.
num_digits
=
num_digits
;
params
.
trailing_zeros
=
(
precision
!=
0
&&
(
!
specs
.
type
||
fspec
.
format
==
float_format
::
fixed
||
fspec
.
format
==
float_format
::
exp
))
||
specs
.
alt
;
params
.
upper
=
fspec
.
upper
;
num_digits
=
static_cast
<
int
>
(
buffer
.
size
());
write_padded
(
as
,
grisu_writer
<
char_type
>
(
buffer
.
data
(),
num_digits
,
exp
,
params
,
point
));
}
else
{
write_padded
(
as
,
double_writer
{
sign
,
buffer
,
decimal_point_pos
,
point
});
}
}
}
// Formats a floating-point number (float, double, or long double).
// Writes a character to the buffer.
template
<
typename
T
,
bool
USE_GRISU
=
internal
::
use_grisu
<
T
>()
>
void
write_fp
(
T
value
,
const
format_specs
&
specs
);
/** Writes a character to the buffer. */
void
write
(
char
value
)
{
void
write
(
char
value
)
{
auto
&&
it
=
reserve
(
1
);
auto
&&
it
=
reserve
(
1
);
*
it
++
=
value
;
*
it
++
=
value
;
...
@@ -1777,11 +1826,7 @@ template <typename Range> class basic_writer {
...
@@ -1777,11 +1826,7 @@ template <typename Range> class basic_writer {
*
it
++
=
value
;
*
it
++
=
value
;
}
}
/**
// Writes value to the buffer.
\rst
Writes *value* to the buffer.
\endrst
*/
void
write
(
string_view
value
)
{
void
write
(
string_view
value
)
{
auto
&&
it
=
reserve
(
value
.
size
());
auto
&&
it
=
reserve
(
value
.
size
());
it
=
internal
::
copy_str
<
char_type
>
(
value
.
begin
(),
value
.
end
(),
it
);
it
=
internal
::
copy_str
<
char_type
>
(
value
.
begin
(),
value
.
end
(),
it
);
...
@@ -1820,78 +1865,6 @@ template <typename Range> class basic_writer {
...
@@ -1820,78 +1865,6 @@ template <typename Range> class basic_writer {
}
}
};
};
template
<
typename
Range
>
template
<
typename
T
,
bool
USE_GRISU
>
void
basic_writer
<
Range
>::
write_fp
(
T
value
,
const
format_specs
&
specs
)
{
auto
sign
=
specs
.
sign
;
if
(
std
::
signbit
(
value
))
{
// value < 0 is false for NaN so use signbit.
sign
=
sign
::
minus
;
value
=
-
value
;
}
else
if
(
sign
==
sign
::
minus
)
{
sign
=
sign
::
none
;
}
float_spec
fspec
=
parse_float_type_spec
(
specs
.
type
);
if
(
!
std
::
isfinite
(
value
))
{
const
char
*
str
=
std
::
isinf
(
value
)
?
(
fspec
.
upper
?
"INF"
:
"inf"
)
:
(
fspec
.
upper
?
"NAN"
:
"nan"
);
return
write_padded
(
specs
,
inf_or_nan_writer
{
sign
,
fspec
.
percent
,
str
});
}
if
(
fspec
.
percent
)
value
*=
100
;
memory_buffer
buffer
;
int
exp
=
0
;
int
precision
=
specs
.
precision
>=
0
||
!
specs
.
type
?
specs
.
precision
:
6
;
int
num_digits
=
fspec
.
format
==
float_format
::
exp
?
precision
+
1
:
precision
;
unsigned
options
=
0
;
if
(
fspec
.
format
==
float_format
::
fixed
)
options
|=
grisu_options
::
fixed
;
if
(
const_check
(
sizeof
(
value
)
==
sizeof
(
float
)))
options
|=
grisu_options
::
binary32
;
bool
use_grisu
=
USE_GRISU
&&
(
specs
.
type
!=
'a'
&&
specs
.
type
!=
'A'
)
&&
grisu_format
(
static_cast
<
double
>
(
value
),
buffer
,
num_digits
,
options
,
exp
);
char
*
decimal_point_pos
=
nullptr
;
if
(
!
use_grisu
)
decimal_point_pos
=
sprintf_format
(
value
,
buffer
,
specs
);
if
(
fspec
.
percent
)
{
buffer
.
push_back
(
'%'
);
--
exp
;
// Adjust decimal place position.
}
format_specs
as
=
specs
;
if
(
specs
.
align
==
align
::
numeric
)
{
if
(
sign
)
{
auto
&&
it
=
reserve
(
1
);
*
it
++
=
static_cast
<
char_type
>
(
data
::
signs
[
sign
]);
sign
=
sign
::
none
;
if
(
as
.
width
)
--
as
.
width
;
}
as
.
align
=
align
::
right
;
}
else
if
(
specs
.
align
==
align
::
none
)
{
as
.
align
=
align
::
right
;
}
char_type
point
=
fspec
.
locale
?
decimal_point
<
char_type
>
(
locale_
)
:
static_cast
<
char_type
>
(
'.'
);
if
(
use_grisu
)
{
auto
params
=
gen_digits_params
();
params
.
sign
=
sign
;
params
.
format
=
fspec
.
format
;
params
.
num_digits
=
num_digits
;
params
.
trailing_zeros
=
(
precision
!=
0
&&
(
!
specs
.
type
||
fspec
.
format
==
float_format
::
fixed
||
fspec
.
format
==
float_format
::
exp
))
||
specs
.
alt
;
params
.
upper
=
fspec
.
upper
;
num_digits
=
static_cast
<
int
>
(
buffer
.
size
());
write_padded
(
as
,
grisu_writer
<
char_type
>
(
buffer
.
data
(),
num_digits
,
exp
,
params
,
point
));
}
else
{
write_padded
(
as
,
double_writer
{
sign
,
buffer
,
decimal_point_pos
,
point
});
}
}
using
writer
=
basic_writer
<
buffer_range
<
char
>>
;
using
writer
=
basic_writer
<
buffer_range
<
char
>>
;
template
<
typename
T
>
struct
is_integral
:
std
::
is_integral
<
T
>
{};
template
<
typename
T
>
struct
is_integral
:
std
::
is_integral
<
T
>
{};
...
@@ -1983,7 +1956,7 @@ class arg_formatter_base {
...
@@ -1983,7 +1956,7 @@ class arg_formatter_base {
template
<
typename
T
,
FMT_ENABLE_IF
(
std
::
is_floating_point
<
T
>
::
value
)
>
template
<
typename
T
,
FMT_ENABLE_IF
(
std
::
is_floating_point
<
T
>
::
value
)
>
iterator
operator
()(
T
value
)
{
iterator
operator
()(
T
value
)
{
writer_
.
write
_fp
(
value
,
specs_
?
*
specs_
:
format_specs
());
writer_
.
write
(
value
,
specs_
?
*
specs_
:
format_specs
());
return
out
();
return
out
();
}
}
...
...
include/fmt/printf.h
View file @
3e1f70fe
// Formatting library for C++
// Formatting library for C++
- legacy printf implementation
//
//
// Copyright (c) 2012 - 2016, Victor Zverovich
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
// All rights reserved.
...
...
test/locale-test.cc
View file @
3e1f70fe
...
@@ -42,13 +42,6 @@ template <typename Char> struct small_grouping : std::numpunct<Char> {
...
@@ -42,13 +42,6 @@ template <typename Char> struct small_grouping : std::numpunct<Char> {
TEST
(
LocaleTest
,
DoubleDecimalPoint
)
{
TEST
(
LocaleTest
,
DoubleDecimalPoint
)
{
std
::
locale
loc
(
std
::
locale
(),
new
numpunct
<
char
>
());
std
::
locale
loc
(
std
::
locale
(),
new
numpunct
<
char
>
());
EXPECT_EQ
(
"1?23"
,
fmt
::
format
(
loc
,
"{:n}"
,
1.23
));
EXPECT_EQ
(
"1?23"
,
fmt
::
format
(
loc
,
"{:n}"
,
1.23
));
// Test with Grisu disabled.
fmt
::
memory_buffer
buf
;
fmt
::
internal
::
writer
w
(
buf
,
fmt
::
internal
::
locale_ref
(
loc
));
auto
specs
=
fmt
::
format_specs
();
specs
.
type
=
'n'
;
w
.
write_fp
<
double
,
false
>
(
1.23
,
specs
);
EXPECT_EQ
(
fmt
::
to_string
(
buf
),
"1?23"
);
}
}
TEST
(
LocaleTest
,
Format
)
{
TEST
(
LocaleTest
,
Format
)
{
...
...
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