Changeset View
Changeset View
Standalone View
Standalone View
lib/libedit/chartype.c
Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv) | ||||
return wargv; | return wargv; | ||||
} | } | ||||
protected size_t | protected size_t | ||||
ct_enc_width(Char c) | ct_enc_width(Char c) | ||||
{ | { | ||||
/* UTF-8 encoding specific values */ | char buf[MB_LEN_MAX]; | ||||
if (c < 0x80) | int size; | ||||
return 1; | if ((size = ct_wctomb(buf, c)) < 0) | ||||
else if (c < 0x0800) | return 0; | ||||
naito.yuichiro_gmail.com: hrs@ says that wctomb(3) has an internal shift state,
if wctomb(3) is called outside of libedit… | |||||
return 2; | return size; | ||||
else if (c < 0x10000) | |||||
return 3; | |||||
else if (c < 0x110000) | |||||
return 4; | |||||
else | |||||
return 0; /* not a valid codepoint */ | |||||
} | } | ||||
protected ssize_t | protected ssize_t | ||||
ct_encode_char(char *dst, size_t len, Char c) | ct_encode_char(char *dst, size_t len, Char c) | ||||
{ | { | ||||
ssize_t l = 0; | ssize_t l = 0; | ||||
if (len < ct_enc_width(c)) | if (len < ct_enc_width(c)) | ||||
return -1; | return -1; | ||||
▲ Show 20 Lines • Show All 183 Lines • Show Last 20 Lines |
hrs@ says that wctomb(3) has an internal shift state,
if wctomb(3) is called outside of libedit,
the internal state can be changed and causes miscalculate multibyte size.
So in this part, wcrtomb(3) should be used.
wcrtomb(3) requires that shift state is given in the argument.
We always initialize the shift state in ct_enc_width() to keep independent from outside of libedit.