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