GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
QtLoggerFmt.h
1 
29 #pragma once
30 
31 template <>
32 struct fmt::formatter<QString> {
33  // Parses format specifications.
34  constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
35  return ctx.begin();
36  }
37 
38  // Formats the QString qstr and writes it to the output.
39  template <typename FormatContext>
40  auto format(const QString& qstr, FormatContext& ctx) const
41  -> decltype(ctx.out()) {
42  // Convert QString to UTF-8 QString (to handle Unicode characters
43  // correctly)
44  QByteArray utf8_array = qstr.toUtf8();
45  return fmt::format_to(ctx.out(), "{}", utf8_array.constData());
46  }
47 };
48 
49 template <>
50 struct fmt::formatter<QByteArray> {
51  // Parses format specifications.
52  constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
53  return ctx.begin();
54  }
55 
56  // Formats the QString qstr and writes it to the output.
57  template <typename FormatContext>
58  auto format(const QByteArray& qarray, FormatContext& ctx) const
59  -> decltype(ctx.out()) {
60  // Convert QString to UTF-8 QString (to handle Unicode characters
61  // correctly)
62  return fmt::format_to(ctx.out(), "{}", qarray.constData());
63  }
64 };