aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-07-23 09:40:22 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-07-23 09:40:22 +0200
commit8c0c5cb28ce74d4eb66a3161dadaa07068b15383 (patch)
tree12c3b8c35efa7a68b5875f38fbcfd07077ee5c1f /src/tools
parenta5ca65453e04a2af2b01c1c0bfb65c9a5cc1563e (diff)
downloadprofani-tty-8c0c5cb28ce74d4eb66a3161dadaa07068b15383.tar.gz
Fix /correct quotation marks usage
Add new `parse_args_as_one()` function to just use everything after the command as the argument. Fix https://github.com/profanity-im/profanity/issues/1404
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/parser.c27
-rw-r--r--src/tools/parser.h1
2 files changed, 28 insertions, 0 deletions
diff --git a/src/tools/parser.c b/src/tools/parser.c
index 7365f1a3..beb61383 100644
--- a/src/tools/parser.c
+++ b/src/tools/parser.c
@@ -222,6 +222,33 @@ parse_args_with_freetext(const char* const inp, int min, int max, gboolean* resu
return _parse_args_helper(inp, min, max, result, TRUE);
}
+/*
+ * Will just take everything after the first space as the argument.
+ * Used for `/correct` so that we also include quotation marks.
+ */
+gchar**
+parse_args_as_one(const char* const inp, int min, int max, gboolean* result)
+{
+ gchar** args = g_malloc0(2 * sizeof(*args));
+ int length = g_utf8_strlen(inp, -1);
+ gchar* space = g_utf8_strchr(inp, length, ' ');
+ if (space) {
+ int sub_length = g_utf8_strlen(space, -1);
+ if (sub_length > 1) {
+ args[0] = g_strdup(space + 1);
+ *result = TRUE;
+ return args;
+ } else {
+ g_free(args);
+ }
+ } else {
+ g_free(args);
+ }
+
+ *result = FALSE;
+ return NULL;
+}
+
int
count_tokens(const char* const string)
{
diff --git a/src/tools/parser.h b/src/tools/parser.h
index d1b6f7bf..054ab2b7 100644
--- a/src/tools/parser.h
+++ b/src/tools/parser.h
@@ -40,6 +40,7 @@
gchar** parse_args(const char* const inp, int min, int max, gboolean* result);
gchar** parse_args_with_freetext(const char* const inp, int min, int max, gboolean* result);
+gchar** parse_args_as_one(const char* const inp, int min, int max, gboolean* result);
int count_tokens(const char* const string);
char* get_start(const char* const string, int tokens);
GHashTable* parse_options(gchar** args, gchar** keys, gboolean* res);