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 _CL_HAVE_TCHAR_H
8#if defined(_UCS2)
9 #define TCHAR wchar_t
10
11 //note: descriptions with * in front have replacement functions
12
13 //formatting functions
14 #define _sntprintf swprintf //* make a formatted a string
15 #define _tprintf wprintf //* print a formatted string
16
17 //this one has no replacement functions yet, but it is only used in the tests
18 #define _vsntprintf vsnwprintf //* print a formatted string using variable arguments
19
20 //we are using the internal functions of the compiler here
21 //if LUCENE_USE_INTERNAL_CHAR_FUNCTIONS is defined, thesse
22 //will be replaced by internal functions
23 #define _istalnum iswalnum //* alpha/numeric char check
24 #define _istalpha iswalpha //* alpha char check
25 #define _istspace iswspace //* space char check
26 #define _istdigit iswdigit //* digit char check
27 #define _totlower towlower //* convert char to lower case
28 #define _totupper towupper //* convert char to lower case
29 #define _tcslwr wcslwr //* convert string to lower case
30
31 //these are the string handling functions
32 //we may need to create wide-character/multi-byte replacements for these
33 #define _tcscpy wcscpy //copy a string to another string
34 #define _tcsncpy wcsncpy //copy a specified amount of one string to another string.
35 #define _tcscat wcscat //copy a string onto the end of the other string
36 #define _tcschr wcschr //find location of one character
37 #define _tcsstr wcsstr //find location of a string
38 #define _tcslen wcslen //get length of a string
39 #define _tcscmp wcscmp //case sensitive compare two strings
40 #define _tcsncmp wcsncmp //case sensitive compare two strings
41 #define _tcscspn wcscspn //location of any of a set of character in a string
42
43 #ifdef _CL_HAVE_WCSICMP
44 #define _tcsicmp wcsicmp //* case insensitive compare two string
45 #else
46 #define _tcsicmp wcscasecmp //* case insensitive compare two string
47 #endif
48
49 //conversion functions
50 #define _tcstod wcstod //convert a string to a double
51 #ifdef _PA_RISC
52 #define _tcstoi64 __wcstoll //* convers a string to an 64bit bit integer
53 #else
54 #define _tcstoi64 wcstoll //* convers a string to an 64bit bit integer
55 #endif
56 #define _i64tot lltow //* converts a 64 bit integer to a string (with base)
57
58#else //if defined(_ASCII)
59 #define TCHAR char
60
61 //formatting functions
62 #define _sntprintf snprintf
63 #define _tprintf printf
64 #define _vsntprintf vsnprintf
65
66 //we are using the internal functions of the compiler here
67 //if LUCENE_USE_INTERNAL_CHAR_FUNCTIONS is defined, thesse
68 //will be replaced by internal functions
69 #define _istalnum isalnum
70 #define _istalpha isalpha
71 #define _istspace isspace
72 #define _istdigit isdigit
73 #define _totlower tolower
74 #define _totupper toupper
75 #define _tcslwr strlwr
76
77 //these are the string handling functions
78 #define _tcscpy strcpy
79 #define _tcsncpy strncpy
80 #define _tcscat strcat
81 #define _tcschr strchr
82 #define _tcsstr strstr
83 #define _tcslen strlen
84 #define _tcscmp strcmp
85 #define _tcsncmp strncmp
86 #define _tcsicmp strcasecmp
87 #define _tcscspn strcspn
88
89 //converstion methods
90 #define _tcstod strtod
91 #define _tcstoi64 strtoll
92 #define _i64tot lltoa
93#endif
94#else //HAVE_TCHAR_H
95 #include <tchar.h>
96
97#ifdef UNDER_CE
98#include <QString>
99#define _i64tot i64tot
100inline TCHAR* i64tot(__int64 value, TCHAR* str, int radix)
101{
102 QT_USE_NAMESPACE
103 _tcscpy(str, (TCHAR *) QString::number(value, radix).utf16());
104 return str;
105}
106
107#define _tcstoi64 tcstoi64
108inline __int64 tcstoi64(const TCHAR *nptr, TCHAR **endptr, int base)
109{
110 QT_USE_NAMESPACE
111 bool ok;
112 return QString::fromUtf16((ushort*) nptr).toInt(&ok, base);
113}
114
115#endif
116
117 //some tchar headers miss these...
118 #ifndef _tcstoi64
119 #if defined(_UCS2)
120 #define _tcstoi64 wcstoll //* convers a string to an 64bit bit integer
121 #else
122 #define _tcstoi64 strtoll
123 #endif
124 #endif
125
126#endif //HAVE_TCHAR_H
127