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

escape string

parent 4c9aa867
No related branches found
No related tags found
No related merge requests found
...@@ -7,9 +7,33 @@ namespace pyopencl { ...@@ -7,9 +7,33 @@ namespace pyopencl {
void void
dbg_print_str(std::ostream &stm, const char *str, size_t len) dbg_print_str(std::ostream &stm, const char *str, size_t len)
{ {
// TODO escape
stm << '"'; 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 << '"'; stm << '"';
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment