TEST(String, Iconv) { const char *noel_utf8 = "no\xc3\xabl"; /* noël */ const char *noel_iso = "no\xebl"; char *str; FILE *f; /* string_iconv */ WEE_TEST_STR(NULL, string_iconv (0, NULL, NULL, NULL)); WEE_TEST_STR("", string_iconv (0, NULL, NULL, "")); WEE_TEST_STR("abc", string_iconv (0, NULL, NULL, "abc")); WEE_TEST_STR("abc", string_iconv (1, "UTF-8", "ISO-8859-15", "abc")); WEE_TEST_STR(noel_iso, string_iconv (1, "UTF-8", "ISO-8859-15", noel_utf8)); WEE_TEST_STR(noel_utf8, string_iconv (0, "ISO-8859-15", "UTF-8", noel_iso)); /* string_iconv_to_internal */ WEE_TEST_STR(NULL, string_iconv_to_internal (NULL, NULL)); WEE_TEST_STR("", string_iconv_to_internal (NULL, "")); WEE_TEST_STR("abc", string_iconv_to_internal (NULL, "abc")); WEE_TEST_STR(noel_utf8, string_iconv_to_internal ("ISO-8859-15", noel_iso)); /* string_iconv_from_internal */ WEE_TEST_STR(NULL, string_iconv_from_internal (NULL, NULL)); WEE_TEST_STR("", string_iconv_from_internal (NULL, "")); WEE_TEST_STR("abc", string_iconv_from_internal (NULL, "abc")); WEE_TEST_STR(noel_iso, string_iconv_from_internal ("ISO-8859-15", noel_utf8)); /* string_iconv_fprintf */ f = fopen ("/dev/null", "w"); LONGS_EQUAL(0, string_iconv_fprintf (f, NULL)); LONGS_EQUAL(1, string_iconv_fprintf (f, "abc")); LONGS_EQUAL(1, string_iconv_fprintf (f, noel_utf8)); LONGS_EQUAL(1, string_iconv_fprintf (f, noel_iso)); fclose (f); }
int gui_bar_window_print_string (struct t_gui_bar_window *bar_window, enum t_gui_bar_filling filling, int *x, int *y, const char *string, int reset_color_before_display, int hide_chars_if_scrolling, int *index_item, int *index_subitem, int *index_line) { int x_with_hidden, size_on_screen, low_char, hidden; char utf_char[16], *next_char, *output; if (!string || !string[0]) return 1; wmove (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, *y, *x); if (reset_color_before_display) { gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]), CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG])); } x_with_hidden = *x; hidden = 0; while (string && string[0]) { switch (string[0]) { case GUI_COLOR_COLOR_CHAR: string++; switch (string[0]) { case GUI_COLOR_FG_CHAR: /* fg color */ string++; gui_window_string_apply_color_fg ((unsigned char **)&string, GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar); break; case GUI_COLOR_BG_CHAR: /* bg color */ string++; gui_window_string_apply_color_bg ((unsigned char **)&string, GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar); break; case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */ string++; gui_window_string_apply_color_fg_bg ((unsigned char **)&string, GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar); break; case GUI_COLOR_EXTENDED_CHAR: /* pair number */ string++; gui_window_string_apply_color_pair ((unsigned char **)&string, GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar); break; case GUI_COLOR_EMPHASIS_CHAR: /* emphasis */ string++; gui_window_toggle_emphasis (); break; case GUI_COLOR_BAR_CHAR: /* bar color */ switch (string[1]) { case GUI_COLOR_BAR_FG_CHAR: /* bar foreground */ string += 2; gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG])); break; case GUI_COLOR_BAR_DELIM_CHAR: /* bar delimiter */ string += 2; gui_window_set_custom_color_fg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_DELIM])); break; case GUI_COLOR_BAR_BG_CHAR: /* bar background */ string += 2; gui_window_set_custom_color_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG])); break; case GUI_COLOR_BAR_START_INPUT_CHAR: string += 2; hidden = 0; break; case GUI_COLOR_BAR_START_INPUT_HIDDEN_CHAR: string += 2; hidden = 1; break; case GUI_COLOR_BAR_MOVE_CURSOR_CHAR: /* move cursor to current position on screen */ string += 2; getyx (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, bar_window->cursor_y, bar_window->cursor_x); bar_window->cursor_x += bar_window->x; bar_window->cursor_y += bar_window->y; break; case GUI_COLOR_BAR_START_ITEM: string += 2; if (*index_item < 0) { *index_item = 0; *index_subitem = 0; } else { (*index_subitem)++; if (*index_subitem >= bar_window->items_subcount[*index_item]) { (*index_item)++; *index_subitem = 0; } } *index_line = 0; gui_bar_window_coords_add (bar_window, (*index_item >= bar_window->items_count) ? -1 : *index_item, (*index_item >= bar_window->items_count) ? -1 : *index_subitem, *index_line, *x + bar_window->x, *y + bar_window->y); break; case GUI_COLOR_BAR_START_LINE_ITEM: string += 2; (*index_line)++; gui_bar_window_coords_add (bar_window, *index_item, *index_subitem, *index_line, *x + bar_window->x, *y + bar_window->y); break; default: string++; break; } break; case GUI_COLOR_RESET_CHAR: /* reset color (keep attributes) */ string++; gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]), CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG])); break; default: gui_window_string_apply_color_weechat ((unsigned char **)&string, GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar); break; } break; case GUI_COLOR_SET_ATTR_CHAR: string++; gui_window_string_apply_color_set_attr ((unsigned char **)&string, GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar); break; case GUI_COLOR_REMOVE_ATTR_CHAR: string++; gui_window_string_apply_color_remove_attr ((unsigned char **)&string, GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar); break; case GUI_COLOR_RESET_CHAR: string++; gui_window_remove_color_style (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_ALL_ATTR); gui_window_set_custom_color_fg_bg (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_FG]), CONFIG_COLOR(bar_window->bar->options[GUI_BAR_OPTION_COLOR_BG])); break; default: next_char = utf8_next_char (string); if (!next_char) break; memcpy (utf_char, string, next_char - string); utf_char[next_char - string] = '\0'; if ((((unsigned char)utf_char[0]) < 32) && (!utf_char[1])) { low_char = 1; snprintf (utf_char, sizeof (utf_char), "%c", 'A' + ((unsigned char)utf_char[0]) - 1); } else { low_char = 0; if (!gui_chat_utf_char_valid (utf_char)) snprintf (utf_char, sizeof (utf_char), " "); } size_on_screen = utf8_char_size_screen (utf_char); if (size_on_screen >= 0) { if (hide_chars_if_scrolling && (x_with_hidden < bar_window->scroll_x)) { /* hidden char (before scroll_x value) */ x_with_hidden++; } else if (!hidden) { if (*x + size_on_screen > bar_window->width) { if (filling == GUI_BAR_FILLING_VERTICAL) return 1; if (*y >= bar_window->height - 1) return 0; *x = 0; (*y)++; wmove (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, *y, *x); } output = string_iconv_from_internal (NULL, utf_char); if (low_char) wattron (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE); waddstr (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, (output) ? output : utf_char); if (low_char) wattroff (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, A_REVERSE); if (output) free (output); if (gui_window_current_emphasis) { gui_window_emphasize (GUI_BAR_WINDOW_OBJECTS(bar_window)->win_bar, *x, *y, size_on_screen); } *x += size_on_screen; } } string = next_char; break; } } return 1; }