1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 05:16:38 +02:00

core: set word_end_offset to character after word

It seemed strange to me to have word_end_offset point to the last
character in the word, rather than the character after the word,
especially now with the word stopping before a newline character which
meant word_end_offset would be -1 if there was no characters before the
newline character.
This commit is contained in:
Trygve Aaberge
2023-05-28 14:56:56 +02:00
committed by Sébastien Helleu
parent 96f41ce4bf
commit 6f3a67fdc1
3 changed files with 24 additions and 24 deletions
+3 -3
View File
@@ -1544,7 +1544,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
/* if message ends with spaces, display them */
if ((word_length <= 0) && (word_length_with_spaces > 0)
&& !ptr_data[word_end_offset + 1])
&& !ptr_data[word_end_offset])
{
word_length = word_length_with_spaces;
}
@@ -1582,7 +1582,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
/* display word */
gui_chat_display_word (window, line, ptr_data,
ptr_end_offset + 1,
ptr_end_offset,
0, num_lines, count,
pre_lines_displayed, &lines_displayed,
simulate,
@@ -1594,7 +1594,7 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line,
else
{
/* move pointer after end of word */
ptr_data = ptr_end_offset + 1;
ptr_data = ptr_end_offset;
if (*(ptr_data - 1) == '\0')
ptr_data = NULL;
+5 -5
View File
@@ -338,7 +338,7 @@ gui_chat_get_word_info (struct t_gui_window *window,
{
if (next_char[0] == '\n')
{
*word_end_offset = next_char - start_data - 1;
*word_end_offset = next_char - start_data;
if (*word_length < 0)
*word_length = 0;
return;
@@ -348,7 +348,7 @@ gui_chat_get_word_info (struct t_gui_window *window,
if (leading_spaces)
*word_start_offset = next_char - start_data;
leading_spaces = 0;
*word_end_offset = next_char2 - start_data - 1;
*word_end_offset = next_char2 - start_data;
char_size_screen = utf8_char_size_screen (next_char);
if (char_size_screen > 0)
(*word_length_with_spaces) += char_size_screen;
@@ -362,11 +362,11 @@ gui_chat_get_word_info (struct t_gui_window *window,
if (leading_spaces)
{
(*word_length_with_spaces)++;
*word_end_offset = next_char2 - start_data - 1;
*word_end_offset = next_char2 - start_data;
}
else
{
*word_end_offset = next_char - start_data - 1;
*word_end_offset = next_char - start_data;
return;
}
}
@@ -375,7 +375,7 @@ gui_chat_get_word_info (struct t_gui_window *window,
}
else
{
*word_end_offset = data + strlen (data) - start_data - 1;
*word_end_offset = data + strlen (data) - start_data;
return;
}
}
+16 -16
View File
@@ -339,31 +339,31 @@ TEST(GuiChat, GetWordInfo)
WEE_GET_WORD_INFO (0, 0, 0, -1, NULL);
WEE_GET_WORD_INFO (0, 0, 0, -1, "");
WEE_GET_WORD_INFO (0, 0, 1, 1, "a");
WEE_GET_WORD_INFO (0, 2, 3, 3, "abc");
WEE_GET_WORD_INFO (2, 4, 5, 3, " abc");
WEE_GET_WORD_INFO (2, 4, 5, 3, " abc ");
WEE_GET_WORD_INFO (0, 4, 5, 5, "first second");
WEE_GET_WORD_INFO (1, 5, 6, 5, " first second");
WEE_GET_WORD_INFO (0, 1, 1, 1, "a");
WEE_GET_WORD_INFO (0, 3, 3, 3, "abc");
WEE_GET_WORD_INFO (2, 5, 5, 3, " abc");
WEE_GET_WORD_INFO (2, 5, 5, 3, " abc ");
WEE_GET_WORD_INFO (0, 5, 5, 5, "first second");
WEE_GET_WORD_INFO (1, 6, 6, 5, " first second");
WEE_GET_WORD_INFO (0, -1, 0, 0, "\nabc");
WEE_GET_WORD_INFO (0, 0, 1, 0, " \nabc");
WEE_GET_WORD_INFO (0, 1, 2, 0, " \nabc");
WEE_GET_WORD_INFO (0, 4, 5, 5, "first\nsecond");
WEE_GET_WORD_INFO (0, 0, 0, 0, "\nabc");
WEE_GET_WORD_INFO (0, 1, 1, 0, " \nabc");
WEE_GET_WORD_INFO (0, 2, 2, 0, " \nabc");
WEE_GET_WORD_INFO (0, 5, 5, 5, "first\nsecond");
snprintf (string, sizeof (string), "%c%c01abc", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR);
WEE_GET_WORD_INFO (4, 6, 3, 3, string);
WEE_GET_WORD_INFO (4, 7, 3, 3, string);
snprintf (string, sizeof (string), "abc%c%c01", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR);
WEE_GET_WORD_INFO (0, 6, 3, 3, string);
WEE_GET_WORD_INFO (0, 7, 3, 3, string);
snprintf (string, sizeof (string), " %c%c01 abc", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR);
WEE_GET_WORD_INFO (6, 8, 5, 3, string);
WEE_GET_WORD_INFO (6, 9, 5, 3, string);
snprintf (string, sizeof (string), "\n%c%c01abc", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR);
WEE_GET_WORD_INFO (0, -1, 0, 0, string);
WEE_GET_WORD_INFO (0, 0, 0, 0, string);
snprintf (string, sizeof (string), "%c%c01\nabc", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR);
WEE_GET_WORD_INFO (0, 3, 0, 0, string);
WEE_GET_WORD_INFO (0, 4, 0, 0, string);
snprintf (string, sizeof (string), " %c%c01 \nabc", GUI_COLOR_COLOR_CHAR, GUI_COLOR_FG_CHAR);
WEE_GET_WORD_INFO (0, 5, 2, 0, string);
WEE_GET_WORD_INFO (0, 6, 2, 0, string);
}
/*