Tag Parser 11.0.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
diagnostics.cpp
Go to the documentation of this file.
1#include "./diagnostics.h"
2
3using namespace std;
4
5namespace TagParser {
6
22std::string_view diagLevelName(DiagLevel diagLevel)
23{
24 switch (diagLevel) {
26 return "information";
28 return "warning";
30 return "critical";
32 return "debug";
33 case DiagLevel::None:
34 default:
35 return std::string_view();
36 }
37}
38
42bool Diagnostics::has(DiagLevel level) const
43{
44 for (const auto &msg : *this) {
45 if (msg.level() >= level) {
46 return true;
47 }
48 }
49 return false;
50}
51
56{
58 for (const auto &msg : *this) {
59 if ((level |= msg.level()) >= worstDiagLevel) {
60 return level;
61 }
62 }
63 return level;
64}
65
69string DiagMessage::formatList(const std::vector<string> &values)
70{
71 auto size = values.size() * 4;
72 for (const auto &str : values) {
73 size += str.size();
74 }
75 std::string res;
76 res.reserve(size);
77 for (auto value = values.cbegin(), end = values.cend(), last = values.cend() - 1; value != end; ++value) {
78 if (value == last) {
79 res += " and ";
80 } else if (!res.empty()) {
81 res += ", ";
82 }
83 res += '\"';
84 res += *value;
85 res += '\"';
86 }
87 return res;
88}
89
90} // namespace TagParser
static std::string formatList(const std::vector< std::string > &values)
Concatenates the specified string values to a list.
Definition: diagnostics.cpp:69
bool has(DiagLevel level) const
Returns whether there's at least one DiagMessage which is at least as worse as level.
Definition: diagnostics.cpp:42
DiagLevel level() const
Returns the worst diag level present in the container.
Definition: diagnostics.cpp:55
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TAG_PARSER_EXPORT std::string_view diagLevelName(DiagLevel diagLevel)
Returns the string representation of the specified diagLevel.
Definition: diagnostics.cpp:22
DiagLevel
Specifies the level of the diagnostic message.
Definition: diagnostics.h:16
constexpr auto worstDiagLevel
The worst diag level.
Definition: diagnostics.h:26