ovr_sdk
diff LibOVR/Src/Kernel/OVR_Std.h @ 0:1b39a1b46319
initial 0.4.4
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 14 Jan 2015 06:51:16 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/LibOVR/Src/Kernel/OVR_Std.h Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,638 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +PublicHeader: OVR_Kernel.h 1.7 +Filename : OVR_Std.h 1.8 +Content : Standard C function interface 1.9 +Created : September 19, 2012 1.10 +Notes : 1.11 + 1.12 +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. 1.13 + 1.14 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 1.15 +you may not use the Oculus VR Rift SDK except in compliance with the License, 1.16 +which is provided at the time of installation or download, or which 1.17 +otherwise accompanies this software in either electronic or hard copy form. 1.18 + 1.19 +You may obtain a copy of the License at 1.20 + 1.21 +http://www.oculusvr.com/licenses/LICENSE-3.2 1.22 + 1.23 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 1.24 +distributed under the License is distributed on an "AS IS" BASIS, 1.25 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.26 +See the License for the specific language governing permissions and 1.27 +limitations under the License. 1.28 + 1.29 +************************************************************************************/ 1.30 + 1.31 +#ifndef OVR_Std_h 1.32 +#define OVR_Std_h 1.33 + 1.34 +#include "OVR_Types.h" 1.35 +#include <stdarg.h> // for va_list args 1.36 +#include <string.h> 1.37 +#include <stdio.h> 1.38 +#include <stdlib.h> 1.39 +#include <ctype.h> 1.40 + 1.41 +#if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400) 1.42 +#define OVR_MSVC_SAFESTRING 1.43 +#include <errno.h> 1.44 +#endif 1.45 + 1.46 +// Wide-char funcs 1.47 +#include <wchar.h> 1.48 +#include <wctype.h> 1.49 + 1.50 +namespace OVR { 1.51 + 1.52 +// Has the same behavior as itoa aside from also having a dest size argument. 1.53 +// Return value: Pointer to the resulting null-terminated string, same as parameter str. 1.54 +#if defined(OVR_OS_MS) 1.55 +inline char* OVR_CDECL OVR_itoa(int val, char *dest, size_t destsize, int radix) 1.56 +{ 1.57 +#if defined(OVR_MSVC_SAFESTRING) 1.58 + _itoa_s(val, dest, destsize, radix); 1.59 + return dest; 1.60 +#else 1.61 + OVR_UNUSED(destsize); 1.62 + return itoa(val, dest, radix); 1.63 +#endif 1.64 +} 1.65 +#else // OVR_OS_MS 1.66 +inline char* OVR_itoa(int val, char* dest, size_t len, int radix) 1.67 +{ 1.68 + if (val == 0) 1.69 + { 1.70 + if (len > 1) 1.71 + { 1.72 + dest[0] = '0'; 1.73 + dest[1] = '\0'; 1.74 + } 1.75 + else if(len > 0) 1.76 + dest[0] = '\0'; 1.77 + return dest; 1.78 + } 1.79 + 1.80 + // FIXME: Fix the following code to avoid memory write overruns when len is in sufficient. 1.81 + int cur = val; 1.82 + size_t i = 0; 1.83 + size_t sign = 0; 1.84 + 1.85 + if (val < 0) 1.86 + { 1.87 + val = -val; 1.88 + sign = 1; 1.89 + } 1.90 + 1.91 + while ((val != 0) && (i < (len - 1 - sign))) 1.92 + { 1.93 + cur = val % radix; 1.94 + val /= radix; 1.95 + 1.96 + if (radix == 16) 1.97 + { 1.98 + switch(cur) 1.99 + { 1.100 + case 10: 1.101 + dest[i] = 'a'; 1.102 + break; 1.103 + case 11: 1.104 + dest[i] = 'b'; 1.105 + break; 1.106 + case 12: 1.107 + dest[i] = 'c'; 1.108 + break; 1.109 + case 13: 1.110 + dest[i] = 'd'; 1.111 + break; 1.112 + case 14: 1.113 + dest[i] = 'e'; 1.114 + break; 1.115 + case 15: 1.116 + dest[i] = 'f'; 1.117 + break; 1.118 + default: 1.119 + dest[i] = (char)('0' + cur); 1.120 + break; 1.121 + } 1.122 + } 1.123 + else 1.124 + { 1.125 + dest[i] = (char)('0' + cur); 1.126 + } 1.127 + ++i; 1.128 + } 1.129 + 1.130 + if (sign) 1.131 + { 1.132 + dest[i++] = '-'; 1.133 + } 1.134 + 1.135 + for (size_t j = 0; j < i / 2; ++j) 1.136 + { 1.137 + char tmp = dest[j]; 1.138 + dest[j] = dest[i - 1 - j]; 1.139 + dest[i - 1 - j] = tmp; 1.140 + } 1.141 + dest[i] = '\0'; 1.142 + 1.143 + return dest; 1.144 +} 1.145 + 1.146 +#endif 1.147 + 1.148 + 1.149 +// String functions 1.150 + 1.151 +inline size_t OVR_CDECL OVR_strlen(const char* str) 1.152 +{ 1.153 + return strlen(str); 1.154 +} 1.155 + 1.156 +inline char* OVR_CDECL OVR_strcpy(char* dest, size_t destsize, const char* src) 1.157 +{ 1.158 +#if defined(OVR_MSVC_SAFESTRING) 1.159 + strcpy_s(dest, destsize, src); 1.160 + return dest; 1.161 +#else 1.162 + // FIXME: This should be a safer implementation 1.163 + OVR_UNUSED(destsize); 1.164 + return strcpy(dest, src); 1.165 +#endif 1.166 +} 1.167 + 1.168 + 1.169 +// Acts the same as the strlcpy function. 1.170 +// Copies src to dest, 0-terminating even if it involves truncating the write. 1.171 +// Returns the required strlen of dest (which is one less than the required size of dest). 1.172 +// strlcpy is a safer alternative to strcpy and strncpy and provides size information. 1.173 +// However, it still may result in an incomplete copy. 1.174 +// 1.175 +// Example usage: 1.176 +// char buffer[256]; 1.177 +// if(OVR_strlcpy(buffer, "hello world", sizeof(buffer)) < sizeof(buffer)) 1.178 +// { there was enough space } 1.179 +// else 1.180 +// { need a larger buffer } 1.181 +// 1.182 +size_t OVR_CDECL OVR_strlcpy(char* dest, const char* src, size_t destsize); 1.183 + 1.184 +// Acts the same as the strlcat function. 1.185 +// Appends src to dest, 0-terminating even if it involves an incomplete write. 1.186 +// Doesn't 0-terminate in the case that destsize is 0. 1.187 +// Returns the required strlen of dest (which is one less than the required size of dest). 1.188 +// The terminating 0 char of dest is overwritten by the first 1.189 +// character of src, and a new 0 char is appended to dest. The required capacity 1.190 +// of the destination is (strlen(src) + strlen(dest) + 1). 1.191 +// strlcat is a safer alternative to strcat and provides size information. 1.192 +// However, it still may result in an incomplete copy. 1.193 +// 1.194 +// Example usage: 1.195 +// char buffer[256] = "hello "; 1.196 +// if(OVR_strlcat(buffer, "world", sizeof(buffer)) < sizeof(buffer)) 1.197 +// { there was enough space } 1.198 +// else 1.199 +// { need a larger buffer } 1.200 +// 1.201 +size_t OVR_CDECL OVR_strlcat(char* dest, const char* src, size_t destsize); 1.202 + 1.203 + 1.204 +inline char* OVR_CDECL OVR_strncpy(char* dest, size_t destsize, const char* src, size_t count) 1.205 +{ 1.206 +#if defined(OVR_MSVC_SAFESTRING) 1.207 + strncpy_s(dest, destsize, src, count); 1.208 + return dest; 1.209 +#else 1.210 + // FIXME: This should be a safer implementation 1.211 + OVR_UNUSED(destsize); 1.212 + return strncpy(dest, src, count); 1.213 +#endif 1.214 +} 1.215 + 1.216 +inline char * OVR_CDECL OVR_strcat(char* dest, size_t destsize, const char* src) 1.217 +{ 1.218 +#if defined(OVR_MSVC_SAFESTRING) 1.219 + strcat_s(dest, destsize, src); 1.220 + return dest; 1.221 +#else 1.222 + // FIXME: This should be a safer implementation 1.223 + OVR_UNUSED(destsize); 1.224 + return strcat(dest, src); 1.225 +#endif 1.226 +} 1.227 + 1.228 +inline int OVR_CDECL OVR_strcmp(const char* dest, const char* src) 1.229 +{ 1.230 + return strcmp(dest, src); 1.231 +} 1.232 + 1.233 +inline const char* OVR_CDECL OVR_strchr(const char* str, char c) 1.234 +{ 1.235 + return strchr(str, c); 1.236 +} 1.237 + 1.238 +inline char* OVR_CDECL OVR_strchr(char* str, char c) 1.239 +{ 1.240 + return strchr(str, c); 1.241 +} 1.242 + 1.243 +inline const char* OVR_strrchr(const char* str, char c) 1.244 +{ 1.245 + size_t len = OVR_strlen(str); 1.246 + for (size_t i=len; i>0; i--) 1.247 + if (str[i]==c) 1.248 + return str+i; 1.249 + return 0; 1.250 +} 1.251 + 1.252 +inline const uint8_t* OVR_CDECL OVR_memrchr(const uint8_t* str, size_t size, uint8_t c) 1.253 +{ 1.254 + for (intptr_t i = (intptr_t)size - 1; i >= 0; i--) 1.255 + { 1.256 + if (str[i] == c) 1.257 + return str + i; 1.258 + } 1.259 + return 0; 1.260 +} 1.261 + 1.262 +inline char* OVR_CDECL OVR_strrchr(char* str, char c) 1.263 +{ 1.264 + size_t len = OVR_strlen(str); 1.265 + for (size_t i=len; i>0; i--) 1.266 + if (str[i]==c) 1.267 + return str+i; 1.268 + return 0; 1.269 +} 1.270 + 1.271 + 1.272 +double OVR_CDECL OVR_strtod(const char* string, char** tailptr); 1.273 + 1.274 +inline long OVR_CDECL OVR_strtol(const char* string, char** tailptr, int radix) 1.275 +{ 1.276 + return strtol(string, tailptr, radix); 1.277 +} 1.278 + 1.279 +inline long OVR_CDECL OVR_strtoul(const char* string, char** tailptr, int radix) 1.280 +{ 1.281 + return strtoul(string, tailptr, radix); 1.282 +} 1.283 + 1.284 +inline int OVR_CDECL OVR_strncmp(const char* ws1, const char* ws2, size_t size) 1.285 +{ 1.286 + return strncmp(ws1, ws2, size); 1.287 +} 1.288 + 1.289 +inline uint64_t OVR_CDECL OVR_strtouq(const char *nptr, char **endptr, int base) 1.290 +{ 1.291 +#if defined(OVR_CC_MSVC) 1.292 + return _strtoui64(nptr, endptr, base); 1.293 +#else 1.294 + return strtoull(nptr, endptr, base); 1.295 +#endif 1.296 +} 1.297 + 1.298 +inline int64_t OVR_CDECL OVR_strtoq(const char *nptr, char **endptr, int base) 1.299 +{ 1.300 +#if defined(OVR_CC_MSVC) 1.301 + return _strtoi64(nptr, endptr, base); 1.302 +#else 1.303 + return strtoll(nptr, endptr, base); 1.304 +#endif 1.305 +} 1.306 + 1.307 + 1.308 +inline int64_t OVR_CDECL OVR_atoq(const char* string) 1.309 +{ 1.310 +#if defined(OVR_CC_MSVC) 1.311 + return _atoi64(string); 1.312 +#else 1.313 + return atoll(string); 1.314 +#endif 1.315 +} 1.316 + 1.317 +inline uint64_t OVR_CDECL OVR_atouq(const char* string) 1.318 +{ 1.319 + return OVR_strtouq(string, NULL, 10); 1.320 +} 1.321 + 1.322 + 1.323 +// Implemented in OVR_Std.cpp in platform-specific manner. 1.324 +int OVR_CDECL OVR_stricmp(const char* dest, const char* src); 1.325 +int OVR_CDECL OVR_strnicmp(const char* dest, const char* src, size_t count); 1.326 + 1.327 + 1.328 +// This is like sprintf but with a destination buffer size argument. However, the behavior is different 1.329 +// from vsnprintf in that the return value semantics are like sprintf (which returns -1 on capacity overflow) and 1.330 +// not like snprintf (which returns intended strlen on capacity overflow). 1.331 +inline size_t OVR_CDECL OVR_sprintf(char *dest, size_t destsize, const char* format, ...) 1.332 +{ 1.333 + va_list argList; 1.334 + va_start(argList,format); 1.335 + size_t ret; 1.336 +#if defined(OVR_CC_MSVC) 1.337 + #if defined(OVR_MSVC_SAFESTRING) 1.338 + ret = _vsnprintf_s(dest, destsize, _TRUNCATE, format, argList); 1.339 + OVR_ASSERT(ret != -1); 1.340 + #else 1.341 + OVR_UNUSED(destsize); 1.342 + ret = _vsnprintf(dest, destsize - 1, format, argList); // -1 for space for the null character 1.343 + OVR_ASSERT(ret != -1); 1.344 + dest[destsize-1] = 0; 1.345 + #endif 1.346 +#else 1.347 + OVR_UNUSED(destsize); 1.348 + ret = vsprintf(dest, format, argList); 1.349 + OVR_ASSERT(ret < destsize); 1.350 +#endif 1.351 + va_end(argList); 1.352 + return ret; 1.353 +} 1.354 + 1.355 + 1.356 +// This is like vsprintf but with a destination buffer size argument. However, the behavior is different 1.357 +// from vsnprintf in that the return value semantics are like vsprintf (which returns -1 on capacity overflow) and 1.358 +// not like vsnprintf (which returns intended strlen on capacity overflow). 1.359 +// Return value: 1.360 +// On success, the total number of characters written is returned. 1.361 +// On failure, a negative number is returned. 1.362 +inline size_t OVR_CDECL OVR_vsprintf(char *dest, size_t destsize, const char * format, va_list argList) 1.363 +{ 1.364 + size_t ret; 1.365 +#if defined(OVR_CC_MSVC) 1.366 + #if defined(OVR_MSVC_SAFESTRING) 1.367 + dest[0] = '\0'; 1.368 + int rv = vsnprintf_s(dest, destsize, _TRUNCATE, format, argList); 1.369 + if (rv == -1) 1.370 + { 1.371 + dest[destsize - 1] = '\0'; 1.372 + ret = destsize - 1; 1.373 + } 1.374 + else 1.375 + ret = (size_t)rv; 1.376 + #else 1.377 + OVR_UNUSED(destsize); 1.378 + int rv = _vsnprintf(dest, destsize - 1, format, argList); 1.379 + OVR_ASSERT(rv != -1); 1.380 + ret = (size_t)rv; 1.381 + dest[destsize-1] = 0; 1.382 + #endif 1.383 +#else 1.384 + // FIXME: This should be a safer implementation 1.385 + OVR_UNUSED(destsize); 1.386 + ret = (size_t)vsprintf(dest, format, argList); 1.387 + OVR_ASSERT(ret < destsize); 1.388 +#endif 1.389 + return ret; 1.390 +} 1.391 + 1.392 +// Same behavior as ISO C99 vsnprintf. 1.393 +// Returns the strlen of the resulting formatted string, or a negative value if the format is invalid. 1.394 +// destsize specifies the capacity of the input buffer. 1.395 +// 1.396 +// Example usage: 1.397 +// void Log(char *dest, size_t destsize, const char * format, ...) 1.398 +// { 1.399 +// char buffer[1024]; 1.400 +// va_list argList; 1.401 +// va_start(argList,format); 1.402 +// int result = OVR_vsnprintf(dest, destsize, format, argList); 1.403 +// assert(result < destsize); // Else we'd have to retry with a dynamically allocated buffer (of size=result+1) and new argList copy. 1.404 +// va_end(argList); 1.405 +// } 1.406 + 1.407 +inline int OVR_CDECL OVR_vsnprintf(char *dest, size_t destsize, const char * format, va_list argList) 1.408 +{ 1.409 + int ret; 1.410 +#if defined(OVR_CC_MSVC) 1.411 + OVR_DISABLE_MSVC_WARNING(4996) // 'vsnprintf': This function or variable may be unsafe. 1.412 + ret = vsnprintf(dest, destsize, format, argList); // Microsoft vsnprintf is non-conforming; it returns -1 if destsize is insufficient. 1.413 + if (ret < 0) // If there was a format error or if destsize was insufficient... 1.414 + { 1.415 + ret = _vscprintf(format, argList); // Get the expected dest strlen. If the return value is still -1 then there was a format error. 1.416 + 1.417 + if (destsize) // If we can 0-terminate the output... 1.418 + { 1.419 + if (ret < 0) 1.420 + dest[0] = 0; 1.421 + else 1.422 + dest[destsize-1] = 0; 1.423 + } 1.424 + } 1.425 + // Else the string was written OK and ret is its strlen. 1.426 + OVR_RESTORE_MSVC_WARNING() 1.427 +#else 1.428 + ret = vsnprintf(dest, destsize, format, argList); 1.429 +#endif 1.430 + return ret; 1.431 +} 1.432 + 1.433 + 1.434 +// Same behavior as ISO C99 snprintf. 1.435 +// Returns the strlen of the resulting formatted string, or a negative value if the format is invalid. 1.436 +// destsize specifies the capacity of the input buffer. 1.437 +// 1.438 +// Example usage: 1.439 +// char buffer[16]; 1.440 +// int result = OVR_snprintf(buffer, sizeof(buffer), "%d", 37); 1.441 +// if (result >= sizeof(buffer)) // If there was insufficient capacity... 1.442 +// { 1.443 +// char* p = new char[result + 1]; // Or char* p = (char*)OVR_ALLOC(result + 1); 1.444 +// OVR_snprintf(p, (size_t)result, "%d", 37); 1.445 +// delete[] p; 1.446 +// } 1.447 +// 1.448 +inline int OVR_CDECL OVR_snprintf(char *dest, size_t destsize, const char * format, ...) 1.449 +{ 1.450 + va_list argList; 1.451 + va_start(argList,format); 1.452 + int ret = OVR_vsnprintf(dest, destsize, format, argList); 1.453 + va_end(argList); 1.454 + return ret; 1.455 +} 1.456 + 1.457 + 1.458 +// Returns the strlen of the resulting formatted string, or a negative value if the format is invalid. 1.459 +// Note: If you are planning on printing a string then it's more efficient to just use OVR_vsnprintf and 1.460 +// look at the return value and handle the uncommon case that there wasn't enough space. 1.461 +inline int OVR_CDECL OVR_vscprintf(const char * format, va_list argList) 1.462 +{ 1.463 + int ret; 1.464 +#if defined(OVR_CC_MSVC) 1.465 + ret = _vscprintf(format, argList); 1.466 +#else 1.467 + ret = vsnprintf(NULL, 0, format, argList); 1.468 +#endif 1.469 + return ret; 1.470 +} 1.471 + 1.472 + 1.473 +wchar_t* OVR_CDECL OVR_wcscpy(wchar_t* dest, size_t destsize, const wchar_t* src); 1.474 +wchar_t* OVR_CDECL OVR_wcsncpy(wchar_t* dest, size_t destsize, const wchar_t* src, size_t count); 1.475 +wchar_t* OVR_CDECL OVR_wcscat(wchar_t* dest, size_t destsize, const wchar_t* src); 1.476 +size_t OVR_CDECL OVR_wcslen(const wchar_t* str); 1.477 +int OVR_CDECL OVR_wcscmp(const wchar_t* a, const wchar_t* b); 1.478 +int OVR_CDECL OVR_wcsicmp(const wchar_t* a, const wchar_t* b); 1.479 + 1.480 +inline int OVR_CDECL OVR_wcsicoll(const wchar_t* a, const wchar_t* b) 1.481 +{ 1.482 +#if defined(OVR_OS_MS) 1.483 + #if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400) 1.484 + return ::_wcsicoll(a, b); 1.485 + #else 1.486 + return ::wcsicoll(a, b); 1.487 + #endif 1.488 +#else 1.489 + // not supported, use regular wcsicmp 1.490 + return OVR_wcsicmp(a, b); 1.491 +#endif 1.492 +} 1.493 + 1.494 +inline int OVR_CDECL OVR_wcscoll(const wchar_t* a, const wchar_t* b) 1.495 +{ 1.496 +#if defined(OVR_OS_MS) || defined(OVR_OS_LINUX) 1.497 + return wcscoll(a, b); 1.498 +#else 1.499 + // not supported, use regular wcscmp 1.500 + return OVR_wcscmp(a, b); 1.501 +#endif 1.502 +} 1.503 + 1.504 +#ifndef OVR_NO_WCTYPE 1.505 + 1.506 +inline int OVR_CDECL UnicodeCharIs(const uint16_t* table, wchar_t charCode) 1.507 +{ 1.508 + unsigned offset = table[charCode >> 8]; 1.509 + if (offset == 0) return 0; 1.510 + if (offset == 1) return 1; 1.511 + return (table[offset + ((charCode >> 4) & 15)] & (1 << (charCode & 15))) != 0; 1.512 +} 1.513 + 1.514 +extern const uint16_t UnicodeAlnumBits[]; 1.515 +extern const uint16_t UnicodeAlphaBits[]; 1.516 +extern const uint16_t UnicodeDigitBits[]; 1.517 +extern const uint16_t UnicodeSpaceBits[]; 1.518 +extern const uint16_t UnicodeXDigitBits[]; 1.519 + 1.520 +// Uncomment if necessary 1.521 +//extern const uint16_t UnicodeCntrlBits[]; 1.522 +//extern const uint16_t UnicodeGraphBits[]; 1.523 +//extern const uint16_t UnicodeLowerBits[]; 1.524 +//extern const uint16_t UnicodePrintBits[]; 1.525 +//extern const uint16_t UnicodePunctBits[]; 1.526 +//extern const uint16_t UnicodeUpperBits[]; 1.527 + 1.528 +inline int OVR_CDECL OVR_iswalnum (wchar_t charCode) { return UnicodeCharIs(UnicodeAlnumBits, charCode); } 1.529 +inline int OVR_CDECL OVR_iswalpha (wchar_t charCode) { return UnicodeCharIs(UnicodeAlphaBits, charCode); } 1.530 +inline int OVR_CDECL OVR_iswdigit (wchar_t charCode) { return UnicodeCharIs(UnicodeDigitBits, charCode); } 1.531 +inline int OVR_CDECL OVR_iswspace (wchar_t charCode) { return UnicodeCharIs(UnicodeSpaceBits, charCode); } 1.532 +inline int OVR_CDECL OVR_iswxdigit(wchar_t charCode) { return UnicodeCharIs(UnicodeXDigitBits, charCode); } 1.533 + 1.534 +// Uncomment if necessary 1.535 +//inline int OVR_CDECL OVR_iswcntrl (wchar_t charCode) { return UnicodeCharIs(UnicodeCntrlBits, charCode); } 1.536 +//inline int OVR_CDECL OVR_iswgraph (wchar_t charCode) { return UnicodeCharIs(UnicodeGraphBits, charCode); } 1.537 +//inline int OVR_CDECL OVR_iswlower (wchar_t charCode) { return UnicodeCharIs(UnicodeLowerBits, charCode); } 1.538 +//inline int OVR_CDECL OVR_iswprint (wchar_t charCode) { return UnicodeCharIs(UnicodePrintBits, charCode); } 1.539 +//inline int OVR_CDECL OVR_iswpunct (wchar_t charCode) { return UnicodeCharIs(UnicodePunctBits, charCode); } 1.540 +//inline int OVR_CDECL OVR_iswupper (wchar_t charCode) { return UnicodeCharIs(UnicodeUpperBits, charCode); } 1.541 + 1.542 +int OVR_CDECL OVR_towupper(wchar_t charCode); 1.543 +int OVR_CDECL OVR_towlower(wchar_t charCode); 1.544 + 1.545 +#else // OVR_NO_WCTYPE 1.546 + 1.547 +inline int OVR_CDECL OVR_iswspace(wchar_t c) 1.548 +{ 1.549 + return iswspace(c); 1.550 +} 1.551 + 1.552 +inline int OVR_CDECL OVR_iswdigit(wchar_t c) 1.553 +{ 1.554 + return iswdigit(c); 1.555 +} 1.556 + 1.557 +inline int OVR_CDECL OVR_iswxdigit(wchar_t c) 1.558 +{ 1.559 + return iswxdigit(c); 1.560 +} 1.561 + 1.562 +inline int OVR_CDECL OVR_iswalpha(wchar_t c) 1.563 +{ 1.564 + return iswalpha(c); 1.565 +} 1.566 + 1.567 +inline int OVR_CDECL OVR_iswalnum(wchar_t c) 1.568 +{ 1.569 + return iswalnum(c); 1.570 +} 1.571 + 1.572 +inline wchar_t OVR_CDECL OVR_towlower(wchar_t c) 1.573 +{ 1.574 + return (wchar_t)towlower(c); 1.575 +} 1.576 + 1.577 +inline wchar_t OVR_towupper(wchar_t c) 1.578 +{ 1.579 + return (wchar_t)towupper(c); 1.580 +} 1.581 + 1.582 +#endif // OVR_NO_WCTYPE 1.583 + 1.584 +// ASCII versions of tolower and toupper. Don't use "char" 1.585 +inline int OVR_CDECL OVR_tolower(int c) 1.586 +{ 1.587 + return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; 1.588 +} 1.589 + 1.590 +inline int OVR_CDECL OVR_toupper(int c) 1.591 +{ 1.592 + return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; 1.593 +} 1.594 + 1.595 + 1.596 + 1.597 +inline double OVR_CDECL OVR_wcstod(const wchar_t* string, wchar_t** tailptr) 1.598 +{ 1.599 +#if defined(OVR_OS_OTHER) 1.600 + OVR_UNUSED(tailptr); 1.601 + char buffer[64]; 1.602 + char* tp = NULL; 1.603 + size_t max = OVR_wcslen(string); 1.604 + if (max > 63) max = 63; 1.605 + unsigned char c = 0; 1.606 + for (size_t i=0; i < max; i++) 1.607 + { 1.608 + c = (unsigned char)string[i]; 1.609 + buffer[i] = ((c) < 128 ? (char)c : '!'); 1.610 + } 1.611 + buffer[max] = 0; 1.612 + return OVR_strtod(buffer, &tp); 1.613 +#else 1.614 + return wcstod(string, tailptr); 1.615 +#endif 1.616 +} 1.617 + 1.618 +inline long OVR_CDECL OVR_wcstol(const wchar_t* string, wchar_t** tailptr, int radix) 1.619 +{ 1.620 +#if defined(OVR_OS_OTHER) 1.621 + OVR_UNUSED(tailptr); 1.622 + char buffer[64]; 1.623 + char* tp = NULL; 1.624 + size_t max = OVR_wcslen(string); 1.625 + if (max > 63) max = 63; 1.626 + unsigned char c = 0; 1.627 + for (size_t i=0; i < max; i++) 1.628 + { 1.629 + c = (unsigned char)string[i]; 1.630 + buffer[i] = ((c) < 128 ? (char)c : '!'); 1.631 + } 1.632 + buffer[max] = 0; 1.633 + return strtol(buffer, &tp, radix); 1.634 +#else 1.635 + return wcstol(string, tailptr, radix); 1.636 +#endif 1.637 +} 1.638 + 1.639 +} // OVR 1.640 + 1.641 +#endif // OVR_Std_h