feat(utils): utils namespace and custom stoul
This commit is contained in:
parent
04e8292009
commit
5214ed3af1
@ -1,7 +1,21 @@
|
|||||||
#include <webserv/config/utils.hpp>
|
#include <webserv/config/utils.hpp>
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace utils
|
||||||
|
{
|
||||||
|
size_t stoul(const std::string &str, int base)
|
||||||
|
{
|
||||||
|
size_t idx = 0;
|
||||||
|
unsigned long value = std::stoul(str, &idx, base);
|
||||||
|
if (idx != str.length())
|
||||||
|
{
|
||||||
|
throw std::invalid_argument("Invalid characters in number: " + str);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
std::string trim(const std::string &str)
|
std::string trim(const std::string &str)
|
||||||
{
|
{
|
||||||
size_t first = str.find_first_not_of(" \t\n\r");
|
size_t first = str.find_first_not_of(" \t\n\r");
|
||||||
@ -48,5 +62,6 @@ size_t findCorrespondingClosingBrace(const std::string &str, size_t openPos)
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::string::npos; // No matching closing brace found
|
return std::string::npos;
|
||||||
}
|
}
|
||||||
|
} // namespace utils
|
||||||
|
|||||||
@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
#include <stddef.h> // for size_t
|
#include <stddef.h> // for size_t
|
||||||
|
|
||||||
|
namespace utils
|
||||||
|
{
|
||||||
|
size_t stoul(const std::string &str, int base = 10);
|
||||||
std::string trimSemi(const std::string &str);
|
std::string trimSemi(const std::string &str);
|
||||||
std::string trim(const std::string &str);
|
std::string trim(const std::string &str);
|
||||||
size_t findCorrespondingClosingBrace(const std::string &str, size_t openPos);
|
size_t findCorrespondingClosingBrace(const std::string &str, size_t openPos);
|
||||||
|
} // namespace utils
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user