Add function to get string representation of phrase

This commit is contained in:
Martchus 2020-01-14 21:27:46 +01:00
parent 0cdf2c3492
commit 5020214498
3 changed files with 35 additions and 2 deletions

View File

@ -112,8 +112,8 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parser, IO and conversion utilities")
set(META_FEATURES_FOR_COMPILER_DETECTION_HEADER cxx_thread_local)
set(META_VERSION_MAJOR 5)
set(META_VERSION_MINOR 1)
set(META_VERSION_PATCH 1)
set(META_VERSION_MINOR 2)
set(META_VERSION_PATCH 0)
# find required 3rd party libraries
include(3rdParty)

View File

@ -114,6 +114,37 @@ std::ostream &operator<<(std::ostream &stream, Phrases phrase)
return stream;
}
std::string_view phraseString(Phrases phrase)
{
using namespace std::string_view_literals;
switch (phrase) {
case Phrases::Error:
return "Error: "sv;
case Phrases::Warning:
return "Warning: "sv;
case Phrases::PlainMessage:
return " "sv;
case Phrases::SuccessMessage:
return "==> "sv;
case Phrases::SubMessage:
return " -> "sv;
case Phrases::ErrorMessage:
return "==> ERROR: "sv;
case Phrases::WarningMessage:
return "==> WARNING: ";
case Phrases::Info:
return "Info: "sv;
case Phrases::SubError:
return " -> ERROR: "sv;
case Phrases::SubWarning:
return " -> WARNING: "sv;
case Phrases::InfoMessage:
return "==> "sv;
default:
return std::string_view{};
}
}
} // namespace EscapeCodes
} // namespace CppUtilities

View File

@ -5,6 +5,7 @@
#include "../misc/traits.h"
#include <ostream>
#include <string_view>
#include <tuple>
namespace CppUtilities {
@ -150,6 +151,7 @@ enum class Phrases {
InfoMessage, /**< bold, white "==> " */
};
CPP_UTILITIES_EXPORT std::ostream &operator<<(std::ostream &stream, Phrases phrase);
CPP_UTILITIES_EXPORT std::string_view phraseString(Phrases phrase);
} // namespace EscapeCodes
} // namespace CppUtilities