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

Function string_process_escapes

smallthinker/common/common.cpp:602–637  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

600}
601
602void string_process_escapes(std::string & input) {
603 std::size_t input_len = input.length();
604 std::size_t output_idx = 0;
605
606 for (std::size_t input_idx = 0; input_idx < input_len; ++input_idx) {
607 if (input[input_idx] == '\\' && input_idx + 1 < input_len) {
608 switch (input[++input_idx]) {
609 case 'n': input[output_idx++] = '\n'; break;
610 case 'r': input[output_idx++] = '\r'; break;
611 case 't': input[output_idx++] = '\t'; break;
612 case '\'': input[output_idx++] = '\''; break;
613 case '\"': input[output_idx++] = '\"'; break;
614 case '\\': input[output_idx++] = '\\'; break;
615 case 'x':
616 // Handle \x12, etc
617 if (input_idx + 2 < input_len) {
618 const char x[3] = { input[input_idx + 1], input[input_idx + 2], 0 };
619 char *err_p = nullptr;
620 const long val = std::strtol(x, &err_p, 16);
621 if (err_p == x + 2) {
622 input_idx += 2;
623 input[output_idx++] = char(val);
624 break;
625 }
626 }
627 // fall through
628 default: input[output_idx++] = '\\';
629 input[output_idx++] = input[input_idx]; break;
630 }
631 } else {
632 input[output_idx++] = input[input_idx];
633 }
634 }
635
636 input.resize(output_idx);
637}
638
639bool string_parse_kv_override(const char * data, std::vector<llama_model_kv_override> & overrides) {
640 const char * sep = strchr(data, '=');

Callers 4

ctrlvec_load_prompt_fileFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
common_params_parse_exFunction · 0.85

Calls 2

lengthMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected