18 res.reserve(str.length());
21 if (c == esc or c ==
quote) {
24 }
else if (c ==
'\n') {
38 res.reserve(str.length());
40 for (
auto it = str.begin(), end = str.end(); it != end; ++it) {
43 if (*it == esc or *it ==
quote) {
45 }
else if (*it ==
'n') {
68bool m::like(
const std::string &str,
const std::string &pattern,
const char escape_char)
70 M_insist(
'_' != escape_char
and '%' != escape_char,
"illegal escape character");
72 bool dp[pattern.length() + 1][str.length() + 1];
75 for (std::size_t j = 1; j <= str.length(); ++j)
77 std::size_t escaped_row = 0;
78 for (std::size_t i = 1; i <= pattern.length(); ++i) {
79 const auto c = pattern[i - 1];
80 const auto escaped = i == escaped_row;
81 if (escaped
and '_' != c
and '%' != c
and escape_char != c)
83 if (not escaped
and escape_char == c)
85 if (not escaped
and '%' == c)
86 dp[i][0] = dp[i - 1][0];
90 if (pattern.length() + 1 == escaped_row)
94 for (std::size_t i = 1; i <= pattern.length(); ++i) {
95 const auto c = pattern[i - 1];
96 const auto escaped = i == escaped_row;
97 if (not escaped
and escape_char == c) {
100 for (std::size_t j = 0; j <= str.length(); ++j)
101 dp[i][j] = dp[i - 1][j];
104 for (std::size_t j = 1; j <= str.length(); ++j) {
105 if (not escaped
and '%' == c) {
108 dp[i][j] = dp[i][j - 1] or dp[i - 1][j];
109 }
else if ((not escaped
and '_' == c) or str[j - 1] == c) {
112 dp[i][j] = dp[i - 1][j - 1];
120 return dp[pattern.length()][str.length()];
123void m::exec(
const char *executable, std::initializer_list<const char*>
args)
125#if __linux || __APPLE__
130 char **c_args =
new char*[
args.size() + 2];
132 *p++ = strdup(executable);
133 for (
auto arg :
args)
136 execv(executable, c_args);
144 static std::size_t pagesize(0);
146 pagesize = sysconf(_SC_PAGESIZE);
#define M_unreachable(MSG)
std::string replace_all(std::string str, const std::string &from, const std::string &to)
std::string escape(char c)
std::string quote(const std::string &str)
std::string M_EXPORT unescape(const std::string &str, char esc='\\', char quote='"')
void M_EXPORT exec(const char *executable, std::initializer_list< const char * > args)
std::string M_EXPORT html_escape(std::string str)
Escapes special characters in a string to be printable in HTML documents.
std::size_t M_EXPORT get_pagesize()
Returns the page size of the system.
bool M_EXPORT like(const std::string &str, const std::string &pattern, const char escape_char='\\')
Compares a SQL-style LIKE pattern with the given std::string.
Signals a runtime error that mu*t*able is not responsible for and that mu*t*able was not able to reco...