aboutsummaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorTetralux <1348560+Tetralux@users.noreply.github.com>2019-01-21 12:29:32 +0000
committerTetralux <1348560+Tetralux@users.noreply.github.com>2019-01-28 17:58:48 +0000
commit1e180d611dd6bed9cccb42c4bf68c6f7df5b420e (patch)
tree514797844d54aaaec463653e9f663eb09e3e7e07 /src/string.cpp
parente452765d286c83be5c443950132d045a2d311b7d (diff)
Allow 'odin run program.odin -- <args-for-program.exe>
Diffstat (limited to 'src/string.cpp')
-rw-r--r--src/string.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/string.cpp b/src/string.cpp
index 7ceeb78a1..5f4a28960 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -318,6 +318,27 @@ String concatenate_strings(gbAllocator a, String const &x, String const &y) {
return make_string(data, len);
}
+String string_join_and_quote(gbAllocator a, Array<String> strings) {
+ if (!strings.count) {
+ return make_string(nullptr, 0);
+ }
+
+ isize str_len = 0;
+ for (isize i = 0; i < strings.count; i++) {
+ str_len += strings[i].len;
+ }
+
+ gbString s = gb_string_make_reserve(a, str_len+strings.count); // +strings.count for spaces after args.
+ for (isize i = 0; i < strings.count; i++) {
+ if (i > 0) {
+ s = gb_string_append_fmt(s, " ");
+ }
+ s = gb_string_append_fmt(s, "\"%.*s\" ", LIT(strings[i]));
+ }
+
+ return make_string(cast(u8 *) s, gb_string_length(s));
+}
+
String copy_string(gbAllocator a, String const &s) {
u8 *data = gb_alloc_array(a, u8, s.len+1);
gb_memmove(data, s.text, s.len);
@@ -328,7 +349,6 @@ String copy_string(gbAllocator a, String const &s) {
-
#if defined(GB_SYSTEM_WINDOWS)
int convert_multibyte_to_widechar(char *multibyte_input, int input_length, wchar_t *output, int output_size) {
return MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, multibyte_input, input_length, output, output_size);