iu9-ca-web-chat/src/http_server/engine_engine_number_9/baza.cpp

48 lines
1.4 KiB
C++
Raw Normal View History

2024-07-27 11:27:52 +00:00
#include "baza.h"
#include "baza_inter.h"
2024-07-27 11:27:52 +00:00
#include <errno.h>
#include <string.h>
namespace een9 {
ServerError::ServerError(const std::string &err, const std::string &file, const std::string &func, int line): err(err),
FILE(file),
func(func),
LINE(line) {
char buf[4096];
snprintf(buf, 4096, "Error occured in function %s (line %d of %s)\n"
"Error: %s",
func.c_str(), LINE, FILE.c_str(), err.c_str());
WHAT = buf;
}
const char * ServerError::what() const noexcept {
return WHAT.c_str();
}
std::string prettyprint_errno(const std::string &pref) {
const char* d = strerrorname_np(errno);
return pref.empty() ? std::string(d) : std::string(pref) + ": " + d;
}
/* This function is VITAL */
bool strIn(const std::string &str, const char *arr[]) {
for (const char** elPtr = arr; *elPtr != NULL; elPtr += 1) {
if (str == (*elPtr))
return true;
}
return false;
}
bool endsIn(const std::string &a, const std::string &b) {
if (b.size() > a.size())
return false;
return std::equal(a.end() - (ssize_t)b.size(), a.end(), b.begin());
}
std::string getSubstring(const std::string &str, size_t A, size_t B) {
ASSERT(A <= B && B <= str.size(), "Incorrect substring segment");
return str.substr(A, B - A);
}
2024-07-27 11:27:52 +00:00
}