예제 #1
0
파일: main.c 프로젝트: jdolan/quetoo
/**
 * @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);
}
예제 #2
0
 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));
 }
예제 #3
0
 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);
 }
예제 #4
0
 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));
 }