Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libedit/chartype.c
Show All 31 Lines | |||||
#include "config.h" | #include "config.h" | ||||
#if !defined(lint) && !defined(SCCSID) | #if !defined(lint) && !defined(SCCSID) | ||||
__RCSID("$NetBSD: chartype.c,v 1.23 2016/02/28 23:02:24 christos Exp $"); | __RCSID("$NetBSD: chartype.c,v 1.23 2016/02/28 23:02:24 christos Exp $"); | ||||
#endif /* not lint && not SCCSID */ | #endif /* not lint && not SCCSID */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <limits.h> | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "el.h" | #include "el.h" | ||||
#define CT_BUFSIZ ((size_t)1024) | #define CT_BUFSIZ ((size_t)1024) | ||||
#ifdef WIDECHAR | #ifdef WIDECHAR | ||||
▲ Show 20 Lines • Show All 129 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 */ | mbstate_t ps = (mbstate_t){{0}}; | ||||
if (c < 0x80) | size_t len; | ||||
return 1; | char cbuf[MB_LEN_MAX]; | ||||
else if (c < 0x0800) | len = ct_wcrtomb(cbuf, c, &ps); | ||||
return 2; | if (len == (size_t)-1) | ||||
else if (c < 0x10000) | return (0); | ||||
return 3; | return (len); | ||||
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 |