Implement C++ pretty-printer
This commit is contained in:
@@ -35,6 +35,38 @@ bool is_identifier(const std::string &str) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void quote_string(const std::string &s, std::ostream *os) {
|
||||
bool usesinglequote = false;
|
||||
for (char c : s) {
|
||||
if (c == '"') {
|
||||
usesinglequote = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
(*os) << (usesinglequote ? '\'' : '"');
|
||||
for (char c : s) {
|
||||
if (c >= 32) {
|
||||
if (c == '"') {
|
||||
(*os) << (usesinglequote ? "\"" : "\\\"");
|
||||
} else if (c == '\'') {
|
||||
(*os) << (usesinglequote ? "\\'" : "'");
|
||||
} else {
|
||||
(*os) << c;
|
||||
}
|
||||
} else {
|
||||
switch (c) {
|
||||
case '\n': (*os) << "\\n"; break;
|
||||
case '\t': (*os) << "\\t"; break;
|
||||
case '\r': (*os) << "\\r"; break;
|
||||
default:
|
||||
(*os) << "\\" << std::setw(3) << int(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
(*os) << (usesinglequote ? '\'' : '"');
|
||||
}
|
||||
|
||||
IdVector id_vector_create(int64_t id1, int64_t id2, int64_t id3, int64_t id4) {
|
||||
IdVector result;
|
||||
if (id1 >= 0) result.push_back(id1);
|
||||
|
||||
Reference in New Issue
Block a user