logmeow/misc.cpp

34 lines
761 B
C++
Raw Normal View History

2023-01-16 04:05:25 +00:00
#include <iomanip>
#include <sstream>
2023-01-16 08:41:26 +00:00
#include <system_error>
2023-01-16 04:05:25 +00:00
#include "misc.h"
std::string quote(const std::string& str) {
std::stringstream ss;
ss << std::quoted(str);
return ss.str();
}
2023-01-16 08:41:26 +00:00
2023-01-17 15:35:08 +00:00
void throw_system_error(int err, const char* what) {
if (err == ENOMEM) {
throw std::bad_alloc();
}
throw std::system_error(err, std::generic_category(), what);
2023-01-16 08:41:26 +00:00
}
2023-01-17 15:35:08 +00:00
void throw_system_error(int err, std::string what) {
if (err == ENOMEM) {
throw std::bad_alloc();
}
throw std::system_error(err, std::generic_category(), std::move(what));
2023-01-16 08:41:26 +00:00
}
2023-01-17 15:35:08 +00:00
void throw_system_error(const char* what) {
throw_system_error(errno, what);
2023-01-16 08:41:26 +00:00
}
2023-01-17 15:35:08 +00:00
void throw_system_error(std::string what) {
throw_system_error(errno, std::move(what));
2023-01-16 08:41:26 +00:00
}