45#ifndef LIPSUM_MIN_BUILD
54 { std::to_string(value) } -> std::convertible_to<std::string>;
65 concept Streamable =
requires(std::ostream& outs,
const T& value) {
66 { outs << value } -> std::same_as<std::ostream&>;
79 (std::integral<T> || std::unsigned_integral<T>) &&
80 !(std::same_as<T, char>) && !(std::same_as<T, signed char>) &&
81 !(std::same_as<T, unsigned char>) && !(std::same_as<T, bool>);
105 Format format = Format::HTML);
125 template <
typename... Args>
127 [[maybe_unused]]
const Args&... args)
130 std::ostringstream oss;
131 oss <<
"lipsum-cpp ";
154 case LogType::Critical:
161 ((oss << args), ...);
163 std::string message = oss.str();
164# ifndef LIPSUM_MIN_BUILD
165# ifdef __EMSCRIPTEN__
166 auto funcCalling = emscripten_console_warn;
167 if (type == LogType::Trace || type == LogType::Info)
169 funcCalling = emscripten_console_log;
171 if (type == LogType::Error || type == LogType::Critical)
173 funcCalling = emscripten_console_error;
175 funcCalling(message.c_str());
176# elif defined(_WIN32)
177 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
179 if (type == LogType::Trace)
183 if (type == LogType::Info)
187 if (type == LogType::Error)
191 if (type == LogType::Critical)
196 SetConsoleTextAttribute(hConsole, colorUsing);
197 std::cerr << message;
199 SetConsoleTextAttribute(hConsole, 7);
202 if (type == LogType::Trace)
206 if (type == LogType::Info)
210 if (type == LogType::Error)
214 if (type == LogType::Critical)
218 std::cerr <<
"\033[" << colorUsing <<
"m" << message <<
"\033[0m";
221 std::cerr << message;
226#ifndef LIPSUM_MIN_BUILD
242 template <Streamable T> std::string
ToString(
const T& param)
245 std::ostringstream oss;
250 template <ToStringable T> std::string
ToString(
const T& param)
253 return std::to_string(param);
273 template <
typename T> T
ToType(
const std::string& input)
277 if constexpr (std::same_as<T, std::string>)
281 else if constexpr (std::same_as<T, bool>)
284 return (input ==
"true" || input ==
"1");
286 else if constexpr (std::same_as<T, char>)
289 return input.empty() ?
'\0' : input.at(0);
294 auto [ptr, ec] = std::from_chars(input.data(),
295 input.data() + input.size(),
297 if (ec != std::errc{})
299 LogWarn(internal::LogType::Error,
300 "lpsm::internal::ToType: std::from_chars() failed; "
301 "invalidly formatted integer? Returning default T.");
310 std::istringstream iss(input);
317 template <
typename T> std::string
ToString(
const T& param)
319 std::ostringstream oss;
324 template <
typename T> T
ToType(
const std::string& param)
327 std::istringstream iss(param);
328 iss >> std::boolalpha >> res;
Is T an int?
Definition internal.hpp:78
Can std::ostream take T?
Definition internal.hpp:65
Can std::to_string() be called with T?
Definition internal.hpp:53
Core macros for lipsum-cpp.
#define LIPSUM_API
Macro for shared libraries.
Definition core.hpp:71
Miscellaneous functions of lipsum-cpp.
This namespace contains functions only used internally by other functions.
LogType
Log types for lipsum::internal::LogWarn().
Definition internal.hpp:37
void LogWarn(LogType type, const Args &... args)
Log a warning.
Definition internal.hpp:126
LIPSUM_API std::string HandleHTMLEntity(char letter, Format format=Format::HTML)
Handle HTML entities.
Definition argvec2.inl:56
T ToType(const std::string &input)
Convert a string to an object.
Definition internal.hpp:273
std::string ToString(const T ¶m)
Convert an object to a string.
Definition internal.hpp:242
Format
Types of formats.
Definition misc.hpp:33
Standard library includes of lipsum-cpp.