mirror of
https://github.com/weechat/weechat.git
synced 2026-07-08 18:53:12 +02:00
api: add infos "nick_color_ignore_case" and "nick_color_name_ignore_case" (issue #194)
This commit is contained in:
+29
-7
@@ -243,6 +243,10 @@ gui_nick_strdup_for_color (const char *nickname)
|
||||
/*
|
||||
* Finds a color name for a nick (according to nick letters).
|
||||
*
|
||||
* If case_range < 0, nick is case sensitive.
|
||||
* If case_range == 0, nick is converted to lower case (with string_tolower).
|
||||
* If case_range > 0, nick is converted to lower case (with string_tolower_range).
|
||||
*
|
||||
* If colors is NULL (most common case), the color returned is either a forced
|
||||
* color (from option "weechat.look.nick_color_force") or a color from option
|
||||
* "weechat.color.chat_nick_colors".
|
||||
@@ -258,16 +262,18 @@ gui_nick_strdup_for_color (const char *nickname)
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_nick_find_color_name (const char *nickname, const char *colors)
|
||||
gui_nick_find_color_name (const char *nickname, int case_range,
|
||||
const char *colors)
|
||||
{
|
||||
int color, num_colors;
|
||||
char *nickname2, **list_colors, *result;
|
||||
char *nickname2, *nickname3, **list_colors, *result;
|
||||
const char *forced_color, *ptr_result;
|
||||
static char *default_color = "default";
|
||||
|
||||
list_colors = NULL;
|
||||
num_colors = 0;
|
||||
nickname2 = NULL;
|
||||
nickname3 = NULL;
|
||||
ptr_result = NULL;
|
||||
|
||||
if (!nickname || !nickname[0])
|
||||
@@ -281,12 +287,13 @@ gui_nick_find_color_name (const char *nickname, const char *colors)
|
||||
}
|
||||
|
||||
nickname2 = gui_nick_strdup_for_color (nickname);
|
||||
if (!nickname2)
|
||||
goto end;
|
||||
|
||||
if (!list_colors)
|
||||
{
|
||||
/* look if color is forced for the nick */
|
||||
forced_color = gui_nick_get_forced_color (
|
||||
(nickname2) ? nickname2 : nickname);
|
||||
forced_color = gui_nick_get_forced_color (nickname2);
|
||||
if (forced_color)
|
||||
{
|
||||
ptr_result = forced_color;
|
||||
@@ -299,9 +306,18 @@ gui_nick_find_color_name (const char *nickname, const char *colors)
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (case_range < 0)
|
||||
nickname3 = strdup (nickname2);
|
||||
else if (case_range == 0)
|
||||
nickname3 = string_tolower (nickname2);
|
||||
else
|
||||
nickname3 = string_tolower_range (nickname2, case_range);
|
||||
if (!nickname3)
|
||||
goto end;
|
||||
|
||||
/* hash nickname to get color */
|
||||
color = gui_nick_hash_color (
|
||||
(nickname2) ? nickname2 : nickname,
|
||||
nickname3,
|
||||
(list_colors) ? num_colors : config_num_nick_colors);
|
||||
ptr_result = (list_colors) ?
|
||||
list_colors[color] : config_nick_colors[color];
|
||||
@@ -312,12 +328,18 @@ end:
|
||||
string_free_split (list_colors);
|
||||
if (nickname2)
|
||||
free (nickname2);
|
||||
if (nickname3)
|
||||
free (nickname3);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finds a color code for a nick (according to nick letters).
|
||||
*
|
||||
* If case_range < 0, nick is case sensitive.
|
||||
* If case_range == 0, nick is converted to lower case (with string_tolower).
|
||||
* If case_range > 0, nick is converted to lower case (with string_tolower_range).
|
||||
*
|
||||
* If colors is NULL (most common case), the color returned is either a forced
|
||||
* color (from option "weechat.look.nick_color_force") or a color from option
|
||||
* "weechat.color.chat_nick_colors".
|
||||
@@ -333,12 +355,12 @@ end:
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_nick_find_color (const char *nickname, const char *colors)
|
||||
gui_nick_find_color (const char *nickname, int case_range, const char *colors)
|
||||
{
|
||||
char *color;
|
||||
const char *ptr_result;
|
||||
|
||||
color = gui_nick_find_color_name (nickname, colors);
|
||||
color = gui_nick_find_color_name (nickname, case_range, colors);
|
||||
ptr_result = gui_color_get_custom (color);
|
||||
if (color)
|
||||
free (color);
|
||||
|
||||
+2
-2
@@ -20,9 +20,9 @@
|
||||
#ifndef WEECHAT_GUI_NICK_H
|
||||
#define WEECHAT_GUI_NICK_H
|
||||
|
||||
extern char *gui_nick_find_color_name (const char *nickname,
|
||||
extern char *gui_nick_find_color_name (const char *nickname, int case_range,
|
||||
const char *colors);
|
||||
extern char *gui_nick_find_color (const char *nickname,
|
||||
extern char *gui_nick_find_color (const char *nickname, int case_range,
|
||||
const char *colors);
|
||||
|
||||
#endif /* WEECHAT_GUI_NICK_H */
|
||||
|
||||
Reference in New Issue
Block a user