mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2024-12-26 03:14:35 +00:00
Allow common process_escapes to handle \x sequences (#3928)
* Allow common process_escapes to handle \x sequences * Fix edge case when second hex digit is NUL
This commit is contained in:
parent
bb60fd0bf6
commit
d9ccce2e33
@ -90,6 +90,19 @@ void process_escapes(std::string& input) {
|
|||||||
case '\'': input[output_idx++] = '\''; break;
|
case '\'': input[output_idx++] = '\''; break;
|
||||||
case '\"': input[output_idx++] = '\"'; break;
|
case '\"': input[output_idx++] = '\"'; break;
|
||||||
case '\\': input[output_idx++] = '\\'; break;
|
case '\\': input[output_idx++] = '\\'; break;
|
||||||
|
case 'x':
|
||||||
|
// Handle \x12, etc
|
||||||
|
if (input_idx + 2 < input_len) {
|
||||||
|
const char x[3] = { input[input_idx + 1], input[input_idx + 2], 0 };
|
||||||
|
char *err_p = nullptr;
|
||||||
|
const long val = std::strtol(x, &err_p, 16);
|
||||||
|
if (err_p == x + 2) {
|
||||||
|
input_idx += 2;
|
||||||
|
input[output_idx++] = char(val);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Intentionally fall through to default.
|
||||||
|
}
|
||||||
default: input[output_idx++] = '\\';
|
default: input[output_idx++] = '\\';
|
||||||
input[output_idx++] = input[input_idx]; break;
|
input[output_idx++] = input[input_idx]; break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user