diff options
| author | Dominik Pötzschke <16013351+dpoetzschke@users.noreply.github.com> | 2024-10-30 11:24:50 +0100 |
|---|---|---|
| committer | Dominik Pötzschke <16013351+dpoetzschke@users.noreply.github.com> | 2024-10-30 11:24:50 +0100 |
| commit | 6f966f30aab6f739dd65301500a6a0aff67da1d5 (patch) | |
| tree | 203ec93e5e61d4ad8932ca28482db52259636fe2 /src/string.cpp | |
| parent | d8187d1cf26668adf1bac9bea7389f3f31f22d86 (diff) | |
fix: fix windows params bug
Diffstat (limited to 'src/string.cpp')
| -rw-r--r-- | src/string.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/string.cpp b/src/string.cpp index 3c7d96934..14f56e4f0 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -411,6 +411,25 @@ gb_internal String concatenate4_strings(gbAllocator a, String const &x, String c return make_string(data, len); } +#if defined(GB_SYSTEM_WINDOWS) +gb_internal String escape_char(gbAllocator a, String s, char cte) { + isize buf_len = s.len; + u8 *buf = gb_alloc_array(a, u8, buf_len); + isize i = 0; + for (isize j = 0; j < s.len; j++) { + u8 c = s.text[j]; + + if (c == cte) { + buf[i++] = '\\'; + buf[i++] = c; + } else { + buf[i++] = c; + } + } + return make_string(buf, i); +} +#endif + gb_internal String string_join_and_quote(gbAllocator a, Array<String> strings) { if (!strings.count) { return make_string(nullptr, 0); @@ -426,7 +445,11 @@ gb_internal String string_join_and_quote(gbAllocator a, Array<String> strings) { if (i > 0) { s = gb_string_append_fmt(s, " "); } +#if defined(GB_SYSTEM_WINDOWS) + s = gb_string_append_fmt(s, "\"%.*s\" ", LIT(escape_char(a, strings[i], '\\'))); +#else s = gb_string_append_fmt(s, "\"%.*s\" ", LIT(strings[i])); +#endif } return make_string(cast(u8 *) s, gb_string_length(s)); |