mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-20 22:16:21 +00:00
fix: ensure consistent unescaping and space handling
Unescape any character following a backslash. This fixes autocompletion for names with escaped spaces. For example: `/msg Thor\ Odinson hello` Signed-off-by: Michael Vetter <jubalh@iodoru.org>
This commit is contained in:
@@ -237,7 +237,7 @@ autocomplete_complete(Autocomplete ac, const gchar* search_str, gboolean quote,
|
||||
// unescape search string
|
||||
GString* unescaped = g_string_new("");
|
||||
for (const char* p = search_str; *p; p++) {
|
||||
if (*p == '\\' && (*(p + 1) == '"' || *(p + 1) == '\\')) {
|
||||
if (*p == '\\' && (*(p + 1) != '\0')) {
|
||||
p++;
|
||||
}
|
||||
g_string_append_c(unescaped, *p);
|
||||
|
||||
@@ -272,6 +272,15 @@ count_tokens(const char* const string)
|
||||
if (curr_uni == ' ') {
|
||||
if (!in_quotes) {
|
||||
num_tokens++;
|
||||
while (i + 1 < length) {
|
||||
gchar* next_ch = g_utf8_offset_to_pointer(string, i + 1);
|
||||
gunichar next_uni = g_utf8_get_char(next_ch);
|
||||
if (next_uni == ' ') {
|
||||
i++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (curr_uni == '"') {
|
||||
if (in_quotes) {
|
||||
@@ -319,6 +328,18 @@ get_start(const char* const string, int tokens)
|
||||
if (curr_uni == ' ') {
|
||||
if (!in_quotes) {
|
||||
num_tokens++;
|
||||
while (i + 1 < length) {
|
||||
gchar* next_ch = g_utf8_offset_to_pointer(string, i + 1);
|
||||
gunichar next_uni = g_utf8_get_char(next_ch);
|
||||
if (next_uni == ' ') {
|
||||
if (num_tokens <= tokens) {
|
||||
g_string_append_unichar(result, next_uni);
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (curr_uni == '"') {
|
||||
if (in_quotes) {
|
||||
|
||||
Reference in New Issue
Block a user