ZeroErr
δΈ/En
Loading...
Searching...
No Matches
format.h
Go to the documentation of this file.
1
#pragma once
2
#include "
zeroerr/print.h
"
3
4
#include <sstream>
5
#include <string>
6
7
namespace
zeroerr
{
8
9
24
template
<
typename
... T>
25
std::string
format
(
const
char
* fmt, T... args) {
26
std::stringstream ss;
27
bool
parse_name =
false
;
28
Printer
print;
29
30
print.
isQuoted
=
false
;
31
print.
isCompact
=
true
;
32
print.
line_break
=
""
;
33
std::string str_args[] = {print(args)...};
34
35
int
j = 0;
36
for
(
const
char
* i = fmt; *i !=
'\0'
; i++) {
37
switch
(*i) {
38
case
'{'
: parse_name =
true
;
break
;
39
case
'}'
:
40
parse_name =
false
;
41
ss << str_args[j++];
42
break
;
43
default
:
44
if
(!parse_name) ss << *i;
45
break
;
46
}
47
}
48
return
ss.
str
();
49
}
50
51
}
// namespace zeroerr
zeroerr
Definition
benchmark.cpp:17
zeroerr::format
std::string format(const char *fmt, T... args)
Format a string with arguments.
Definition
format.h:25
print.h
zeroerr::Printer
A functor class Printer for printing a value of any type.
Definition
print.h:63
zeroerr::Printer::isQuoted
bool isQuoted
Definition
print.h:106
zeroerr::Printer::str
std::string str() const
Definition
print.h:253
zeroerr::Printer::isCompact
bool isCompact
Definition
print.h:105
zeroerr::Printer::line_break
const char * line_break
Definition
print.h:108
include
zeroerr
format.h
Generated by
1.9.8