Mobile API Reference  MicroStrategy 2019
PDCwchar.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : PDCwchar.h
3 // AUTHOR : Perl Script
4 // CREATION : 6/13/02
5 // Copyright (C) MicroStrategy, Inc. 2002
6 //==============================================================================================
7 #ifndef PDCwchar_h
8 #define PDCwchar_h
9 
10 // this must be the *first* file included
11 #include "ProtectedSource/Prolog.h"
12 
13 #include <wchar.h>
14 
15 #ifdef NO_WCHAR_SUPPORT
16  typedef char WCHAR;
17  #define _T(x) x
18  #define _tcslen strlen
19  #define _tcscpy strcpy
20  #define _tcscmp strcmp
21  #define _tcsicmp strcasecmp
22 #else
23  typedef wchar_t WCHAR;
24  #define _T(x) L##x
25  #define _tcslen wcslen
26  #define _tcscpy wcscpy
27  #define _tcscmp wcscmp
28  #define _tcsicmp wcsicmp
29 #endif
30 
31 // 2004-03-03 vovechkin
32 // define string operations equivalent on UNIX and Windows
33 #ifdef WIN32
34 
35  inline int wtoi(const wchar_t* ipStr)
36  {
37  return ::_wtoi(ipStr);
38  }
39 
40  inline wchar_t* wcstok(wchar_t* ws1, const wchar_t* ws2, wchar_t** ptr)
41  {
42  // 2004-09-09 vovechkin
43  // on Windows, the third parameter is not necessary, because
44  // function ::wcstok stores that pointer internally.
45  return (ptr != 0) ? ::wcstok_s(ws1, ws2, ptr) : 0;
46  }
47 
48 #elif defined(sun)
49 
50  #include <strings.h>
51  #include <widec.h>
52 
53  inline int stricmp(const char* s1, const char* s2)
54  {
55  return ::strcasecmp(s1, s2);
56  }
57 
58  inline int wcsicmp(const wchar_t* s1, const wchar_t* s2)
59  {
60  return ::wscasecmp(s1, s2);
61  }
62 
63  inline int strnicmp(const char* s1, const char* s2, int n)
64  {
65  return ::strncasecmp(s1, s2, n);
66  }
67 
68  inline int wcsnicmp(const wchar_t* s1, const wchar_t* s2, int n)
69  {
70  return ::wsncasecmp(s1, s2, n);
71  }
72 
73  inline wchar_t* wcslwr(wchar_t* string)
74  {
75  for (wchar_t* lpStr = string; *lpStr != L'\0'; ++lpStr)
76  {
77  *lpStr = ::towlower(*lpStr);
78  }
79 
80  return string;
81  }
82 
83  inline int wtoi(const wchar_t* string)
84  {
85  return watoi(string);
86  }
87 
88 
89 #elif defined(linux)
90 
91  #include <cwchar>
92  #include <string>
93  #include <cwctype>
94 
95  inline int stricmp(const char* s1, const char* s2)
96  {
97  return ::strcasecmp(s1, s2);
98  }
99 #ifndef NO_WCHAR_SUPPORT
100  inline int wcsicmp(const wchar_t* s1, const wchar_t* s2)
101  {
102  return ::wcscasecmp(s1, s2);
103  }
104 #endif
105  inline int strnicmp(const char* s1, const char* s2, int n)
106  {
107  return ::strncasecmp(s1, s2, n);
108  }
109 #ifndef NO_WCHAR_SUPPORT
110  inline int wcsnicmp(const wchar_t* s1, const wchar_t* s2, int n)
111  {
112  return ::wcsncasecmp(s1, s2, n);
113  }
114 #endif
115  inline wchar_t* wcslwr(wchar_t* string)
116  {
117  for (wchar_t* lpStr = string; *lpStr != L'\0'; ++lpStr)
118  {
119  *lpStr = ::towlower(*lpStr);
120  }
121 
122  return string;
123  }
124 
125  inline int wtoi(const wchar_t* string)
126  {
127  return wcstol(string, (wchar_t **)0, 10);
128  }
129 
130 #elif defined(_AIX)
131 
132 // 2004-03-11 vovechkin
133 // these are defined in '/usr/include/wchar.h'
134 #ifdef wstrcmp
135 #undef wstrcmp
136 #endif // wstrcmp
137 
138  #include <strings.h>
139  #include <wstring.h>
140 
141  inline int stricmp(const char* s1, const char* s2)
142  {
143  return ::strcasecmp(s1, s2);
144  }
145 
146  inline int wcsicmp(const wchar_t* s1, const wchar_t* s2)
147  {
148  return ::wcscasecmp(s1, s2);
149  }
150 
151  inline int strnicmp(const char* s1, const char* s2, int n)
152  {
153  return ::strncasecmp(s1, s2, n);
154  }
155 
156  inline int wcsnicmp(const wchar_t* s1, const wchar_t* s2, int n)
157  {
158  return ::wcsncasecmp(s1, s2, n);
159  }
160 
161  inline wchar_t* wcslwr(wchar_t* string)
162  {
163  for (wchar_t* lpStr = string; *lpStr != L'\0'; ++lpStr)
164  {
165  *lpStr = ::towlower(*lpStr);
166  }
167 
168  return string;
169  }
170 
171  inline int wtoi(const wchar_t* string)
172  {
173  return watoi(const_cast<wchar_t*>(string));
174  }
175 
176 #elif defined (__hpux)
177 
178  #include <cwchar>
179  #include <string>
180  #include <cwctype>
181  #include <alloca.h>
182 
183  inline int stricmp(const char* s1, const char* s2)
184  {
185  return ::strcasecmp(s1, s2);
186  }
187 
188  inline wchar_t* wcslwr(wchar_t* string)
189  {
190  for (wchar_t* lpStr = string; *lpStr != L'\0'; ++lpStr)
191  {
192  *lpStr = ::towlower(*lpStr);
193  }
194 
195  return string;
196  }
197 
198  inline int wcsicmp(const wchar_t* s1, const wchar_t* s2)
199  {
200  //TQMS 964671, xfan, 9/11/2014
201  wchar_t* s1_1 = new wchar_t[wcslen(s1) + 1];
202  wchar_t* s2_1 = new wchar_t[wcslen(s2) + 1];
203 
204  int lRet = -1;
205  if ( s1_1 && s2_1 )
206  {
207  wcslcpy(s1_1, wcslen(s1) + 1, s1);
208  wcslcpy(s2_1, wcslen(s2) + 1, s2);
209  lRet = ::wcscmp(wcslwr(s1_1), wcslwr(s2_1) );
210  }
211 
212  if(s1_1)
213  delete[] s1_1;
214  if(s2_1)
215  delete[] s2_1;
216  return lRet;
217  }
218 
219  inline int strnicmp(const char* s1, const char* s2, int n)
220  {
221  return ::strncasecmp(s1, s2, n);
222  }
223 
224  inline int wcsnicmp(const wchar_t* s1, const wchar_t* s2, int n)
225  {
226  wchar_t* s1_1 = new wchar_t[wcslen(s1) + 1];
227  wchar_t* s2_1 = new wchar_t[wcslen(s2) + 1];
228 
229  int lRet = -1;
230  if ( s1_1 && s2_1 )
231  {
232  wcslcpy(s1_1, wcslen(s1) + 1, s1);
233  wcslcpy(s2_1, wcslen(s2) + 1, s2);
234  lRet = ::wcsncmp(wcslwr(s1_1), wcslwr(s2_1), n);
235  }
236 
237  if(s1_1)
238  delete[] s1_1;
239  if(s2_1)
240  delete[] s2_1;
241  return lRet;
242  }
243 
244  inline int wtoi(const wchar_t* string)
245  {
246  return wcstol(string, (wchar_t **)0, 10);
247  }
248 #elif defined(_MAC)
249 //added by ydong
250 //to support _MAC projects
251 #include <cwchar>
252 #include <string>
253 #include <cwctype>
254 
255 inline int stricmp(const char* s1, const char* s2)
256 {
257  return ::strcasecmp(s1, s2);
258 }
259 
260 inline int wcsicmp(const wchar_t* s1, const wchar_t* s2)
261 {
262  return ::wcscasecmp(s1, s2);
263 }
264 
265 inline int strnicmp(const char* s1, const char* s2, int n)
266 {
267  return ::strncasecmp(s1, s2, n);
268 }
269 
270 inline int wcsnicmp(const wchar_t* s1, const wchar_t* s2, int n)
271 {
272  return ::wcsncasecmp(s1, s2, n);
273 }
274 
275 inline wchar_t* wcslwr(wchar_t* string)
276 {
277  for (wchar_t* lpStr = string; *lpStr != L'\0'; ++lpStr)
278  {
279  *lpStr = ::towlower(*lpStr);
280  }
281 
282  return string;
283 }
284 
285 inline int wtoi(const wchar_t* string)
286 {
287  return (int)wcstol(string, (wchar_t **)0, 10);
288 }
289 #else
290 //#error UNKNOWN PLATFORM
291 #endif
292 
293 #if !defined(WIN32) && defined(WIN64)
294 
320 inline errno_t wcscat_s(wchar_t *strDestination, size_t sizeInWords, const wchar_t *strSource)
321 {
322  _VALIDATE_RETURN_ERRCODE(strDestination!=NULL,EINVAL);
323  _VALIDATE_RETURN_ERRCODE(strSource!=NULL,EINVAL);
324  _VALIDATE_RETURN_ERRCODE(sizeInWords>wcslen(strSource)+wcslen(strDestination),EINVAL);
325  ::wcscat(strDestination,strSource);
326  return 0;
327 }
328 
346 inline errno_t wcscpy_s(wchar_t *strDestination, size_t sizeInWords, const wchar_t *strSource)
347 {
348  _VALIDATE_RETURN_ERRCODE(strDestination!=NULL,EINVAL);
349  _VALIDATE_RETURN_ERRCODE(strSource!=NULL,EINVAL);
350  _VALIDATE_RETURN_ERRCODE(sizeInWords>wcslen(strSource),EINVAL);
351  ::wcscpy(strDestination,strSource);
352  return 0;
353 }
354 
375 inline errno_t wcsncat_s(wchar_t *strDestination, size_t sizeInWords, const wchar_t *strSource, size_t count)
376 {
377  _VALIDATE_RETURN_ERRCODE(strDestination!=NULL,EINVAL);
378  _VALIDATE_RETURN_ERRCODE(strSource!=NULL,EINVAL);
379  _VALIDATE_RETURN_ERRCODE(sizeInWords>wcslen(strSource)+(count>wcslen(strSource)?wcslen(strSource):count),EINVAL);
380  ::wcsncat(strDestination,strSource,count);
381  return 0;
382 }
383 
403 inline errno_t wcsncpy_s(wchar_t *strDestination, size_t sizeInWords, const wchar_t *strSource, size_t count)
404 {
405  _VALIDATE_RETURN_ERRCODE(strDestination!=NULL,EINVAL);
406  _VALIDATE_RETURN_ERRCODE(strSource!=NULL,EINVAL);
407  size_t len=(count>wcslen(strSource)?wcslen(strSource):count);
408  _VALIDATE_RETURN_ERRCODE(sizeInWords>len,EINVAL);
409  ::wcsncpy(strDestination,strSource,len);
410  strDestination[len]=(L'\0');
411  return 0;
412 }
413 
414 #endif
415 
416 
417 // this must be the *last* file included
418 #include "ProtectedSource/Epilog.h"
419 
420 #endif // PDCwchar_h
wchar_t WCHAR
Definition: PDCwchar.h:23
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)
Definition: PDCerrno.h:21
UINT len
Definition: Msi_bstr.h:37
#define NULL
Definition: Null.h:10