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 #include <spdlog/spdlog.h>
32 
33 #include <QString>
34 
35 template <>
36 struct fmt::formatter<QString> {
37  // Parses format specifications.
38  constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
39  return ctx.begin();
40  }
41 
42  // Formats the QString qstr and writes it to the output.
43  template <typename FormatContext>
44  auto format(const QString& qstr, FormatContext& ctx) const
45  -> decltype(ctx.out()) {
46  // Convert QString to UTF-8 QString (to handle Unicode characters
47  // correctly)
48  QByteArray utf8_array = qstr.toUtf8();
49  return fmt::format_to(ctx.out(), "{}", utf8_array.constData());
50  }
51 };
52 
53 template <>
54 struct fmt::formatter<QByteArray> {
55  // Parses format specifications.
56  constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
57  return ctx.begin();
58  }
59 
60  // Formats the QString qstr and writes it to the output.
61  template <typename FormatContext>
62  auto format(const QByteArray& qarray, FormatContext& ctx) const
63  -> decltype(ctx.out()) {
64  // Convert QString to UTF-8 QString (to handle Unicode characters
65  // correctly)
66  return fmt::format_to(ctx.out(), "{}", qarray.constData());
67  }
68 };