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
ae3cc844
Commit
ae3cc844
authored
Mar 07, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check format string at compile time in print
parent
585512fc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
+23
-7
include/fmt/format.h
include/fmt/format.h
+23
-7
No files found.
include/fmt/format.h
View file @
ae3cc844
...
...
@@ -1468,6 +1468,10 @@ class arg_formatter_base {
struct
format_string
{};
template
<
typename
S
>
struct
is_format_string
:
std
::
integral_constant
<
bool
,
std
::
is_base_of
<
format_string
,
S
>::
value
>
{};
template
<
typename
Char
>
FMT_CONSTEXPR
bool
is_name_start
(
Char
c
)
{
return
(
'a'
<=
c
&&
c
<=
'z'
)
||
(
'A'
<=
c
&&
c
<=
'Z'
)
||
'_'
==
c
;
...
...
@@ -2093,6 +2097,14 @@ FMT_CONSTEXPR bool check_format_string(
return
true
;
}
template
<
typename
...
Args
,
typename
String
>
void
check_format_string
(
String
format_str
)
{
FMT_CONSTEXPR_DECL
bool
invalid_format
=
internal
::
check_format_string
<
char
,
internal
::
error_handler
,
Args
...
>
(
string_view
(
format_str
.
data
(),
format_str
.
size
()));
(
void
)
invalid_format
;
}
// Specifies whether to format T using the standard formatter.
// It is not possible to use get_type in formatter specialization directly
// because of a bug in MSVC.
...
...
@@ -3399,13 +3411,17 @@ inline std::wstring vformat(wstring_view format_str, wformat_args args) {
template
<
typename
String
,
typename
...
Args
>
inline
typename
std
::
enable_if
<
std
::
is_base_of
<
internal
::
format_string
,
String
>::
value
,
std
::
string
>::
type
internal
::
is_format_string
<
String
>::
value
,
std
::
string
>::
type
format
(
String
format_str
,
const
Args
&
...
args
)
{
FMT_CONSTEXPR_DECL
bool
invalid_format
=
internal
::
check_format_string
<
char
,
internal
::
error_handler
,
Args
...
>
(
string_view
(
format_str
.
value
(),
format_str
.
size
()));
(
void
)
invalid_format
;
return
vformat
(
format_str
.
value
(),
make_args
(
args
...));
internal
::
check_format_string
<
Args
...
>
(
format_str
);
return
vformat
(
format_str
.
data
(),
make_args
(
args
...));
}
template
<
typename
String
,
typename
...
Args
>
inline
typename
std
::
enable_if
<
internal
::
is_format_string
<
String
>::
value
>::
type
print
(
String
format_str
,
const
Args
&
...
args
)
{
internal
::
check_format_string
<
Args
...
>
(
format_str
);
return
vprint
(
format_str
.
data
(),
make_args
(
args
...));
}
// Counts the number of characters in the output of format(format_str, args...).
...
...
@@ -3505,7 +3521,7 @@ operator"" _a(const wchar_t *s, std::size_t) { return {s}; }
#define FMT_STRING(s) [] { \
struct S : fmt::internal::format_string { \
static FMT_CONSTEXPR auto
value
() { return s; } \
static FMT_CONSTEXPR auto
data
() { return s; } \
static FMT_CONSTEXPR size_t size() { return sizeof(s); } \
}; \
return S{}; \
...
...
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