aboutsummaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2019-01-29 22:12:01 +0000
committerGitHub <noreply@github.com>2019-01-29 22:12:01 +0000
commit96ef6aa7f34677a8fc46f7807f2d12346c02a5bb (patch)
treebacb8a68862c5821ff9377909c034caebc3bc9a1 /src/string.cpp
parent238a40321a5e1a759f0e9e449e9e9d134cbe7537 (diff)
parent1e180d611dd6bed9cccb42c4bf68c6f7df5b420e (diff)
Merge pull request #327 from Tetralux/tet/pass-args-to-run
Provide a way to pass arguments to compiled executable during 'odin run program.odin'.
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);