int gui_completion_nickncmp (const char *base_word, const char *nick, int max) { char *base_word2, *nick2; int case_sensitive, return_cmp; case_sensitive = CONFIG_BOOLEAN(config_completion_nick_case_sensitive); if (!CONFIG_STRING(config_completion_nick_ignore_chars) || !CONFIG_STRING(config_completion_nick_ignore_chars)[0] || !base_word[0] || !nick[0] || gui_completion_nick_has_ignored_chars (base_word)) { return (case_sensitive) ? strncmp (base_word, nick, max) : string_strncasecmp (base_word, nick, max); } base_word2 = gui_completion_nick_strdup_ignore_chars (base_word); nick2 = gui_completion_nick_strdup_ignore_chars (nick); return_cmp = (case_sensitive) ? strncmp (base_word2, nick2, utf8_strlen (base_word2)) : string_strncasecmp (base_word2, nick2, utf8_strlen (base_word2)); free (base_word2); free (nick2); return return_cmp; }
void gui_completion_list_add (struct t_gui_completion *completion, const char *word, int nick_completion, const char *where) { char buffer[512]; if (!word || !word[0]) return; if (!completion->base_word || !completion->base_word[0] || (nick_completion && (gui_completion_nickncmp (completion->base_word, word, utf8_strlen (completion->base_word)) == 0)) || (!nick_completion && (string_strncasecmp (completion->base_word, word, utf8_strlen (completion->base_word)) == 0))) { if (nick_completion && (completion->base_word_pos == 0)) { snprintf (buffer, sizeof (buffer), "%s%s", word, CONFIG_STRING(config_completion_nick_completer)); weelist_add (completion->completion_list, buffer, where, (nick_completion) ? (void *)1 : (void *)0); } else { weelist_add (completion->completion_list, word, where, (nick_completion) ? (void *)1 : (void *)0); } } }
void gui_completion_list_add (struct t_gui_completion *completion, const char *word, int nick_completion, const char *where) { struct t_gui_completion_word *completion_word; char buffer[512]; int index; if (!word || !word[0]) return; if (!completion->base_word || !completion->base_word[0] || (nick_completion && (gui_completion_nickncmp (completion->base_word, word, utf8_strlen (completion->base_word)) == 0)) || (!nick_completion && (string_strncasecmp (completion->base_word, word, utf8_strlen (completion->base_word)) == 0))) { completion_word = malloc (sizeof (*completion_word)); if (completion_word) { completion_word->nick_completion = nick_completion; completion_word->count = 0; index = -1; if (strcmp (where, WEECHAT_LIST_POS_BEGINNING) == 0) { completion->list->sorted = 0; index = 0; } else if (strcmp (where, WEECHAT_LIST_POS_END) == 0) { completion->list->sorted = 0; index = -1; } if (nick_completion && (completion->base_word_pos == 0)) { snprintf (buffer, sizeof (buffer), "%s%s", word, CONFIG_STRING(config_completion_nick_completer)); completion_word->word = strdup (buffer); arraylist_insert (completion->list, index, completion_word); completion->add_space = 0; } else { completion_word->word = strdup (word); arraylist_insert (completion->list, index, completion_word); } } } }
int gui_completion_nickncmp (const char *base_word, const char *nick, int max) { char *base_word2, *nick2; int return_cmp; if (!CONFIG_STRING(config_completion_nick_ignore_chars) || !CONFIG_STRING(config_completion_nick_ignore_chars)[0] || !base_word || !nick || !base_word[0] || !nick[0] || gui_completion_nick_has_ignored_chars (base_word)) return string_strncasecmp (base_word, nick, max); base_word2 = gui_completion_nick_strdup_ignore_chars (base_word); nick2 = gui_completion_nick_strdup_ignore_chars (nick); return_cmp = string_strncasecmp (base_word2, nick2, utf8_strlen (base_word2)); free (base_word2); free (nick2); return return_cmp; }
struct t_hook * gui_completion_search_command (struct t_weechat_plugin *plugin, const char *command) { struct t_hook *ptr_hook, *hook_for_other_plugin, *hook_incomplete_command; int length_command, allow_incomplete_commands, count_incomplete_commands; hook_for_other_plugin = NULL; hook_incomplete_command = NULL; length_command = strlen (command); count_incomplete_commands = 0; allow_incomplete_commands = CONFIG_BOOLEAN(config_look_command_incomplete); for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted && HOOK_COMMAND(ptr_hook, command) && HOOK_COMMAND(ptr_hook, command)[0]) { if (string_strcasecmp (HOOK_COMMAND(ptr_hook, command), command) == 0) { if (ptr_hook->plugin == plugin) return ptr_hook; hook_for_other_plugin = ptr_hook; } else if (allow_incomplete_commands && (string_strncasecmp (HOOK_COMMAND(ptr_hook, command), command, length_command) == 0)) { hook_incomplete_command = ptr_hook; count_incomplete_commands++; } } } if (hook_for_other_plugin) return hook_for_other_plugin; return (count_incomplete_commands == 1) ? hook_incomplete_command : NULL; }
bool StringUtil::IsFileUrl(const String& input) { return string_strncasecmp( input.data(), input.size(), "file://", sizeof("file://") - 1, sizeof("file://") - 1) == 0; }
TEST(String, Comparison) { /* case-insensitive comparison */ LONGS_EQUAL(0, string_strcasecmp (NULL, NULL)); LONGS_EQUAL(-1, string_strcasecmp (NULL, "abc")); LONGS_EQUAL(1, string_strcasecmp ("abc", NULL)); LONGS_EQUAL(0, string_strcasecmp ("abc", "abc")); LONGS_EQUAL(0, string_strcasecmp ("abc", "ABC")); LONGS_EQUAL(0, string_strcasecmp ("ABC", "ABC")); LONGS_EQUAL(-1, string_strcasecmp ("abc", "def")); LONGS_EQUAL(-1, string_strcasecmp ("abc", "DEF")); LONGS_EQUAL(-1, string_strcasecmp ("ABC", "def")); LONGS_EQUAL(-1, string_strcasecmp ("ABC", "DEF")); LONGS_EQUAL(1, string_strcasecmp ("def", "abc")); LONGS_EQUAL(1, string_strcasecmp ("def", "ABC")); LONGS_EQUAL(1, string_strcasecmp ("DEF", "abc")); LONGS_EQUAL(1, string_strcasecmp ("DEF", "ABC")); /* case-insensitive comparison with max length */ LONGS_EQUAL(0, string_strncasecmp (NULL, NULL, 3)); LONGS_EQUAL(-1, string_strncasecmp (NULL, "abc", 3)); LONGS_EQUAL(1, string_strncasecmp ("abc", NULL, 3)); LONGS_EQUAL(0, string_strncasecmp ("abc", "abc", 3)); LONGS_EQUAL(0, string_strncasecmp ("abcabc", "abcdef", 3)); LONGS_EQUAL(-1, string_strncasecmp ("abcabc", "abcdef", 6)); LONGS_EQUAL(0, string_strncasecmp ("abc", "ABC", 3)); LONGS_EQUAL(0, string_strncasecmp ("abcabc", "ABCDEF", 3)); LONGS_EQUAL(-1, string_strncasecmp ("abcabc", "ABCDEF", 6)); LONGS_EQUAL(0, string_strncasecmp ("ABC", "ABC", 3)); LONGS_EQUAL(0, string_strncasecmp ("ABCABC", "ABCDEF", 3)); LONGS_EQUAL(-1, string_strncasecmp ("ABCABC", "ABCDEF", 6)); LONGS_EQUAL(-1, string_strncasecmp ("abc", "def", 3)); LONGS_EQUAL(-1, string_strncasecmp ("abc", "DEF", 3)); LONGS_EQUAL(-1, string_strncasecmp ("ABC", "def", 3)); LONGS_EQUAL(-1, string_strncasecmp ("ABC", "DEF", 3)); LONGS_EQUAL(1, string_strncasecmp ("def", "abc", 3)); LONGS_EQUAL(1, string_strncasecmp ("def", "ABC", 3)); LONGS_EQUAL(1, string_strncasecmp ("DEF", "abc", 3)); LONGS_EQUAL(1, string_strncasecmp ("DEF", "ABC", 3)); /* case-insensitive comparison with a range */ LONGS_EQUAL(0, string_strcasecmp_range (NULL, NULL, 30)); LONGS_EQUAL(-1, string_strcasecmp_range (NULL, "abc", 30)); LONGS_EQUAL(1, string_strcasecmp_range ("abc", NULL, 30)); LONGS_EQUAL(-1, string_strcasecmp_range ("A", "Z", 30)); LONGS_EQUAL(1, string_strcasecmp_range ("Z", "A", 30)); LONGS_EQUAL(0, string_strcasecmp_range ("A", "a", 30)); LONGS_EQUAL(-1, string_strcasecmp_range ("ë", "€", 30)); LONGS_EQUAL(0, string_strcasecmp_range ("[", "{", 30)); LONGS_EQUAL(0, string_strcasecmp_range ("]", "}", 30)); LONGS_EQUAL(0, string_strcasecmp_range ("\\", "|", 30)); LONGS_EQUAL(0, string_strcasecmp_range ("^", "~", 30)); LONGS_EQUAL(-1, string_strcasecmp_range ("[", "{", 26)); LONGS_EQUAL(-1, string_strcasecmp_range ("]", "}", 26)); LONGS_EQUAL(-1, string_strcasecmp_range ("\\", "|", 26)); LONGS_EQUAL(-1, string_strcasecmp_range ("^", "~", 26)); /* case-insensitive comparison with max length and a range */ LONGS_EQUAL(0, string_strncasecmp_range (NULL, NULL, 3, 30)); LONGS_EQUAL(-1, string_strncasecmp_range (NULL, "abc", 3, 30)); LONGS_EQUAL(1, string_strncasecmp_range ("abc", NULL, 3, 30)); LONGS_EQUAL(-1, string_strncasecmp_range ("ABC", "ZZZ", 3, 30)); LONGS_EQUAL(1, string_strncasecmp_range ("ZZZ", "ABC", 3, 30)); LONGS_EQUAL(0, string_strncasecmp_range ("ABC", "abc", 3, 30)); LONGS_EQUAL(0, string_strncasecmp_range ("ABCABC", "abcdef", 3, 30)); LONGS_EQUAL(-1, string_strncasecmp_range ("ABCABC", "abcdef", 6, 30)); LONGS_EQUAL(-1, string_strncasecmp_range ("ëëë", "€€€", 3, 30)); LONGS_EQUAL(0, string_strncasecmp_range ("[[[", "{{{", 3, 30)); LONGS_EQUAL(0, string_strncasecmp_range ("[[[abc", "{{{def", 3, 30)); LONGS_EQUAL(-1, string_strncasecmp_range ("[[[abc", "{{{def", 6, 30)); LONGS_EQUAL(0, string_strncasecmp_range ("]]]", "}}}", 3, 30)); LONGS_EQUAL(0, string_strncasecmp_range ("]]]abc", "}}}def", 3, 30)); LONGS_EQUAL(-1, string_strncasecmp_range ("]]]abc", "}}}def", 6, 30)); LONGS_EQUAL(0, string_strncasecmp_range ("\\\\\\", "|||", 3, 30)); LONGS_EQUAL(0, string_strncasecmp_range ("\\\\\\abc", "|||def", 3, 30)); LONGS_EQUAL(-1, string_strncasecmp_range ("\\\\\\abc", "|||def", 6, 30)); LONGS_EQUAL(0, string_strncasecmp_range ("^^^", "~~~", 3, 30)); LONGS_EQUAL(0, string_strncasecmp_range ("^^^abc", "~~~def", 3, 30)); LONGS_EQUAL(-1, string_strncasecmp_range ("^^^abc", "~~~def", 6, 30)); LONGS_EQUAL(-1, string_strncasecmp_range ("[[[", "{{{", 3, 26)); LONGS_EQUAL(-1, string_strncasecmp_range ("]]]", "}}}", 3, 26)); LONGS_EQUAL(-1, string_strncasecmp_range ("\\\\\\", "|||", 3, 26)); LONGS_EQUAL(-1, string_strncasecmp_range ("^^^", "~~~", 3, 26)); /* comparison with chars ignored */ LONGS_EQUAL(0, string_strcmp_ignore_chars (NULL, NULL, "", 0)); LONGS_EQUAL(-1, string_strcmp_ignore_chars (NULL, "abc", "", 0)); LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc", NULL, "", 0)); LONGS_EQUAL(-1, string_strcmp_ignore_chars ("ABC", "ZZZ", "", 0)); LONGS_EQUAL(1, string_strcmp_ignore_chars ("ZZZ", "ABC", "", 0)); LONGS_EQUAL(0, string_strcmp_ignore_chars ("ABC", "abc", "", 0)); LONGS_EQUAL(-1, string_strcmp_ignore_chars ("ABC", "abc", "", 1)); LONGS_EQUAL(0, string_strcmp_ignore_chars ("abc..abc", "abcabc", ".", 0)); LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc..abc", "ABCABC", ".", 1)); LONGS_EQUAL(0, string_strcmp_ignore_chars ("abc..abc", "abc-.-.abc", ".-", 0)); LONGS_EQUAL(1, string_strcmp_ignore_chars ("abc..abc", "ABC-.-.ABC", ".-", 1)); }
int hook_command_run_exec (struct t_gui_buffer *buffer, const char *command) { struct t_hook *ptr_hook, *next_hook; int rc, hook_matching, length; char *command2; const char *ptr_command; if (!weechat_hooks[HOOK_TYPE_COMMAND_RUN]) return WEECHAT_RC_OK; ptr_command = command; command2 = NULL; if (command[0] != '/') { length = strlen (command) + 1; command2 = malloc (length); if (command2) { snprintf (command2, length, "/%s", command + 1); ptr_command = command2; } } ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND_RUN]; while (ptr_hook) { next_hook = ptr_hook->next_hook; if (!ptr_hook->deleted && !ptr_hook->running && HOOK_COMMAND_RUN(ptr_hook, command)) { hook_matching = string_match (ptr_command, HOOK_COMMAND_RUN(ptr_hook, command), 0); if (!hook_matching && !strchr (HOOK_COMMAND_RUN(ptr_hook, command), ' ')) { length = strlen (HOOK_COMMAND_RUN(ptr_hook, command)); hook_matching = ((string_strncasecmp (ptr_command, HOOK_COMMAND_RUN(ptr_hook, command), utf8_strlen (HOOK_COMMAND_RUN(ptr_hook, command))) == 0) && ((ptr_command[length] == ' ') || (ptr_command[length] == '\0'))); } if (hook_matching) { ptr_hook->running = 1; rc = (HOOK_COMMAND_RUN(ptr_hook, callback)) ( ptr_hook->callback_pointer, ptr_hook->callback_data, buffer, ptr_command); ptr_hook->running = 0; if (rc == WEECHAT_RC_OK_EAT) { if (command2) free (command2); return rc; } } } ptr_hook = next_hook; } if (command2) free (command2); return WEECHAT_RC_OK; }