Skip to content
Snippets Groups Projects
Commit 4ef31701 authored by Yichao Yu's avatar Yichao Yu
Browse files

escape string

parent 4c9aa867
Branches
Tags
No related merge requests found
......@@ -7,9 +7,33 @@ namespace pyopencl {
void
dbg_print_str(std::ostream &stm, const char *str, size_t len)
{
// TODO escape
stm << '"';
stm.write(str, len);
for (size_t i = 0;i < len;i++) {
char escaped = 0;
#define escape_char(in, out) \
case in: \
escaped = out; \
break
switch (str[i]) {
escape_char('\'', '\'');
escape_char('\"', '\"');
escape_char('\?', '\?');
escape_char('\\', '\\');
escape_char('\0', '0');
escape_char('\a', 'a');
escape_char('\b', 'b');
escape_char('\f', 'f');
escape_char('\r', 'r');
escape_char('\v', 'v');
default:
break;
}
if (escaped) {
stm << '\\' << escaped;
} else {
stm << str[i];
}
}
stm << '"';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment