mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 17:23:15 +02:00
core: fix cut of chars in "cutscr" of evaluated strings
This fixes two problems:
- stop before max char displayed with wide chars
- preserve combining chars in the output
Before the fix (wrong):
>> ${cutscr:3,+,こんにちは世界}
== [こん+]
>> ${cutscr:1,+,a${\u0308}}
== [a+]
After the fix (OK):
>> ${cutscr:3,+,こんにちは世界}
== [こ+]
>> ${cutscr:1,+,a${\u0308}}
== [ä]
This commit is contained in:
+3
-1
@@ -224,7 +224,7 @@ gui_chat_string_add_offset_screen (const char *string, int offset_screen)
|
||||
{
|
||||
int size_on_screen;
|
||||
|
||||
while (string && string[0] && (offset_screen > 0))
|
||||
while (string && string[0] && (offset_screen >= 0))
|
||||
{
|
||||
string = gui_chat_string_next_char (NULL, NULL,
|
||||
(unsigned char *)string,
|
||||
@@ -233,6 +233,8 @@ gui_chat_string_add_offset_screen (const char *string, int offset_screen)
|
||||
{
|
||||
size_on_screen = gui_chat_char_size_screen (string);
|
||||
offset_screen -= size_on_screen;
|
||||
if (offset_screen < 0)
|
||||
return string;
|
||||
string = utf8_next_char (string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,16 +220,46 @@ TEST(Eval, EvalExpression)
|
||||
|
||||
/* test cut of chars */
|
||||
WEE_CHECK_EVAL("", "${cut:0,,}");
|
||||
WEE_CHECK_EVAL("", "${cutscr:0,,}");
|
||||
|
||||
WEE_CHECK_EVAL("", "${cut:0,+,}");
|
||||
WEE_CHECK_EVAL("", "${cutscr:0,+,}");
|
||||
|
||||
WEE_CHECK_EVAL("", "${cut:0,,test}");
|
||||
WEE_CHECK_EVAL("", "${cutscr:0,,test}");
|
||||
|
||||
WEE_CHECK_EVAL("+", "${cut:0,+,test}");
|
||||
WEE_CHECK_EVAL("+", "${cutscr:0,+,test}");
|
||||
|
||||
WEE_CHECK_EVAL("te", "${cut:2,,test}");
|
||||
WEE_CHECK_EVAL("te", "${cutscr:2,,test}");
|
||||
|
||||
WEE_CHECK_EVAL("te+", "${cut:2,+,test}");
|
||||
WEE_CHECK_EVAL("te+", "${cutscr:2,+,test}");
|
||||
|
||||
WEE_CHECK_EVAL("éà", "${cut:2,,éàô}");
|
||||
WEE_CHECK_EVAL("éà", "${cutscr:2,,éàô}");
|
||||
|
||||
WEE_CHECK_EVAL("éà+", "${cut:2,+,éàô}");
|
||||
WEE_CHECK_EVAL("éà+", "${cutscr:2,+,éàô}");
|
||||
|
||||
WEE_CHECK_EVAL("こ+", "${cut:1,+,こんにちは世界}");
|
||||
WEE_CHECK_EVAL("+", "${cutscr:1,+,こんにちは世界}");
|
||||
|
||||
WEE_CHECK_EVAL("こん+", "${cut:2,+,こんにちは世界}");
|
||||
WEE_CHECK_EVAL("こ+", "${cutscr:2,+,こんにちは世界}");
|
||||
|
||||
WEE_CHECK_EVAL("こんに+", "${cut:3,+,こんにちは世界}");
|
||||
WEE_CHECK_EVAL("こ+", "${cutscr:3,+,こんにちは世界}");
|
||||
|
||||
WEE_CHECK_EVAL("こんにち+", "${cut:4,+,こんにちは世界}");
|
||||
WEE_CHECK_EVAL("こん+", "${cutscr:4,+,こんにちは世界}");
|
||||
|
||||
WEE_CHECK_EVAL("こんにちは+", "${cut:5,+,こんにちは世界}");
|
||||
WEE_CHECK_EVAL("こん+", "${cutscr:4,+,こんにちは世界}");
|
||||
|
||||
WEE_CHECK_EVAL("こん+", "${cutscr:4,+,こんにちは世界}");
|
||||
|
||||
/* test color */
|
||||
WEE_CHECK_EVAL(gui_color_get_custom ("green"), "${color:green}");
|
||||
WEE_CHECK_EVAL(gui_color_get_custom ("*214"), "${color:*214}");
|
||||
|
||||
Reference in New Issue
Block a user