mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
replace guint by gsize for the glib2 version of irssi_ssl_read
like it's defined in GIOFuncs for glib2 moved src/fe-text/utf8.* to src/fe-common/core changed get_utf8_char so it returns a status code and the unichar argument pointer to the value that it returned before if there were no errors, so you can check for a negative value an handle the error git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4091 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
870253e12c
commit
fb6bdac677
@ -277,7 +277,7 @@ static GIOStatus irssi_ssl_cert_step(GIOSSLChannel *chan)
|
|||||||
return G_IO_STATUS_ERROR;
|
return G_IO_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GIOStatus irssi_ssl_read(GIOChannel *handle, gchar *buf, guint len, guint *ret, GError **gerr)
|
static GIOStatus irssi_ssl_read(GIOChannel *handle, gchar *buf, gsize len, gsize *ret, GError **gerr)
|
||||||
{
|
{
|
||||||
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
|
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
|
||||||
gint err;
|
gint err;
|
||||||
|
@ -76,22 +76,23 @@
|
|||||||
(Result) |= ((Chars)[(Count)] & 0x3f); \
|
(Result) |= ((Chars)[(Count)] & 0x3f); \
|
||||||
}
|
}
|
||||||
|
|
||||||
unichar get_utf8_char(const unsigned char **ptr, int len)
|
int get_utf8_char(const unsigned char **ptr, int len, unichar *chr_r)
|
||||||
{
|
{
|
||||||
int i, result, mask, chrlen;
|
int i, result, mask, chrlen;
|
||||||
|
|
||||||
mask = 0;
|
mask = 0;
|
||||||
UTF8_COMPUTE(**ptr, mask, chrlen);
|
UTF8_COMPUTE(**ptr, mask, chrlen);
|
||||||
if (chrlen == -1)
|
if (chrlen == -1)
|
||||||
return (unichar) -2;
|
return -2;
|
||||||
|
|
||||||
if (chrlen > len)
|
if (chrlen > len)
|
||||||
return (unichar) -1;
|
return -1;
|
||||||
|
|
||||||
UTF8_GET(result, *ptr, i, mask, chrlen);
|
UTF8_GET(result, *ptr, i, mask, chrlen);
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
return (unichar) -2;
|
return -2;
|
||||||
|
|
||||||
|
*chr_r = (unichar) result;
|
||||||
*ptr += chrlen-1;
|
*ptr += chrlen-1;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -100,9 +101,10 @@ int strlen_utf8(const char *str)
|
|||||||
{
|
{
|
||||||
const unsigned char *p = (const unsigned char *) str;
|
const unsigned char *p = (const unsigned char *) str;
|
||||||
int len;
|
int len;
|
||||||
|
unichar chr_r;
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
while (*p != '\0' && get_utf8_char(&p, 6) > 0) {
|
while (*p != '\0' && get_utf8_char(&p, 6, &chr_r) > 0) {
|
||||||
len++;
|
len++;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
#define __UTF8_H
|
#define __UTF8_H
|
||||||
|
|
||||||
/* Returns -2 = invalid, -1 = need more data, otherwise unichar. */
|
/* Returns -2 = invalid, -1 = need more data, otherwise unichar. */
|
||||||
unichar get_utf8_char(const unsigned char **ptr, int len);
|
int get_utf8_char(const unsigned char **ptr, int len, unichar *chr_r);
|
||||||
|
|
||||||
/* Returns length of UTF8 string */
|
/* Returns length of UTF8 string */
|
||||||
int strlen_utf8(const char *str);
|
int strlen_utf8(const char *str);
|
@ -556,13 +556,12 @@ static int input_utf8(const unsigned char *buffer, int size, unichar *result)
|
|||||||
{
|
{
|
||||||
const unsigned char *end = buffer;
|
const unsigned char *end = buffer;
|
||||||
|
|
||||||
*result = get_utf8_char(&end, size);
|
switch (get_utf8_char(&end, size, result)) {
|
||||||
switch (*result) {
|
case -2:
|
||||||
case (unichar) -2:
|
|
||||||
/* not UTF8 - fallback to 8bit ascii */
|
/* not UTF8 - fallback to 8bit ascii */
|
||||||
*result = *buffer;
|
*result = *buffer;
|
||||||
return 1;
|
return 1;
|
||||||
case (unichar) -1:
|
case -1:
|
||||||
/* need more data */
|
/* need more data */
|
||||||
return -1;
|
return -1;
|
||||||
default:
|
default:
|
||||||
|
@ -212,8 +212,7 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
|
|||||||
char_len++;
|
char_len++;
|
||||||
|
|
||||||
next_ptr = ptr;
|
next_ptr = ptr;
|
||||||
chr = get_utf8_char(&next_ptr, char_len);
|
if (get_utf8_char(&next_ptr, char_len, &chr) < 0)
|
||||||
if (chr < 0)
|
|
||||||
char_len = 1;
|
char_len = 1;
|
||||||
else
|
else
|
||||||
char_len = utf8_width(chr);
|
char_len = utf8_width(chr);
|
||||||
@ -432,8 +431,11 @@ static int view_line_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
|
|||||||
|
|
||||||
end = text;
|
end = text;
|
||||||
if (view->utf8) {
|
if (view->utf8) {
|
||||||
unichar chr = get_utf8_char(&end, 6);
|
unichar chr;
|
||||||
char_width = utf8_width(chr);
|
if (get_utf8_char(&end, 6, &chr)<0)
|
||||||
|
char_width = 1;
|
||||||
|
else
|
||||||
|
char_width = utf8_width(chr);
|
||||||
} else {
|
} else {
|
||||||
if (term_type == TERM_TYPE_BIG5 &&
|
if (term_type == TERM_TYPE_BIG5 &&
|
||||||
is_big5(end[0], end[1]))
|
is_big5(end[0], end[1]))
|
||||||
|
Loading…
Reference in New Issue
Block a user