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
fb32161f
Commit
fb32161f
authored
Aug 15, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move implementation specific stuff from format.h to format.cc.
parent
c7cfa7d4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
24 deletions
+25
-24
format.cc
format.cc
+7
-3
format.h
format.h
+3
-11
test/CMakeLists.txt
test/CMakeLists.txt
+7
-3
test/format-test.cc
test/format-test.cc
+8
-7
No files found.
format.cc
View file @
fb32161f
...
...
@@ -109,6 +109,12 @@ inline int safe_printf(char *buffer, size_t size, const char *format, ...) {
#endif // _MSC_VER
template
<
typename
T
>
struct
IsLongDouble
{
enum
{
VALUE
=
0
};
};
template
<
>
struct
IsLongDouble
<
long
double
>
{
enum
{
VALUE
=
1
};
};
const
char
RESET_COLOR
[]
=
"
\x1b
[0m"
;
typedef
void
(
*
FormatFunc
)(
fmt
::
Writer
&
,
int
,
fmt
::
StringRef
);
...
...
@@ -260,8 +266,6 @@ inline Arg::StringValue<wchar_t> ignore_incompatible_str(
Arg
::
StringValue
<
wchar_t
>
s
)
{
return
s
;
}
}
// namespace
int
fmt
::
internal
::
signbit_noinline
(
double
value
)
{
return
getsign
(
value
);
}
void
fmt
::
SystemError
::
init
(
int
error_code
,
StringRef
format_str
,
const
ArgList
&
args
)
{
error_code_
=
error_code
;
...
...
@@ -645,7 +649,7 @@ void fmt::BasicWriter<Char>::write_double(T value, const FormatSpec &spec) {
*
format_ptr
++
=
'.'
;
*
format_ptr
++
=
'*'
;
}
if
(
internal
::
IsLongDouble
<
T
>::
VALUE
)
if
(
IsLongDouble
<
T
>::
VALUE
)
*
format_ptr
++
=
'L'
;
*
format_ptr
++
=
type
;
*
format_ptr
=
'\0'
;
...
...
format.h
View file @
fb32161f
...
...
@@ -410,8 +410,6 @@ inline bool is_negative(T value) {
return
SignChecker
<
std
::
numeric_limits
<
T
>::
is_signed
>::
is_negative
(
value
);
}
int
signbit_noinline
(
double
value
);
template
<
typename
T
>
struct
IntTraits
{
// Smallest of uint32_t and uint64_t that is large enough to represent
...
...
@@ -435,12 +433,6 @@ FMT_SPECIALIZE_MAKE_UNSIGNED(int, unsigned);
FMT_SPECIALIZE_MAKE_UNSIGNED
(
long
,
unsigned
long
);
FMT_SPECIALIZE_MAKE_UNSIGNED
(
LongLong
,
ULongLong
);
template
<
typename
T
>
struct
IsLongDouble
{
enum
{
VALUE
=
0
};
};
template
<
>
struct
IsLongDouble
<
long
double
>
{
enum
{
VALUE
=
1
};
};
void
report_unknown_type
(
char
code
,
const
char
*
type
);
extern
const
uint32_t
POWERS_OF_10_32
[];
...
...
@@ -452,7 +444,7 @@ extern const uint64_t POWERS_OF_10_64[];
inline
unsigned
count_digits
(
uint64_t
n
)
{
// Based on http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
// and the benchmark https://github.com/localvoid/cxx-benchmark-count-digits.
u
int64_t
t
=
(
64
-
__builtin_clzll
(
n
|
1
))
*
1233
>>
12
;
u
nsigned
t
=
(
64
-
__builtin_clzll
(
n
|
1
))
*
1233
>>
12
;
return
t
-
(
n
<
POWERS_OF_10_64
[
t
])
+
1
;
}
# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz)
...
...
@@ -1862,10 +1854,10 @@ class FormatInt {
}
void
FormatSigned
(
LongLong
value
)
{
ULongLong
abs_value
=
value
;
ULongLong
abs_value
=
static_cast
<
ULongLong
>
(
value
)
;
bool
negative
=
value
<
0
;
if
(
negative
)
abs_value
=
0
-
value
;
abs_value
=
0
-
abs_
value
;
str_
=
format_decimal
(
abs_value
);
if
(
negative
)
*--
str_
=
'-'
;
...
...
test/CMakeLists.txt
View file @
fb32161f
set
(
TEST_MAIN_SRC test-main.cc gtest-extra.cc gtest-extra.h util.cc
)
add_library
(
test-main
${
TEST_MAIN_SRC
}
)
target_link_libraries
(
test-main gtest
format
)
target_link_libraries
(
test-main gtest
)
# Adds a test.
# Usage: add_fmt_test(name libs srcs...)
function
(
add_fmt_test name libs
)
add_executable
(
${
name
}
${
name
}
.cc
${
ARGN
}
)
cmake_parse_arguments
(
add_fmt_test CUSTOM_LINK
""
""
${
ARGN
}
)
add_executable
(
${
name
}
${
name
}
.cc
${
add_fmt_test_UNPARSED_ARGUMENTS
}
)
target_link_libraries
(
${
name
}
${
libs
}
)
if
(
NOT add_fmt_test_CUSTOM_LINK
)
target_link_libraries
(
${
name
}
format
)
endif
()
add_test
(
${
name
}
${
name
}
)
endfunction
()
add_fmt_test
(
gtest-extra-test test-main
)
add_fmt_test
(
format-test test-main
)
add_fmt_test
(
format-test test-main
CUSTOM_LINK ../posix.cc ../posix.h
)
add_fmt_test
(
printf-test test-main
)
foreach
(
target format-test printf-test
)
if
(
CMAKE_COMPILER_IS_GNUCXX
)
...
...
test/format-test.cc
View file @
fb32161f
...
...
@@ -35,6 +35,13 @@
#include <memory>
#include <sstream>
// Include format.cc instead of format.h to test implementation-specific stuff.
#include "format.cc"
#include "util.h"
#include "gtest-extra.h"
#include <stdint.h>
#if defined(_WIN32) && !defined(__MINGW32__)
// Fix MSVC warning about "unsafe" fopen.
FILE
*
safe_fopen
(
const
char
*
filename
,
const
char
*
mode
)
{
...
...
@@ -45,12 +52,6 @@ FILE *safe_fopen(const char *filename, const char *mode) {
#define fopen safe_fopen
#endif
#include "format.h"
#include "util.h"
#include "gtest-extra.h"
#include <stdint.h>
#undef min
#undef max
...
...
@@ -1230,7 +1231,7 @@ TEST(FormatterTest, FormatNaN) {
double
nan
=
std
::
numeric_limits
<
double
>::
quiet_NaN
();
EXPECT_EQ
(
"nan"
,
format
(
"{}"
,
nan
));
EXPECT_EQ
(
"+nan"
,
format
(
"{:+}"
,
nan
));
if
(
fmt
::
internal
::
signbit_noinline
(
-
nan
))
if
(
getsign
(
-
nan
))
EXPECT_EQ
(
"-nan"
,
format
(
"{}"
,
-
nan
));
else
fmt
::
print
(
"Warning: compiler doesn't handle negative NaN correctly"
);
...
...
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