mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-26 12:35:32 +00:00
Initial support for header-only configuration
This commit is contained in:
parent
aca49379a5
commit
d9c605c61f
24
format.cc
24
format.cc
@ -81,6 +81,10 @@ using fmt::internal::Arg;
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef FMT_HEADER_ONLY
|
||||||
|
# define FMT_FUNC inline
|
||||||
|
#endif
|
||||||
|
|
||||||
#if _MSC_VER
|
#if _MSC_VER
|
||||||
# pragma warning(push)
|
# pragma warning(push)
|
||||||
# pragma warning(disable: 4127) // conditional expression is constant
|
# pragma warning(disable: 4127) // conditional expression is constant
|
||||||
@ -348,7 +352,7 @@ inline Arg::StringValue<wchar_t> ignore_incompatible_str(
|
|||||||
Arg::StringValue<wchar_t> s) { return s; }
|
Arg::StringValue<wchar_t> s) { return s; }
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void fmt::SystemError::init(
|
FMT_FUNC void fmt::SystemError::init(
|
||||||
int error_code, StringRef format_str, ArgList args) {
|
int error_code, StringRef format_str, ArgList args) {
|
||||||
error_code_ = error_code;
|
error_code_ = error_code;
|
||||||
MemoryWriter w;
|
MemoryWriter w;
|
||||||
@ -413,7 +417,7 @@ const uint64_t fmt::internal::POWERS_OF_10_64[] = {
|
|||||||
ULongLong(1000000000) * ULongLong(1000000000) * 10
|
ULongLong(1000000000) * ULongLong(1000000000) * 10
|
||||||
};
|
};
|
||||||
|
|
||||||
void fmt::internal::report_unknown_type(char code, const char *type) {
|
FMT_FUNC void fmt::internal::report_unknown_type(char code, const char *type) {
|
||||||
if (std::isprint(static_cast<unsigned char>(code))) {
|
if (std::isprint(static_cast<unsigned char>(code))) {
|
||||||
FMT_THROW(fmt::FormatError(
|
FMT_THROW(fmt::FormatError(
|
||||||
fmt::format("unknown format code '{}' for {}", code, type)));
|
fmt::format("unknown format code '{}' for {}", code, type)));
|
||||||
@ -468,7 +472,7 @@ void fmt::WindowsError::init(
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void fmt::internal::format_system_error(
|
FMT_FUNC void fmt::internal::format_system_error(
|
||||||
fmt::Writer &out, int error_code,
|
fmt::Writer &out, int error_code,
|
||||||
fmt::StringRef message) FMT_NOEXCEPT(true) {
|
fmt::StringRef message) FMT_NOEXCEPT(true) {
|
||||||
FMT_TRY {
|
FMT_TRY {
|
||||||
@ -619,7 +623,7 @@ inline Arg fmt::BasicFormatter<Char>::parse_arg_index(const Char *&s) {
|
|||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg fmt::internal::FormatterBase::do_get_arg(
|
FMT_FUNC Arg fmt::internal::FormatterBase::do_get_arg(
|
||||||
unsigned arg_index, const char *&error) {
|
unsigned arg_index, const char *&error) {
|
||||||
Arg arg = args_[arg_index];
|
Arg arg = args_[arg_index];
|
||||||
if (arg.type == Arg::NONE)
|
if (arg.type == Arg::NONE)
|
||||||
@ -1042,7 +1046,7 @@ void fmt::BasicFormatter<Char>::format(
|
|||||||
write(writer_, start_, s);
|
write(writer_, start_, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fmt::report_system_error(
|
FMT_FUNC void fmt::report_system_error(
|
||||||
int error_code, fmt::StringRef message) FMT_NOEXCEPT(true) {
|
int error_code, fmt::StringRef message) FMT_NOEXCEPT(true) {
|
||||||
report_error(internal::format_system_error, error_code, message);
|
report_error(internal::format_system_error, error_code, message);
|
||||||
}
|
}
|
||||||
@ -1054,23 +1058,23 @@ void fmt::report_windows_error(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void fmt::print(std::FILE *f, StringRef format_str, ArgList args) {
|
FMT_FUNC void fmt::print(std::FILE *f, StringRef format_str, ArgList args) {
|
||||||
MemoryWriter w;
|
MemoryWriter w;
|
||||||
w.write(format_str, args);
|
w.write(format_str, args);
|
||||||
std::fwrite(w.data(), 1, w.size(), f);
|
std::fwrite(w.data(), 1, w.size(), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fmt::print(StringRef format_str, ArgList args) {
|
FMT_FUNC void fmt::print(StringRef format_str, ArgList args) {
|
||||||
print(stdout, format_str, args);
|
print(stdout, format_str, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fmt::print(std::ostream &os, StringRef format_str, ArgList args) {
|
FMT_FUNC void fmt::print(std::ostream &os, StringRef format_str, ArgList args) {
|
||||||
MemoryWriter w;
|
MemoryWriter w;
|
||||||
w.write(format_str, args);
|
w.write(format_str, args);
|
||||||
os.write(w.data(), w.size());
|
os.write(w.data(), w.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void fmt::print_colored(Color c, StringRef format, ArgList args) {
|
FMT_FUNC void fmt::print_colored(Color c, StringRef format, ArgList args) {
|
||||||
char escape[] = "\x1b[30m";
|
char escape[] = "\x1b[30m";
|
||||||
escape[3] = '0' + static_cast<char>(c);
|
escape[3] = '0' + static_cast<char>(c);
|
||||||
std::fputs(escape, stdout);
|
std::fputs(escape, stdout);
|
||||||
@ -1078,7 +1082,7 @@ void fmt::print_colored(Color c, StringRef format, ArgList args) {
|
|||||||
std::fputs(RESET_COLOR, stdout);
|
std::fputs(RESET_COLOR, stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fmt::fprintf(std::FILE *f, StringRef format, ArgList args) {
|
FMT_FUNC int fmt::fprintf(std::FILE *f, StringRef format, ArgList args) {
|
||||||
MemoryWriter w;
|
MemoryWriter w;
|
||||||
printf(w, format, args);
|
printf(w, format, args);
|
||||||
std::size_t size = w.size();
|
std::size_t size = w.size();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user