adding ase_wctomb

This commit is contained in:
hyung-hwan 2008-10-14 09:04:24 +00:00
parent dc0203008e
commit 559d3fba6f
4 changed files with 51 additions and 14 deletions

View File

@ -76,12 +76,19 @@ dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([stddef.h wchar.h wctype.h])
dnl Checks data types
AC_CHECK_TYPE([wchar_t],
[AC_DEFINE([HAVE_WCHAR_T_IN_STDDEF_H],
[],[wchar_t is available in stddef.h])],
[],
[#include <stddef.h>])
AC_CHECK_TYPES(mbstate_t,,,[#include <wchar.h>])
dnl check functions
AC_CHECK_FUNCS(wcrtomb mbrtowc)
dnl Checks the size of primitive data types
AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(short)

View File

@ -37,8 +37,27 @@ extern "C" {
extern ase_ccls_t* ase_ccls;
ase_bool_t ase_ccls_is (ase_cint_t c, int type);
ase_cint_t ase_ccls_to (ase_cint_t c, int type);
ase_bool_t ase_ccls_is (
ase_cint_t c,
ase_ccls_type_t type
);
ase_cint_t ase_ccls_to (
ase_cint_t c,
ase_ccls_type_t type
);
ase_size_t ase_wctomb (
ase_wchar_t wc,
ase_mchar_t* mb,
ase_size_t mblen
);
ase_size_t ase_mbtowc (
const ase_mchar_t* mb,
ase_size_t mblen,
ase_wchar_t* wc
);
#ifdef __cplusplus
}

View File

@ -22,7 +22,7 @@ static ase_bool_t is_graph (ase_cint_t c) { return isgraph(c); }
static ase_bool_t is_cntrl (ase_cint_t c) { return iscntrl(c); }
static ase_bool_t is_punct (ase_cint_t c) { return ispunct(c); }
ase_bool_t ase_ccls_is (ase_cint_t c, int type)
ase_bool_t ase_ccls_is (ase_cint_t c, ase_ccls_type_t type)
{
/* TODO: use GetStringTypeW/A for WIN32 to implement these */
@ -46,7 +46,7 @@ ase_bool_t ase_ccls_is (ase_cint_t c, int type)
return f[type] (c);
}
ase_cint_t ase_ccls_to (ase_cint_t c, int type)
ase_cint_t ase_ccls_to (ase_cint_t c, ase_ccls_type_t type)
{
ASE_ASSERTX (type >= ASE_CCLS_UPPER && type <= ASE_CCLS_LOWER,
"The character type should be one of ASE_CCLS_UPPER and ASE_CCLS_LOWER");
@ -60,7 +60,7 @@ ase_cint_t ase_ccls_to (ase_cint_t c, int type)
#include <wctype.h>
ase_bool_t ase_ccls_is (ase_cint_t c, int type)
ase_bool_t ase_ccls_is (ase_cint_t c, ase_ccls_type_t type)
{
static const char* name[] =
{
@ -99,7 +99,7 @@ ase_bool_t ase_ccls_is (ase_cint_t c, int type)
return iswctype (c, desc[type]);
}
ase_cint_t ase_ccls_to (ase_cint_t c, int type)
ase_cint_t ase_ccls_to (ase_cint_t c, ase_ccls_type_t type)
{
static const char* name[] =
{
@ -124,12 +124,12 @@ ase_cint_t ase_ccls_to (ase_cint_t c, int type)
#error unsupported character type
#endif
static ase_bool_t ccls_is (void* data, ase_cint_t c, int type)
static ase_bool_t ccls_is (void* data, ase_cint_t c, ase_ccls_type_t type)
{
return ase_ccls_is (c, type);
}
static ase_cint_t ccls_to (void* data, ase_cint_t c, int type)
static ase_cint_t ccls_to (void* data, ase_cint_t c, ase_ccls_type_t type)
{
return ase_ccls_to (c, type);
}
@ -143,14 +143,25 @@ static ase_ccls_t ccls =
ase_ccls_t* ase_ccls = &ccls;
#if 0
int ase_wctomb (ase_wchar_t wc, ase_mchar_t* mb, int mblen)
ase_size_t ase_wctomb (ase_wchar_t wc, ase_mchar_t* mb, ase_size_t mblen)
{
if (mblen < MB_CUR_MAX) return -1;
return wctomb (mb, wc);
#ifdef HAVE_WCRTOMB
mbstate_t mbs;
if (mblen < MB_CUR_MAX)
{
/* buffer too small */
return -1;
}
/* TODO: it may end with EILSEQ */
return wcrtomb (mb, wc, &mbs);
#else
#error Not Supported
#endif
}
#if 0
ase_wchar_t ase_mbtowc (ase_mchar_t* mb, int mblen)
{
}

View File

@ -81,7 +81,7 @@ const ase_char_t* ase_tio_geterrstr (ase_tio_t* tio)
ASE_T("no error"),
ASE_T("out of memory"),
ASE_T("no more space"),
ASE_T("illegal utf-8 sequence"),
ASE_T("illegal sequence"),
ASE_T("no input function attached"),
ASE_T("input function returned an error"),
ASE_T("input function failed to open"),