]> granicus.if.org Git - postgresql/blob - contrib/tsearch2/ts_locale.h
Reduce WAL activity for page splits:
[postgresql] / contrib / tsearch2 / ts_locale.h
1 #ifndef __TSLOCALE_H__
2 #define __TSLOCALE_H__
3
4 #include "postgres.h"
5 #include "utils/pg_locale.h"
6 #include "mb/pg_wchar.h"
7
8 #include <ctype.h>
9 #include <limits.h>
10
11 /*
12  * towlower() and friends should be in <wctype.h>, but some pre-C99 systems
13  * declare them in <wchar.h>.
14  */
15 #ifdef HAVE_WCHAR_H
16 #include <wchar.h>
17 #endif
18 #ifdef HAVE_WCTYPE_H
19 #include <wctype.h>
20 #endif
21
22 #if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)
23 #define TS_USE_WIDE
24 #endif
25
26 #ifdef TS_USE_WIDE
27 #endif   /* TS_USE_WIDE */
28
29
30 #define TOUCHAR(x)      (*((unsigned char*)(x)))
31
32 #ifdef TS_USE_WIDE
33 size_t          char2wchar(wchar_t *to, const char *from, size_t len);
34
35 #ifdef WIN32
36
37 size_t          wchar2char(char *to, const wchar_t *from, size_t len);
38
39 #else                                                   /* WIN32 */
40
41 /* correct wcstombs */
42 #define wchar2char wcstombs
43
44 #endif   /* WIN32 */
45
46 #define t_isdigit(x)    ( pg_mblen(x)==1 && isdigit( TOUCHAR(x) ) )
47 #define t_isspace(x)    ( pg_mblen(x)==1 && isspace( TOUCHAR(x) ) )
48 extern int      _t_isalpha(const char *ptr);
49
50 #define t_isalpha(x)    ( (pg_mblen(x)==1) ? isalpha( TOUCHAR(x) ) : _t_isalpha(x) )
51 extern int      _t_isprint(const char *ptr);
52
53 #define t_isprint(x)    ( (pg_mblen(x)==1) ? isprint( TOUCHAR(x) ) : _t_isprint(x) )
54 /*
55  * t_iseq() should be called only for ASCII symbols
56  */
57 #define t_iseq(x,c) ( (pg_mblen(x)==1) ? ( TOUCHAR(x) == ((unsigned char)(c)) ) : false )
58
59 #define COPYCHAR(d,s)   do {                                    \
60         int lll = pg_mblen( s );                                        \
61                                                                                                 \
62         while( lll-- )                                                          \
63                 TOUCHAR((d)+lll) = TOUCHAR((s)+lll);    \
64 } while(0)
65
66 #else                                                   /* not def TS_USE_WIDE */
67
68 #define t_isdigit(x)    isdigit( TOUCHAR(x) )
69 #define t_isspace(x)    isspace( TOUCHAR(x) )
70 #define t_isalpha(x)    isalpha( TOUCHAR(x) )
71 #define t_isprint(x)    isprint( TOUCHAR(x) )
72 #define t_iseq(x,c) ( TOUCHAR(x) == ((unsigned char)(c)) )
73
74 #define COPYCHAR(d,s)   TOUCHAR(d) = TOUCHAR(s)
75 #endif
76
77 char       *lowerstr(char *str);
78
79 #endif   /* __TSLOCALE_H__ */