20 res.reserve(str.length());
23 if (c == esc or c ==
quote) {
26 }
else if (c ==
'\n') {
40 res.reserve(str.length());
42 for (
auto it = str.begin(), end = str.end(); it != end; ++it) {
45 if (*it == esc or *it ==
quote) {
47 }
else if (*it ==
'n') {
70bool m::like(
const std::string &str,
const std::string &pattern,
const char escape_char)
72 M_insist(
'_' != escape_char
and '%' != escape_char,
"illegal escape character");
74 bool dp[pattern.length() + 1][str.length() + 1];
77 for (std::size_t j = 1; j <= str.length(); ++j)
79 std::size_t escaped_row = 0;
80 for (std::size_t i = 1; i <= pattern.length(); ++i) {
81 const auto c = pattern[i - 1];
82 const auto escaped = i == escaped_row;
83 if (escaped
and '_' != c
and '%' != c
and escape_char != c)
85 if (not escaped
and escape_char == c)
87 if (not escaped
and '%' == c)
88 dp[i][0] = dp[i - 1][0];
92 if (pattern.length() + 1 == escaped_row)
96 for (std::size_t i = 1; i <= pattern.length(); ++i) {
97 const auto c = pattern[i - 1];
98 const auto escaped = i == escaped_row;
99 if (not escaped
and escape_char == c) {
102 for (std::size_t j = 0; j <= str.length(); ++j)
103 dp[i][j] = dp[i - 1][j];
106 for (std::size_t j = 1; j <= str.length(); ++j) {
107 if (not escaped
and '%' == c) {
110 dp[i][j] = dp[i][j - 1] or dp[i - 1][j];
111 }
else if ((not escaped
and '_' == c) or str[j - 1] == c) {
114 dp[i][j] = dp[i - 1][j - 1];
122 return dp[pattern.length()][str.length()];
125void m::exec(
const char *executable, std::initializer_list<const char*>
args)
127#if __linux || __APPLE__
132 waitpid(pid, &status, 0);
133 }
else if (pid == 0) {
135 char **c_args =
new char*[
args.size() + 2];
137 *p++ = strdup(executable);
138 for (
auto arg :
args)
141 execv(executable, c_args);
149 static std::size_t pagesize(0);
151 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...