Skip to content

Commit

Permalink
"escape" string literals ""properly"" in jsast. Derp derp derp.
Browse files Browse the repository at this point in the history
  • Loading branch information
epriestley committed May 4, 2011
1 parent f85213a commit d9a906e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions support/jsast/jsast.cpp
Expand Up @@ -108,7 +108,7 @@ string get_node_value(Node *node) {
} else if (typeid(*node) == typeid(NodeIdentifier)) { } else if (typeid(*node) == typeid(NodeIdentifier)) {
NodeIdentifier *ni = static_cast<NodeIdentifier *>(node); NodeIdentifier *ni = static_cast<NodeIdentifier *>(node);
return ni->name(); return ni->name();
} }
return ""; return "";
} }


Expand All @@ -130,11 +130,24 @@ void print_tree(Node *node) {
print_tree(*ii); print_tree(*ii);
} }
} }

printf("]"); printf("]");

string s = get_node_value(node); string s = get_node_value(node);
if (s.length()) { if (s.length()) {
printf(", \"%s\", \"%d\"", s.c_str(), node->lineno()); int len = s.length();
char *dst = new char[s.length() * 2];
const char *src = s.c_str();
const char *end = src + len;
char *ptr = dst;
for (; src != end; src++) {
if (*src == '\\' || *src == '"') {
(*ptr++) = '\\';
}
(*ptr++) = *src;
}
(*ptr) = 0;
printf(", \"%s\", \"%d\"", dst, node->lineno());
delete[] dst;
} }


printf("]"); printf("]");
Expand Down

0 comments on commit d9a906e

Please sign in to comment.