/** * @brief This routine appends the given argument to a command line such that CommandLineToArgvW will return the argument string unchanged. Arguments in a command line should be separated by spaces; this function does not add these spaces. Thanks @ https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/ */ static gchar *ArgvQuote(const gchar *argument, const _Bool force) { if (!force && strlen(argument) > 0 && str_find_first_of(argument, " \t\n\v\"") == -1) { return g_strdup(argument); } GString *commandLine = g_string_new("\""); for (const char *c = argument; ; ++c) { size_t num_slashes = 0; while (*c && *c == '\\') { c++; num_slashes++; } if (!*c) { for (size_t i = 0; i < num_slashes * 2; i++) { g_string_append_c(commandLine, '\\'); } break; } else if (*c == '"') { for (size_t i = 0; i < (num_slashes * 2) + 1; i++) { g_string_append_c(commandLine, '\\'); } } else { for (size_t i = 0; i < num_slashes; i++) { g_string_append_c(commandLine, '\\'); } } g_string_append_c(commandLine, *c); } g_string_append_c(commandLine, '"'); return g_string_free(commandLine, false); }
UtfIterator<C> str_find_first_of(const basic_string<C>& str, const C* target) { return str_find_first_of(utf_begin(str), utf_end(str), cstr(target)); }
UtfIterator<C> str_find_first_of(const Irange<UtfIterator<C>>& range, const basic_string<C>& target) { return str_find_first_of(range.begin(), range.end(), target); }
UtfIterator<C> str_find_first_of(const UtfIterator<C>& b, const UtfIterator<C>& e, const C* target) { return str_find_first_of(b, e, cstr(target)); }