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