2005-11-21 20:27:57 +08:00
|
|
|
#ifndef __TSLOCALE_H__
|
|
|
|
#define __TSLOCALE_H__
|
|
|
|
|
|
|
|
#include "postgres.h"
|
2005-12-12 19:10:12 +08:00
|
|
|
#include "utils/pg_locale.h"
|
|
|
|
#include "mb/pg_wchar.h"
|
2005-11-21 20:27:57 +08:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* towlower() and friends should be in <wctype.h>, but some pre-C99 systems
|
|
|
|
* declare them in <wchar.h>.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_WCHAR_H
|
|
|
|
#include <wchar.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WCTYPE_H
|
|
|
|
#include <wctype.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)
|
|
|
|
#define TS_USE_WIDE
|
2005-12-12 19:10:12 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TS_USE_WIDE
|
|
|
|
#endif /* TS_USE_WIDE */
|
|
|
|
|
|
|
|
|
|
|
|
#define TOUCHAR(x) (*((unsigned char*)(x)))
|
|
|
|
|
|
|
|
#ifdef TS_USE_WIDE
|
2007-01-15 23:16:11 +08:00
|
|
|
size_t char2wchar(wchar_t *to, const char *from, size_t len);
|
2005-11-21 20:27:57 +08:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
2005-11-23 02:17:34 +08:00
|
|
|
size_t wchar2char(char *to, const wchar_t *from, size_t len);
|
2007-01-15 23:16:11 +08:00
|
|
|
|
2006-10-04 08:30:14 +08:00
|
|
|
#else /* WIN32 */
|
2005-11-21 20:27:57 +08:00
|
|
|
|
2007-01-15 23:16:11 +08:00
|
|
|
/* correct wcstombs */
|
2005-11-21 20:27:57 +08:00
|
|
|
#define wchar2char wcstombs
|
2007-01-15 23:16:11 +08:00
|
|
|
|
2005-11-23 02:17:34 +08:00
|
|
|
#endif /* WIN32 */
|
2005-12-12 19:10:12 +08:00
|
|
|
|
2006-10-04 08:30:14 +08:00
|
|
|
#define t_isdigit(x) ( pg_mblen(x)==1 && isdigit( TOUCHAR(x) ) )
|
|
|
|
#define t_isspace(x) ( pg_mblen(x)==1 && isspace( TOUCHAR(x) ) )
|
|
|
|
extern int _t_isalpha(const char *ptr);
|
|
|
|
|
|
|
|
#define t_isalpha(x) ( (pg_mblen(x)==1) ? isalpha( TOUCHAR(x) ) : _t_isalpha(x) )
|
|
|
|
extern int _t_isprint(const char *ptr);
|
|
|
|
|
|
|
|
#define t_isprint(x) ( (pg_mblen(x)==1) ? isprint( TOUCHAR(x) ) : _t_isprint(x) )
|
2005-12-12 19:10:12 +08:00
|
|
|
/*
|
2006-10-04 08:30:14 +08:00
|
|
|
* t_iseq() should be called only for ASCII symbols
|
2005-12-12 19:10:12 +08:00
|
|
|
*/
|
2006-10-04 08:30:14 +08:00
|
|
|
#define t_iseq(x,c) ( (pg_mblen(x)==1) ? ( TOUCHAR(x) == ((unsigned char)(c)) ) : false )
|
2005-12-12 19:10:12 +08:00
|
|
|
|
2007-01-15 23:16:11 +08:00
|
|
|
#define COPYCHAR(d,s) do { \
|
|
|
|
int lll = pg_mblen( s ); \
|
|
|
|
\
|
|
|
|
while( lll-- ) \
|
2005-12-21 21:05:49 +08:00
|
|
|
TOUCHAR((d)+lll) = TOUCHAR((s)+lll); \
|
2005-12-12 19:10:12 +08:00
|
|
|
} while(0)
|
|
|
|
|
2006-10-04 08:30:14 +08:00
|
|
|
#else /* not def TS_USE_WIDE */
|
2005-12-12 19:10:12 +08:00
|
|
|
|
2006-10-04 08:30:14 +08:00
|
|
|
#define t_isdigit(x) isdigit( TOUCHAR(x) )
|
|
|
|
#define t_isspace(x) isspace( TOUCHAR(x) )
|
|
|
|
#define t_isalpha(x) isalpha( TOUCHAR(x) )
|
|
|
|
#define t_isprint(x) isprint( TOUCHAR(x) )
|
|
|
|
#define t_iseq(x,c) ( TOUCHAR(x) == ((unsigned char)(c)) )
|
2005-12-12 19:10:12 +08:00
|
|
|
|
2006-10-04 08:30:14 +08:00
|
|
|
#define COPYCHAR(d,s) TOUCHAR(d) = TOUCHAR(s)
|
2005-12-12 19:10:12 +08:00
|
|
|
#endif
|
|
|
|
|
2006-10-04 08:30:14 +08:00
|
|
|
char *lowerstr(char *str);
|
2005-11-21 20:27:57 +08:00
|
|
|
|
2005-11-23 02:17:34 +08:00
|
|
|
#endif /* __TSLOCALE_H__ */
|