1 /*------------------------------------------------------------------------------
2 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
3 *
4 * Distributable under the terms of either the Apache License (Version 2.0) or
5 * the GNU Lesser General Public License, as specified in the COPYING file.
6 ------------------------------------------------------------------------------*/
7 #ifndef _REPL_TCHAR_H
8 #define _REPL_TCHAR_H
9 
10 #ifndef _CL_HAVE_TCHAR_H
11     #if defined(_UCS2)
12 
13         //note: descriptions with * in front have replacement functions
14 
15         //formatting functions
16         #define _sntprintf swprintf //* make a formatted a string
17         #define _tprintf wprintf //* print a formatted string
18 
19         //this one has no replacement functions yet, but it is only used in the tests
20         #define _vsntprintf vsnwprintf //* print a formatted string using variable arguments
21 
22         //we are using the internal functions of the compiler here
23         //if LUCENE_USE_INTERNAL_CHAR_FUNCTIONS is defined, thesse
24         //will be replaced by internal functions
25         #define _istalnum iswalnum //* alpha/numeric char check
26         #define _istalpha iswalpha //* alpha char check
27         #define _istspace iswspace //* space char check
28         #define _istdigit iswdigit //* digit char check
29         #define _totlower towlower //* convert char to lower case
30         #define _totupper towupper //* convert char to lower case
31         #define _tcslwr wcslwr //* convert string to lower case
32 
33         //these are the string handling functions
34         //we may need to create wide-character/multi-byte replacements for these
35         #define _tcscpy wcscpy //copy a string to another string
36         #define _tcsncpy wcsncpy //copy a specified amount of one string to another string.
37         #define _tcscat wcscat //copy a string onto the end of the other string
38     		#define _tcsncat wcsncat
39         #define _tcschr wcschr //find location of one character
40         #define _tcsstr wcsstr //find location of a string
41         #define _tcslen wcslen //get length of a string
42         #define _tcscmp wcscmp //case sensitive compare two strings
43         #define _tcsncmp wcsncmp //case sensitive compare two strings
44         #define _tcscspn wcscspn //location of any of a set of character in a string
45 
46 				//string compare
47         #ifdef _CL_HAVE_FUNCTION_WCSICMP
48             #define _tcsicmp wcsicmp //* case insensitive compare two string
49         #else
50             #define _tcsicmp wcscasecmp //* case insensitive compare two string
51         #endif
52 				#if defined(_CL_HAVE_FUNCTION_WCSDUP)
53 			  	#define _tcsdup	wcsdup
54 			  #else
55 			  	#define _tcsdup	lucene_wcsdup
56 			  #endif
57 
58         //conversion functions
59         #define _tcstod wcstod //convert a string to a double
60         #define _tcstoi64 wcstoll //* convers a string to an 64bit bit integer
61         #define _itot _i64tot
62         #define _i64tot lltow //* converts a 64 bit integer to a string (with base)
63     #else //if defined(_ASCII)
64 
65         //formatting functions
66         #define _sntprintf snprintf
67         #define _tprintf printf
68         #define _vsntprintf vsnprintf
69 
70         //we are using the internal functions of the compiler here
71         //if LUCENE_USE_INTERNAL_CHAR_FUNCTIONS is defined, thesse
72         //will be replaced by internal functions
73         #define _istalnum isalnum
74         #define _istalpha isalpha
75         #define _istspace isspace
76         #define _istdigit isdigit
77         #define _totlower tolower
78         #define _totupper toupper
79         #define _tcslwr strlwr
80 
81         //these are the string handling functions
82         #define _tcscpy strcpy
83         #define _tcsncpy strncpy
84         #define _tcscat strcat
85     		#define _tcsncat strncat
86         #define _tcschr strchr
87         #define _tcsstr strstr
88         #define _tcslen strlen
89         #define _tcscmp strcmp
90         #define _tcsncmp strncmp
91         #define _tcsicmp strcasecmp
92         #define _tcscspn strcspn
93         #define _tcsdup strdup //string duplicate
94         //converstion methods
95         #define _tcstod strtod
96         #define _tcstoi64 strtoll
97         #define _itot _i64tot
98         #define _i64tot lltoa
99 
100     #endif
101 
102 #else //HAVE_TCHAR_H
103     #include <tchar.h>
104 
105     //some tchar headers miss these...
106     #ifndef _tcstoi64
107         #if defined(_UCS2)
108         	#define _tcstoi64 wcstoll //* convers a string to an 64bit bit integer
109         #else
110         	#define _tcstoi64 strtoll
111         #endif
112     #endif
113 
114 #endif //HAVE_TCHAR_H
115 
116 #ifndef _ttoi
117   #define _ttoi(x) (int)_tcstoi64(x,NULL,10)
118 #endif
119 
120 #ifndef _itot
121   #define _itot(i, buf, radix) lucene_i64tot(i, buf, radix)
122 #endif
123 
124 namespace std
125 {
126 #ifndef tstring
127   #ifdef _UNICODE
128     typedef wstring tstring;
129   #else
130     typedef string tstring;
131   #endif
132 #endif
133 };
134 
135 #define STRCPY_AtoA(target,src,len) strncpy(target,src,len)
136 #define STRDUP_AtoA(x) strdup(x)
137 
138 #if defined(_UCS2)
139   #define stringDuplicate(x) _tcsdup(x)
140 
141   #if defined(_CL_HAVE_FUNCTION_WCSDUP)
142   	#define STRDUP_WtoW	wcsdup
143   #else
144   	#define STRDUP_WtoW	lucene_wcsdup
145   #endif
146   #define STRDUP_TtoT STRDUP_WtoW
147   #define STRDUP_WtoT STRDUP_WtoW
148   #define STRDUP_TtoW STRDUP_WtoW
149 
150   #define STRDUP_AtoW(x) CL_NS(util)::Misc::_charToWide(x)
151   #define STRDUP_AtoT STRDUP_AtoW
152 
153   #define STRDUP_WtoA(x) CL_NS(util)::Misc::_wideToChar(x)
154   #define STRDUP_TtoA STRDUP_WtoA
155 
156   #define STRCPY_WtoW(target,src,len) _tcsncpy(target,src,len)
157   #define STRCPY_TtoW STRCPY_WtoW
158   #define STRCPY_WtoT STRCPY_WtoW
159   //#define _tcscpy STRCPY_WtoW
160 
161   #define STRCPY_AtoW(target,src,len) CL_NS(util)::Misc::_cpycharToWide(src,target,len)
162   #define STRCPY_AtoT STRCPY_AtoW
163 
164   #define STRCPY_WtoA(target,src,len) CL_NS(util)::Misc::_cpywideToChar(src,target,len)
165   #define STRCPY_TtoA STRCPY_WtoA
166 #else
167   #define stringDuplicate(x) strdup(x)
168   #define STRDUP_AtoT STRDUP_AtoA
169   #define STRDUP_TtoA STRDUP_AtoA
170   #define STRDUP_TtoT STRDUP_AtoA
171 
172   #define STRDUP_WtoT(x) xxxxxxxxxxxxxxx //not possible
173   #define STRCPY_WtoT(target,src,len) xxxxxxxxxxxxxxx //not possible
174 
175   #define STRCPY_AtoT STRCPY_AtoA
176   #define STRCPY_TtoA STRCPY_AtoA
177   //#define _tcscpy STRCPY_AtoA
178 #endif
179 
180 
181 #endif //_REPL_TCHAR_H
182