GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — node/src/json_utils.cc at master · emacslisp/node Expand file tree/ Copy pathjson_utils.ccMore file actions 67 lines (58 loc) · 1.68 KB / Copy pathjson_utils.ccFile metadata and controls67 lines (58 loc) · 1.68 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 #include "json_utils.h" namespace node { std::string EscapeJsonChars(const std::string& str) { const std::string control_symbols[0x20] = { "\\u0000", "\\u0001", "\\u0002", "\\u0003", "\\u0004", "\\u0005", "\\u0006", "\\u0007", "\\b", "\\t", "\\n", "\\v", "\\f", "\\r", "\\u000e", "\\u000f", "\\u0010", "\\u0011", "\\u0012", "\\u0013", "\\u0014", "\\u0015", "\\u0016", "\\u0017", "\\u0018", "\\u0019", "\\u001a", "\\u001b", "\\u001c", "\\u001d", "\\u001e", "\\u001f" }; std::string ret; size_t last_pos = 0; size_t pos = 0; for (; pos < str.size(); ++pos) { std::string replace; char ch = str[pos]; if (ch == '\\') { replace = "\\\\"; } else if (ch == '\"') { replace = "\\\""; } else { size_t num = static_cast<size_t>(ch); if (num < 0x20) replace = control_symbols[num]; } if (!replace.empty()) { if (pos > last_pos) { ret += str.substr(last_pos, pos - last_pos); } last_pos = pos + 1; ret += replace; } } // Append any remaining symbols. if (last_pos < str.size()) { ret += str.substr(last_pos, pos - last_pos); } return ret; } std::string Reindent(const std::string& str, int indent_depth) { std::string indent; for (int i = 0; i < indent_depth; i++) indent += ' '; std::string out; std::string::size_type pos = 0; do { std::string::size_type prev_pos = pos; pos = str.find('\n', pos); out.append(indent); if (pos == std::string::npos) { out.append(str, prev_pos, std::string::npos); break; } else { pos++; out.append(str, prev_pos, pos - prev_pos); } } while (true); return out; } } // namespace node |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |