Made errors mostly work as hoped
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
|
||||
namespace nb {
|
||||
|
||||
const std::string Error::type = "Error";
|
||||
const ErrorCodeMap Error::ErrorMessages = {
|
||||
{ErrorCodes::GENERAL, "General std::exception."},
|
||||
{ErrorCodes::UNDEFINED, "Undefined / general error."},
|
||||
{ErrorCodes::BADERRORCODE, "Unrecognized error code."}
|
||||
const std::string Error<DefaultError>::type = "nb::Error";
|
||||
|
||||
const ErrorCodeMap Error<DefaultError>::ErrorMessages = {
|
||||
{Error::Codes::GENERAL, "General std::exception."},
|
||||
{Error::Codes::UNDEFINED, "Undefined / general error."},
|
||||
{Error::Codes::BADERRORCODE, "Unrecognized error code."}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#endif // _NB_TARGET_LINUX
|
||||
|
||||
#include "Processes.hpp"
|
||||
#include "Types.hpp"
|
||||
|
||||
namespace nb {
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <string>
|
||||
#include "Utils.hpp"
|
||||
|
||||
|
||||
std::string nb::find_and_replace(const std::string& original, const std::string& find, const std::string& replace) {
|
||||
std::string ret = original;
|
||||
|
||||
std::size_t find_len = find.length();
|
||||
std::size_t replace_len = replace.length();
|
||||
std::size_t currpos = 0;
|
||||
std::size_t lastpos = 0;
|
||||
while(true) {
|
||||
lastpos = currpos;
|
||||
currpos = original.find(find, lastpos);
|
||||
if (currpos == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
ret = ret.erase(currpos, find_len);
|
||||
ret = ret.insert(currpos, replace);
|
||||
currpos += replace_len;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user