MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / process_escapes

Function process_escapes

common/common.cpp:80–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80void process_escapes(std::string& input) {
81 std::size_t input_len = input.length();
82 std::size_t output_idx = 0;
83
84 for (std::size_t input_idx = 0; input_idx < input_len; ++input_idx) {
85 if (input[input_idx] == '\\' && input_idx + 1 < input_len) {
86 switch (input[++input_idx]) {
87 case 'n': input[output_idx++] = '\n'; break;
88 case 'r': input[output_idx++] = '\r'; break;
89 case 't': input[output_idx++] = '\t'; break;
90 case '\'': input[output_idx++] = '\''; break;
91 case '\"': input[output_idx++] = '\"'; break;
92 case '\\': input[output_idx++] = '\\'; break;
93 case 'x':
94 // Handle \x12, etc
95 if (input_idx + 2 < input_len) {
96 const char x[3] = { input[input_idx + 1], input[input_idx + 2], 0 };
97 char *err_p = nullptr;
98 const long val = std::strtol(x, &err_p, 16);
99 if (err_p == x + 2) {
100 input_idx += 2;
101 input[output_idx++] = char(val);
102 break;
103 }
104 }
105 // fall through
106 default: input[output_idx++] = '\\';
107 input[output_idx++] = input[input_idx]; break;
108 }
109 } else {
110 input[output_idx++] = input[input_idx];
111 }
112 }
113
114 input.resize(output_idx);
115}
116
117bool gpt_params_parse(int argc, char ** argv, gpt_params & params) {
118 bool result = true;

Callers 4

gpt_params_parse_exFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 2

lengthMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected