bt_common_shell_quote(): accept new parameter `with_single_quotes`
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 8 May 2017 23:40:27 +0000 (19:40 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:42 +0000 (12:57 -0400)
This parameter indicates if the function must put the initial and final
`'` character itself or if it's the caller's job.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
common/common.c
include/babeltrace/common-internal.h

index 8d202ea5f743a50ad290018f87f0ea02e1f22e25..a987e83e060d155e1ffc3f2efef203e7954d2ac4 100644 (file)
@@ -398,7 +398,7 @@ end:
 }
 
 BT_HIDDEN
-GString *bt_common_shell_quote(const char *input)
+GString *bt_common_shell_quote(const char *input, bool with_single_quotes)
 {
        GString *output = g_string_new(NULL);
        const char *ch;
@@ -409,7 +409,10 @@ GString *bt_common_shell_quote(const char *input)
        }
 
        if (strlen(input) == 0) {
-               g_string_assign(output, "''");
+               if (with_single_quotes) {
+                       g_string_assign(output, "''");
+               }
+
                goto end;
        }
 
@@ -430,7 +433,9 @@ GString *bt_common_shell_quote(const char *input)
                goto end;
        }
 
-       g_string_assign(output, "'");
+       if (with_single_quotes) {
+               g_string_assign(output, "'");
+       }
 
        for (ch = input; *ch != '\0'; ch++) {
                if (*ch == '\'') {
@@ -440,7 +445,9 @@ GString *bt_common_shell_quote(const char *input)
                }
        }
 
-       g_string_append_c(output, '\'');
+       if (with_single_quotes) {
+               g_string_append_c(output, '\'');
+       }
 
 end:
        return output;
index b65a9d0cb50a7c500dc861e583623825f4517fb7..13c4b79ac8a045156b55f1700860bfaaa246ab69 100644 (file)
@@ -106,7 +106,7 @@ GString *bt_common_string_until(const char *input, const char *escapable_chars,
                     const char *end_chars, size_t *end_pos);
 
 BT_HIDDEN
-GString *bt_common_shell_quote(const char *input);
+GString *bt_common_shell_quote(const char *input, bool with_single_quotes);
 
 BT_HIDDEN
 bool bt_common_string_is_printable(const char *input);
This page took 0.026413 seconds and 4 git commands to generate.