mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 17:23:15 +02:00
Fixed UTF-8 display bug with chars using more than one cell on screen (bug #16356)
This commit is contained in:
+36
-1
@@ -24,7 +24,10 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#define __USE_XOPEN
|
||||
#include <wchar.h>
|
||||
|
||||
#include "weechat.h"
|
||||
#include "utf8.h"
|
||||
@@ -225,7 +228,7 @@ utf8_strlen (char *string)
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_strlen: return length of an UTF-8 string, for N bytes
|
||||
* utf8_strnlen: return length of an UTF-8 string, for N bytes
|
||||
*/
|
||||
|
||||
int
|
||||
@@ -255,6 +258,38 @@ utf8_strnlen (char *string, int bytes)
|
||||
return length;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_width_screen: return number of chars needed on screen to display UTF-8 string
|
||||
*/
|
||||
|
||||
int
|
||||
utf8_width_screen (char *string)
|
||||
{
|
||||
int length, num_char;
|
||||
wchar_t *wstring;
|
||||
|
||||
if (!string)
|
||||
return 0;
|
||||
|
||||
if (!local_utf8)
|
||||
return strlen (string);
|
||||
|
||||
num_char = mbstowcs (NULL, string, 0) + 1;
|
||||
wstring = (wchar_t *) malloc ((num_char + 1) * sizeof (wchar_t));
|
||||
if (!wstring)
|
||||
return utf8_strlen (string);
|
||||
|
||||
if (mbstowcs (wstring, string, num_char) == (size_t)(-1))
|
||||
{
|
||||
free (wstring);
|
||||
return utf8_strlen (string);
|
||||
}
|
||||
|
||||
length = wcswidth (wstring, num_char);
|
||||
free (wstring);
|
||||
return length;
|
||||
}
|
||||
|
||||
/*
|
||||
* utf8_add_offset: moves forward N chars in an UTF-8 string
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,7 @@ extern char *utf8_next_char (char *);
|
||||
extern int utf8_char_size (char *);
|
||||
extern int utf8_strlen (char *);
|
||||
extern int utf8_strnlen (char *, int);
|
||||
extern int utf8_width_screen (char *);
|
||||
extern char *utf8_add_offset (char *, int);
|
||||
extern int utf8_real_pos (char *, int);
|
||||
extern int utf8_pos (char *, int);
|
||||
|
||||
Reference in New Issue
Block a user