4wchar_t *escape_for_batch(
const wchar_t *input,
size_t n_chars) {
5 if (input ==
nullptr || n_chars == 0) {
10 size_t new_n_chars = 0;
11 for (i = 0; i < n_chars; i++) {
14 if (input[i] == L
'\\' || input[i] == L
'%' || input[i] == L
'"' ||
15 (input[i] == L
'\0' && i < (n_chars - 1))) {
19 wchar_t *out = calloc(new_n_chars + 1, WL);
23 wmemset(out, L
'\0', new_n_chars + 1);
24 if (n_chars == new_n_chars) {
25 wmemcpy(out, input, new_n_chars + 1);
28 for (i = 0, j = 0; i < n_chars && j < new_n_chars; i++, j++) {
30 if (input[i] ==
'\0' && i < (n_chars - 1) && j < (new_n_chars - 1)) {
35 if (input[i] == L
'"' || input[i] == L
'%') {