This commit is contained in:
parent
9a6365bbe8
commit
a95dad6655
80
ase/lib/cmn/chr.c
Normal file
80
ase/lib/cmn/chr.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* $Id: ctype.c 132 2008-03-17 10:27:02Z baconevi $
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#include <ase/cmn/chr.h>
|
||||
|
||||
#if defined(ASE_CHAR_IS_MCHAR)
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
static ase_bool_t ccls_is (void* data, ase_cint_t c, ase_ccls_type_t type)
|
||||
{
|
||||
/* TODO: use GetStringTypeW/A for WIN32 to implement these */
|
||||
}
|
||||
|
||||
static ase_cint_t ccls_to (void* data, ase_cint_t c, in 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");
|
||||
|
||||
if (type == ASE_CCLS_UPPER) return toupper(c);
|
||||
if (type == ASE_CCLS_LOWER) return tolower(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
#elif defined(ASE_CHAR_IS_WCHAR)
|
||||
|
||||
#include <wctype.h>
|
||||
|
||||
static ase_bool_t ccls_is (void* data, ase_cint_t c, ase_ccls_type_t type)
|
||||
{
|
||||
static wctype_t desc[] =
|
||||
{
|
||||
wctype("upper"),
|
||||
wctype("lower"),
|
||||
wctype("alpha"),
|
||||
wctype("digit"),
|
||||
wctype("xdigit"),
|
||||
wctype("alnum"),
|
||||
wctype("space"),
|
||||
wctype("print"),
|
||||
wctype("graph"),
|
||||
wctype("cntrl"),
|
||||
wctype("punct")
|
||||
};
|
||||
|
||||
ASE_ASSERTX (type >= ASE_CCLS_UPPER && type <= ASE_CCLS_PUNCT,
|
||||
"The character type should be one of ase_ccls_type_t values");
|
||||
|
||||
return iswctype (c, desc[type]);
|
||||
}
|
||||
|
||||
static ase_cint_t ccls_to (void* data, ase_cint_t c, in type)
|
||||
{
|
||||
static wctype_t desc[] =
|
||||
{
|
||||
wctrans("toupper"),
|
||||
wctrans("tolower")
|
||||
};
|
||||
|
||||
ASE_ASSERTX (type >= ASE_CCLS_UPPER && type <= ASE_CCLS_LOWER,
|
||||
"The character type should be one of ASE_CCLS_UPPER and ASE_CCLS_LOWER");
|
||||
|
||||
return towctrans (c, desc[type]);
|
||||
}
|
||||
|
||||
#else
|
||||
#error unsupported character type
|
||||
#endif
|
||||
|
||||
static ase_ccls_t ccls =
|
||||
{
|
||||
ccls_is,
|
||||
ccls_to,
|
||||
ASE_NULL
|
||||
};
|
||||
|
||||
ase_ccls_t* ase_ccls = &ccls;
|
22
ase/lib/cmn/chr.h
Normal file
22
ase/lib/cmn/chr.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* {License}
|
||||
*/
|
||||
|
||||
#ifndef _ASE_LIB_CMN_CHR_H_
|
||||
#define _ASE_LIB_CMN_CHR_H_
|
||||
|
||||
#include <ase/cmn/chr.h>
|
||||
|
||||
#ifdef USE_STDC
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#else
|
||||
|
||||
#define ASE_ISALPHA(c) ase_isalpha(c)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user