summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2014-03-11 15:07:36 +0100
committerSebastien Helleu <flashcode@flashtux.org>2014-03-11 15:07:36 +0100
commit9c838d262827777cbe8d524757b249bc341d3c08 (patch)
tree2f0761930b73529f2eadaeaba167f0eb76c5e609 /src
parent925ba52793779804397818648d8910adeec736ad (diff)
downloadweechat-9c838d262827777cbe8d524757b249bc341d3c08.zip
api: add support of case insensitive search and search by buffer full name in function buffer_search (bug #34318)
Diffstat (limited to 'src')
-rw-r--r--src/gui/gui-buffer.c67
-rw-r--r--src/gui/gui-buffer.h2
2 files changed, 47 insertions, 22 deletions
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 53b214346..65ab5cd3c 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -2036,33 +2036,32 @@ gui_buffer_search_main ()
}
/*
- * Searches for a buffer by plugin and name.
+ * Searches for a buffer by full name (example: "irc.freenode.#weechat").
*/
struct t_gui_buffer *
-gui_buffer_search_by_name (const char *plugin, const char *name)
+gui_buffer_search_by_full_name (const char *full_name)
{
struct t_gui_buffer *ptr_buffer;
- int plugin_match;
+ int case_sensitive;
- if (!name || !name[0])
- return gui_current_window->buffer;
+ case_sensitive = 1;
+ if (strncmp (full_name, "(?i)", 4) == 0)
+ {
+ case_sensitive = 0;
+ full_name += 4;
+ }
for (ptr_buffer = gui_buffers; ptr_buffer;
ptr_buffer = ptr_buffer->next_buffer)
{
- if (ptr_buffer->name)
+ if (ptr_buffer->full_name
+ && ((case_sensitive
+ && strcmp (ptr_buffer->full_name, full_name) == 0)
+ || (!case_sensitive
+ && string_strcasecmp (ptr_buffer->full_name, full_name) == 0)))
{
- plugin_match = 1;
- if (plugin && plugin[0])
- {
- if (strcmp (plugin, gui_buffer_get_plugin_name (ptr_buffer)) != 0)
- plugin_match = 0;
- }
- if (plugin_match && (strcmp (ptr_buffer->name, name) == 0))
- {
- return ptr_buffer;
- }
+ return ptr_buffer;
}
}
@@ -2071,21 +2070,47 @@ gui_buffer_search_by_name (const char *plugin, const char *name)
}
/*
- * Searches for a buffer by full name (example: "irc.freenode.#weechat").
+ * Searches for a buffer by plugin and name.
*/
struct t_gui_buffer *
-gui_buffer_search_by_full_name (const char *full_name)
+gui_buffer_search_by_name (const char *plugin, const char *name)
{
struct t_gui_buffer *ptr_buffer;
+ int plugin_match, case_sensitive;
+
+ if (!name || !name[0])
+ return gui_current_window->buffer;
+
+ if (plugin && (strcmp (plugin, "==") == 0))
+ return gui_buffer_search_by_full_name (name);
+
+ case_sensitive = 1;
+ if (strncmp (name, "(?i)", 4) == 0)
+ {
+ case_sensitive = 0;
+ name += 4;
+ }
for (ptr_buffer = gui_buffers; ptr_buffer;
ptr_buffer = ptr_buffer->next_buffer)
{
- if (ptr_buffer->full_name
- && (strcmp (ptr_buffer->full_name, full_name) == 0))
+ if (ptr_buffer->name)
{
- return ptr_buffer;
+ plugin_match = 1;
+ if (plugin && plugin[0])
+ {
+ if (strcmp (plugin, gui_buffer_get_plugin_name (ptr_buffer)) != 0)
+ plugin_match = 0;
+ }
+ if (plugin_match
+ && ((case_sensitive
+ && strcmp (ptr_buffer->name, name) == 0)
+ || (!case_sensitive
+ && string_strcasecmp (ptr_buffer->name, name) == 0)))
+ {
+ return ptr_buffer;
+ }
}
}
diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h
index 7f9056edb..e3552aa73 100644
--- a/src/gui/gui-buffer.h
+++ b/src/gui/gui-buffer.h
@@ -280,9 +280,9 @@ extern void gui_buffer_add_value_num_displayed (struct t_gui_buffer *buffer,
int value);
extern int gui_buffer_is_main (const char *plugin_name, const char *name);
extern struct t_gui_buffer *gui_buffer_search_main ();
+extern struct t_gui_buffer *gui_buffer_search_by_full_name (const char *full_name);
extern struct t_gui_buffer *gui_buffer_search_by_name (const char *plugin,
const char *name);
-extern struct t_gui_buffer *gui_buffer_search_by_full_name (const char *full_name);
extern struct t_gui_buffer *gui_buffer_search_by_partial_name (const char *plugin,
const char *name);
extern struct t_gui_buffer *gui_buffer_search_by_number (int number);