summaryrefslogtreecommitdiff
path: root/src/core/wee-string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/wee-string.c')
-rw-r--r--src/core/wee-string.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 9ae23d7f3..e40538176 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -1,7 +1,7 @@
/*
* wee-string.c - string functions
*
- * Copyright (C) 2003-2015 Sébastien Helleu <flashcode@flashtux.org>
+ * Copyright (C) 2003-2016 Sébastien Helleu <flashcode@flashtux.org>
*
* This file is part of WeeChat, the extensible chat client.
*
@@ -1587,17 +1587,30 @@ string_replace_regex (const char *string, void *regex, const char *replace,
* This function must not be called directly (call string_split or
* string_split_shared instead).
*
+ * According to keep_eol value:
+ * 0: standard split
+ * 1: each argument contains the argument and all the following arguments
+ * 2: same as 1, and separator is kept at the end of string.
+ *
* Examples:
- * string_split ("abc de fghi", " ", 0, 0, NULL)
- * ==> array[0] = "abc"
- * array[1] = "de"
- * array[2] = "fghi"
- * array[3] = NULL
- * string_split ("abc de fghi", " ", 1, 0, NULL)
- * ==> array[0] = "abc de fghi"
- * array[1] = "de fghi"
- * array[2] = "fghi"
- * array[3] = NULL
+ * string_split ("abc de fghi ", " ", 0, 0, &argc)
+ * ==> array[0] == "abc"
+ * array[1] == "de"
+ * array[2] == "fghi"
+ * array[3] == NULL
+ * argc == 3
+ * string_split ("abc de fghi ", " ", 1, 0, &argc)
+ * ==> array[0] == "abc de fghi"
+ * array[1] == "de fghi"
+ * array[2] == "fghi"
+ * array[3] == NULL
+ * argc == 3
+ * string_split ("abc de fghi ", " ", 2, 0, &argc)
+ * ==> array[0] == "abc de fghi "
+ * array[1] == "de fghi "
+ * array[2] == "fghi "
+ * array[3] == NULL
+ * argc == 3
*/
char **
@@ -1628,7 +1641,8 @@ string_split_internal (const char *string, const char *separators, int keep_eol,
{
ptr++;
}
- i++;
+ if (ptr[0])
+ i++;
}
n_items = i;
@@ -2825,6 +2839,14 @@ string_input_for_buffer (const char *string)
if (!string)
return NULL;
+ /* a single "/" is not a command */
+ if (strcmp (string, "/") == 0)
+ return string;
+
+ /* "/ " is not a command */
+ if (strncmp (string, "/ ", 2) == 0)
+ return string;
+
/* special case for C comments pasted in input line */
if (strncmp (string, "/*", 2) == 0)
return string;
@@ -2839,7 +2861,7 @@ string_input_for_buffer (const char *string)
pos_space = strchr (string + 1, ' ');
/*
- * if there's no other '/' or if '/' is after first space,
+ * if there are no other '/' or if '/' is after first space,
* then it is a command, and return NULL
*/
if (!pos_slash || (pos_space && pos_slash > pos_space))
@@ -2854,9 +2876,13 @@ string_input_for_buffer (const char *string)
next_char = utf8_next_char (string);
- /* there's no next char, then it's a command */
+ /* there's no next char, then it's a not command */
if (!next_char || !next_char[0])
- return NULL;
+ return string;
+
+ /* next char is a space, then it's not a command */
+ if (next_char[0] == ' ')
+ return string;
/* check if first char is doubled: if yes, then it's not a command */
if (utf8_charcmp (string, next_char) == 0)