nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: PublicHeader: OVR_Kernel.h nuclear@0: Filename : OVR_Std.h nuclear@0: Content : Standard C function interface nuclear@0: Created : September 19, 2012 nuclear@0: Notes : nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: ************************************************************************************/ nuclear@0: nuclear@0: #ifndef OVR_Std_h nuclear@0: #define OVR_Std_h nuclear@0: nuclear@0: #include "OVR_Types.h" nuclear@0: #include // for va_list args nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: nuclear@0: #if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400) nuclear@0: #define OVR_MSVC_SAFESTRING nuclear@0: #include nuclear@0: #endif nuclear@0: nuclear@0: // Wide-char funcs nuclear@0: #include nuclear@0: #include nuclear@0: nuclear@0: namespace OVR { nuclear@0: nuclear@0: // Has the same behavior as itoa aside from also having a dest size argument. nuclear@0: // Return value: Pointer to the resulting null-terminated string, same as parameter str. nuclear@0: #if defined(OVR_OS_MS) nuclear@0: inline char* OVR_CDECL OVR_itoa(int val, char *dest, size_t destsize, int radix) nuclear@0: { nuclear@0: #if defined(OVR_MSVC_SAFESTRING) nuclear@0: _itoa_s(val, dest, destsize, radix); nuclear@0: return dest; nuclear@0: #else nuclear@0: OVR_UNUSED(destsize); nuclear@0: return itoa(val, dest, radix); nuclear@0: #endif nuclear@0: } nuclear@0: #else // OVR_OS_MS nuclear@0: inline char* OVR_itoa(int val, char* dest, size_t len, int radix) nuclear@0: { nuclear@0: if (val == 0) nuclear@0: { nuclear@0: if (len > 1) nuclear@0: { nuclear@0: dest[0] = '0'; nuclear@0: dest[1] = '\0'; nuclear@0: } nuclear@0: else if(len > 0) nuclear@0: dest[0] = '\0'; nuclear@0: return dest; nuclear@0: } nuclear@0: nuclear@0: // FIXME: Fix the following code to avoid memory write overruns when len is in sufficient. nuclear@0: int cur = val; nuclear@0: size_t i = 0; nuclear@0: size_t sign = 0; nuclear@0: nuclear@0: if (val < 0) nuclear@0: { nuclear@0: val = -val; nuclear@0: sign = 1; nuclear@0: } nuclear@0: nuclear@0: while ((val != 0) && (i < (len - 1 - sign))) nuclear@0: { nuclear@0: cur = val % radix; nuclear@0: val /= radix; nuclear@0: nuclear@0: if (radix == 16) nuclear@0: { nuclear@0: switch(cur) nuclear@0: { nuclear@0: case 10: nuclear@0: dest[i] = 'a'; nuclear@0: break; nuclear@0: case 11: nuclear@0: dest[i] = 'b'; nuclear@0: break; nuclear@0: case 12: nuclear@0: dest[i] = 'c'; nuclear@0: break; nuclear@0: case 13: nuclear@0: dest[i] = 'd'; nuclear@0: break; nuclear@0: case 14: nuclear@0: dest[i] = 'e'; nuclear@0: break; nuclear@0: case 15: nuclear@0: dest[i] = 'f'; nuclear@0: break; nuclear@0: default: nuclear@0: dest[i] = (char)('0' + cur); nuclear@0: break; nuclear@0: } nuclear@0: } nuclear@0: else nuclear@0: { nuclear@0: dest[i] = (char)('0' + cur); nuclear@0: } nuclear@0: ++i; nuclear@0: } nuclear@0: nuclear@0: if (sign) nuclear@0: { nuclear@0: dest[i++] = '-'; nuclear@0: } nuclear@0: nuclear@0: for (size_t j = 0; j < i / 2; ++j) nuclear@0: { nuclear@0: char tmp = dest[j]; nuclear@0: dest[j] = dest[i - 1 - j]; nuclear@0: dest[i - 1 - j] = tmp; nuclear@0: } nuclear@0: dest[i] = '\0'; nuclear@0: nuclear@0: return dest; nuclear@0: } nuclear@0: nuclear@0: #endif nuclear@0: nuclear@0: nuclear@0: // String functions nuclear@0: nuclear@0: inline size_t OVR_CDECL OVR_strlen(const char* str) nuclear@0: { nuclear@0: return strlen(str); nuclear@0: } nuclear@0: nuclear@0: inline char* OVR_CDECL OVR_strcpy(char* dest, size_t destsize, const char* src) nuclear@0: { nuclear@0: #if defined(OVR_MSVC_SAFESTRING) nuclear@0: strcpy_s(dest, destsize, src); nuclear@0: return dest; nuclear@0: #else nuclear@0: // FIXME: This should be a safer implementation nuclear@0: OVR_UNUSED(destsize); nuclear@0: return strcpy(dest, src); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // Acts the same as the strlcpy function. nuclear@0: // Copies src to dest, 0-terminating even if it involves truncating the write. nuclear@0: // Returns the required strlen of dest (which is one less than the required size of dest). nuclear@0: // strlcpy is a safer alternative to strcpy and strncpy and provides size information. nuclear@0: // However, it still may result in an incomplete copy. nuclear@0: // nuclear@0: // Example usage: nuclear@0: // char buffer[256]; nuclear@0: // if(OVR_strlcpy(buffer, "hello world", sizeof(buffer)) < sizeof(buffer)) nuclear@0: // { there was enough space } nuclear@0: // else nuclear@0: // { need a larger buffer } nuclear@0: // nuclear@0: size_t OVR_CDECL OVR_strlcpy(char* dest, const char* src, size_t destsize); nuclear@0: nuclear@0: // Acts the same as the strlcat function. nuclear@0: // Appends src to dest, 0-terminating even if it involves an incomplete write. nuclear@0: // Doesn't 0-terminate in the case that destsize is 0. nuclear@0: // Returns the required strlen of dest (which is one less than the required size of dest). nuclear@0: // The terminating 0 char of dest is overwritten by the first nuclear@0: // character of src, and a new 0 char is appended to dest. The required capacity nuclear@0: // of the destination is (strlen(src) + strlen(dest) + 1). nuclear@0: // strlcat is a safer alternative to strcat and provides size information. nuclear@0: // However, it still may result in an incomplete copy. nuclear@0: // nuclear@0: // Example usage: nuclear@0: // char buffer[256] = "hello "; nuclear@0: // if(OVR_strlcat(buffer, "world", sizeof(buffer)) < sizeof(buffer)) nuclear@0: // { there was enough space } nuclear@0: // else nuclear@0: // { need a larger buffer } nuclear@0: // nuclear@0: size_t OVR_CDECL OVR_strlcat(char* dest, const char* src, size_t destsize); nuclear@0: nuclear@0: nuclear@0: inline char* OVR_CDECL OVR_strncpy(char* dest, size_t destsize, const char* src, size_t count) nuclear@0: { nuclear@0: #if defined(OVR_MSVC_SAFESTRING) nuclear@0: strncpy_s(dest, destsize, src, count); nuclear@0: return dest; nuclear@0: #else nuclear@0: // FIXME: This should be a safer implementation nuclear@0: OVR_UNUSED(destsize); nuclear@0: return strncpy(dest, src, count); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: inline char * OVR_CDECL OVR_strcat(char* dest, size_t destsize, const char* src) nuclear@0: { nuclear@0: #if defined(OVR_MSVC_SAFESTRING) nuclear@0: strcat_s(dest, destsize, src); nuclear@0: return dest; nuclear@0: #else nuclear@0: // FIXME: This should be a safer implementation nuclear@0: OVR_UNUSED(destsize); nuclear@0: return strcat(dest, src); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: inline int OVR_CDECL OVR_strcmp(const char* dest, const char* src) nuclear@0: { nuclear@0: return strcmp(dest, src); nuclear@0: } nuclear@0: nuclear@0: inline const char* OVR_CDECL OVR_strchr(const char* str, char c) nuclear@0: { nuclear@0: return strchr(str, c); nuclear@0: } nuclear@0: nuclear@0: inline char* OVR_CDECL OVR_strchr(char* str, char c) nuclear@0: { nuclear@0: return strchr(str, c); nuclear@0: } nuclear@0: nuclear@0: inline const char* OVR_strrchr(const char* str, char c) nuclear@0: { nuclear@0: size_t len = OVR_strlen(str); nuclear@0: for (size_t i=len; i>0; i--) nuclear@0: if (str[i]==c) nuclear@0: return str+i; nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: inline const uint8_t* OVR_CDECL OVR_memrchr(const uint8_t* str, size_t size, uint8_t c) nuclear@0: { nuclear@0: for (intptr_t i = (intptr_t)size - 1; i >= 0; i--) nuclear@0: { nuclear@0: if (str[i] == c) nuclear@0: return str + i; nuclear@0: } nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: inline char* OVR_CDECL OVR_strrchr(char* str, char c) nuclear@0: { nuclear@0: size_t len = OVR_strlen(str); nuclear@0: for (size_t i=len; i>0; i--) nuclear@0: if (str[i]==c) nuclear@0: return str+i; nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: double OVR_CDECL OVR_strtod(const char* string, char** tailptr); nuclear@0: nuclear@0: inline long OVR_CDECL OVR_strtol(const char* string, char** tailptr, int radix) nuclear@0: { nuclear@0: return strtol(string, tailptr, radix); nuclear@0: } nuclear@0: nuclear@0: inline long OVR_CDECL OVR_strtoul(const char* string, char** tailptr, int radix) nuclear@0: { nuclear@0: return strtoul(string, tailptr, radix); nuclear@0: } nuclear@0: nuclear@0: inline int OVR_CDECL OVR_strncmp(const char* ws1, const char* ws2, size_t size) nuclear@0: { nuclear@0: return strncmp(ws1, ws2, size); nuclear@0: } nuclear@0: nuclear@0: inline uint64_t OVR_CDECL OVR_strtouq(const char *nptr, char **endptr, int base) nuclear@0: { nuclear@0: #if defined(OVR_CC_MSVC) nuclear@0: return _strtoui64(nptr, endptr, base); nuclear@0: #else nuclear@0: return strtoull(nptr, endptr, base); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: inline int64_t OVR_CDECL OVR_strtoq(const char *nptr, char **endptr, int base) nuclear@0: { nuclear@0: #if defined(OVR_CC_MSVC) nuclear@0: return _strtoi64(nptr, endptr, base); nuclear@0: #else nuclear@0: return strtoll(nptr, endptr, base); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: nuclear@0: inline int64_t OVR_CDECL OVR_atoq(const char* string) nuclear@0: { nuclear@0: #if defined(OVR_CC_MSVC) nuclear@0: return _atoi64(string); nuclear@0: #else nuclear@0: return atoll(string); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: inline uint64_t OVR_CDECL OVR_atouq(const char* string) nuclear@0: { nuclear@0: return OVR_strtouq(string, NULL, 10); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // Implemented in OVR_Std.cpp in platform-specific manner. nuclear@0: int OVR_CDECL OVR_stricmp(const char* dest, const char* src); nuclear@0: int OVR_CDECL OVR_strnicmp(const char* dest, const char* src, size_t count); nuclear@0: nuclear@0: nuclear@0: // This is like sprintf but with a destination buffer size argument. However, the behavior is different nuclear@0: // from vsnprintf in that the return value semantics are like sprintf (which returns -1 on capacity overflow) and nuclear@0: // not like snprintf (which returns intended strlen on capacity overflow). nuclear@0: inline size_t OVR_CDECL OVR_sprintf(char *dest, size_t destsize, const char* format, ...) nuclear@0: { nuclear@0: va_list argList; nuclear@0: va_start(argList,format); nuclear@0: size_t ret; nuclear@0: #if defined(OVR_CC_MSVC) nuclear@0: #if defined(OVR_MSVC_SAFESTRING) nuclear@0: ret = _vsnprintf_s(dest, destsize, _TRUNCATE, format, argList); nuclear@0: OVR_ASSERT(ret != -1); nuclear@0: #else nuclear@0: OVR_UNUSED(destsize); nuclear@0: ret = _vsnprintf(dest, destsize - 1, format, argList); // -1 for space for the null character nuclear@0: OVR_ASSERT(ret != -1); nuclear@0: dest[destsize-1] = 0; nuclear@0: #endif nuclear@0: #else nuclear@0: OVR_UNUSED(destsize); nuclear@0: ret = vsprintf(dest, format, argList); nuclear@0: OVR_ASSERT(ret < destsize); nuclear@0: #endif nuclear@0: va_end(argList); nuclear@0: return ret; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // This is like vsprintf but with a destination buffer size argument. However, the behavior is different nuclear@0: // from vsnprintf in that the return value semantics are like vsprintf (which returns -1 on capacity overflow) and nuclear@0: // not like vsnprintf (which returns intended strlen on capacity overflow). nuclear@0: // Return value: nuclear@0: // On success, the total number of characters written is returned. nuclear@0: // On failure, a negative number is returned. nuclear@0: inline size_t OVR_CDECL OVR_vsprintf(char *dest, size_t destsize, const char * format, va_list argList) nuclear@0: { nuclear@0: size_t ret; nuclear@0: #if defined(OVR_CC_MSVC) nuclear@0: #if defined(OVR_MSVC_SAFESTRING) nuclear@0: dest[0] = '\0'; nuclear@0: int rv = vsnprintf_s(dest, destsize, _TRUNCATE, format, argList); nuclear@0: if (rv == -1) nuclear@0: { nuclear@0: dest[destsize - 1] = '\0'; nuclear@0: ret = destsize - 1; nuclear@0: } nuclear@0: else nuclear@0: ret = (size_t)rv; nuclear@0: #else nuclear@0: OVR_UNUSED(destsize); nuclear@0: int rv = _vsnprintf(dest, destsize - 1, format, argList); nuclear@0: OVR_ASSERT(rv != -1); nuclear@0: ret = (size_t)rv; nuclear@0: dest[destsize-1] = 0; nuclear@0: #endif nuclear@0: #else nuclear@0: // FIXME: This should be a safer implementation nuclear@0: OVR_UNUSED(destsize); nuclear@0: ret = (size_t)vsprintf(dest, format, argList); nuclear@0: OVR_ASSERT(ret < destsize); nuclear@0: #endif nuclear@0: return ret; nuclear@0: } nuclear@0: nuclear@0: // Same behavior as ISO C99 vsnprintf. nuclear@0: // Returns the strlen of the resulting formatted string, or a negative value if the format is invalid. nuclear@0: // destsize specifies the capacity of the input buffer. nuclear@0: // nuclear@0: // Example usage: nuclear@0: // void Log(char *dest, size_t destsize, const char * format, ...) nuclear@0: // { nuclear@0: // char buffer[1024]; nuclear@0: // va_list argList; nuclear@0: // va_start(argList,format); nuclear@0: // int result = OVR_vsnprintf(dest, destsize, format, argList); nuclear@0: // assert(result < destsize); // Else we'd have to retry with a dynamically allocated buffer (of size=result+1) and new argList copy. nuclear@0: // va_end(argList); nuclear@0: // } nuclear@0: nuclear@0: inline int OVR_CDECL OVR_vsnprintf(char *dest, size_t destsize, const char * format, va_list argList) nuclear@0: { nuclear@0: int ret; nuclear@0: #if defined(OVR_CC_MSVC) nuclear@0: OVR_DISABLE_MSVC_WARNING(4996) // 'vsnprintf': This function or variable may be unsafe. nuclear@0: ret = vsnprintf(dest, destsize, format, argList); // Microsoft vsnprintf is non-conforming; it returns -1 if destsize is insufficient. nuclear@0: if (ret < 0) // If there was a format error or if destsize was insufficient... nuclear@0: { nuclear@0: ret = _vscprintf(format, argList); // Get the expected dest strlen. If the return value is still -1 then there was a format error. nuclear@0: nuclear@0: if (destsize) // If we can 0-terminate the output... nuclear@0: { nuclear@0: if (ret < 0) nuclear@0: dest[0] = 0; nuclear@0: else nuclear@0: dest[destsize-1] = 0; nuclear@0: } nuclear@0: } nuclear@0: // Else the string was written OK and ret is its strlen. nuclear@0: OVR_RESTORE_MSVC_WARNING() nuclear@0: #else nuclear@0: ret = vsnprintf(dest, destsize, format, argList); nuclear@0: #endif nuclear@0: return ret; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // Same behavior as ISO C99 snprintf. nuclear@0: // Returns the strlen of the resulting formatted string, or a negative value if the format is invalid. nuclear@0: // destsize specifies the capacity of the input buffer. nuclear@0: // nuclear@0: // Example usage: nuclear@0: // char buffer[16]; nuclear@0: // int result = OVR_snprintf(buffer, sizeof(buffer), "%d", 37); nuclear@0: // if (result >= sizeof(buffer)) // If there was insufficient capacity... nuclear@0: // { nuclear@0: // char* p = new char[result + 1]; // Or char* p = (char*)OVR_ALLOC(result + 1); nuclear@0: // OVR_snprintf(p, (size_t)result, "%d", 37); nuclear@0: // delete[] p; nuclear@0: // } nuclear@0: // nuclear@0: inline int OVR_CDECL OVR_snprintf(char *dest, size_t destsize, const char * format, ...) nuclear@0: { nuclear@0: va_list argList; nuclear@0: va_start(argList,format); nuclear@0: int ret = OVR_vsnprintf(dest, destsize, format, argList); nuclear@0: va_end(argList); nuclear@0: return ret; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // Returns the strlen of the resulting formatted string, or a negative value if the format is invalid. nuclear@0: // Note: If you are planning on printing a string then it's more efficient to just use OVR_vsnprintf and nuclear@0: // look at the return value and handle the uncommon case that there wasn't enough space. nuclear@0: inline int OVR_CDECL OVR_vscprintf(const char * format, va_list argList) nuclear@0: { nuclear@0: int ret; nuclear@0: #if defined(OVR_CC_MSVC) nuclear@0: ret = _vscprintf(format, argList); nuclear@0: #else nuclear@0: ret = vsnprintf(NULL, 0, format, argList); nuclear@0: #endif nuclear@0: return ret; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: wchar_t* OVR_CDECL OVR_wcscpy(wchar_t* dest, size_t destsize, const wchar_t* src); nuclear@0: wchar_t* OVR_CDECL OVR_wcsncpy(wchar_t* dest, size_t destsize, const wchar_t* src, size_t count); nuclear@0: wchar_t* OVR_CDECL OVR_wcscat(wchar_t* dest, size_t destsize, const wchar_t* src); nuclear@0: size_t OVR_CDECL OVR_wcslen(const wchar_t* str); nuclear@0: int OVR_CDECL OVR_wcscmp(const wchar_t* a, const wchar_t* b); nuclear@0: int OVR_CDECL OVR_wcsicmp(const wchar_t* a, const wchar_t* b); nuclear@0: nuclear@0: inline int OVR_CDECL OVR_wcsicoll(const wchar_t* a, const wchar_t* b) nuclear@0: { nuclear@0: #if defined(OVR_OS_MS) nuclear@0: #if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400) nuclear@0: return ::_wcsicoll(a, b); nuclear@0: #else nuclear@0: return ::wcsicoll(a, b); nuclear@0: #endif nuclear@0: #else nuclear@0: // not supported, use regular wcsicmp nuclear@0: return OVR_wcsicmp(a, b); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: inline int OVR_CDECL OVR_wcscoll(const wchar_t* a, const wchar_t* b) nuclear@0: { nuclear@0: #if defined(OVR_OS_MS) || defined(OVR_OS_LINUX) nuclear@0: return wcscoll(a, b); nuclear@0: #else nuclear@0: // not supported, use regular wcscmp nuclear@0: return OVR_wcscmp(a, b); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: #ifndef OVR_NO_WCTYPE nuclear@0: nuclear@0: inline int OVR_CDECL UnicodeCharIs(const uint16_t* table, wchar_t charCode) nuclear@0: { nuclear@0: unsigned offset = table[charCode >> 8]; nuclear@0: if (offset == 0) return 0; nuclear@0: if (offset == 1) return 1; nuclear@0: return (table[offset + ((charCode >> 4) & 15)] & (1 << (charCode & 15))) != 0; nuclear@0: } nuclear@0: nuclear@0: extern const uint16_t UnicodeAlnumBits[]; nuclear@0: extern const uint16_t UnicodeAlphaBits[]; nuclear@0: extern const uint16_t UnicodeDigitBits[]; nuclear@0: extern const uint16_t UnicodeSpaceBits[]; nuclear@0: extern const uint16_t UnicodeXDigitBits[]; nuclear@0: nuclear@0: // Uncomment if necessary nuclear@0: //extern const uint16_t UnicodeCntrlBits[]; nuclear@0: //extern const uint16_t UnicodeGraphBits[]; nuclear@0: //extern const uint16_t UnicodeLowerBits[]; nuclear@0: //extern const uint16_t UnicodePrintBits[]; nuclear@0: //extern const uint16_t UnicodePunctBits[]; nuclear@0: //extern const uint16_t UnicodeUpperBits[]; nuclear@0: nuclear@0: inline int OVR_CDECL OVR_iswalnum (wchar_t charCode) { return UnicodeCharIs(UnicodeAlnumBits, charCode); } nuclear@0: inline int OVR_CDECL OVR_iswalpha (wchar_t charCode) { return UnicodeCharIs(UnicodeAlphaBits, charCode); } nuclear@0: inline int OVR_CDECL OVR_iswdigit (wchar_t charCode) { return UnicodeCharIs(UnicodeDigitBits, charCode); } nuclear@0: inline int OVR_CDECL OVR_iswspace (wchar_t charCode) { return UnicodeCharIs(UnicodeSpaceBits, charCode); } nuclear@0: inline int OVR_CDECL OVR_iswxdigit(wchar_t charCode) { return UnicodeCharIs(UnicodeXDigitBits, charCode); } nuclear@0: nuclear@0: // Uncomment if necessary nuclear@0: //inline int OVR_CDECL OVR_iswcntrl (wchar_t charCode) { return UnicodeCharIs(UnicodeCntrlBits, charCode); } nuclear@0: //inline int OVR_CDECL OVR_iswgraph (wchar_t charCode) { return UnicodeCharIs(UnicodeGraphBits, charCode); } nuclear@0: //inline int OVR_CDECL OVR_iswlower (wchar_t charCode) { return UnicodeCharIs(UnicodeLowerBits, charCode); } nuclear@0: //inline int OVR_CDECL OVR_iswprint (wchar_t charCode) { return UnicodeCharIs(UnicodePrintBits, charCode); } nuclear@0: //inline int OVR_CDECL OVR_iswpunct (wchar_t charCode) { return UnicodeCharIs(UnicodePunctBits, charCode); } nuclear@0: //inline int OVR_CDECL OVR_iswupper (wchar_t charCode) { return UnicodeCharIs(UnicodeUpperBits, charCode); } nuclear@0: nuclear@0: int OVR_CDECL OVR_towupper(wchar_t charCode); nuclear@0: int OVR_CDECL OVR_towlower(wchar_t charCode); nuclear@0: nuclear@0: #else // OVR_NO_WCTYPE nuclear@0: nuclear@0: inline int OVR_CDECL OVR_iswspace(wchar_t c) nuclear@0: { nuclear@0: return iswspace(c); nuclear@0: } nuclear@0: nuclear@0: inline int OVR_CDECL OVR_iswdigit(wchar_t c) nuclear@0: { nuclear@0: return iswdigit(c); nuclear@0: } nuclear@0: nuclear@0: inline int OVR_CDECL OVR_iswxdigit(wchar_t c) nuclear@0: { nuclear@0: return iswxdigit(c); nuclear@0: } nuclear@0: nuclear@0: inline int OVR_CDECL OVR_iswalpha(wchar_t c) nuclear@0: { nuclear@0: return iswalpha(c); nuclear@0: } nuclear@0: nuclear@0: inline int OVR_CDECL OVR_iswalnum(wchar_t c) nuclear@0: { nuclear@0: return iswalnum(c); nuclear@0: } nuclear@0: nuclear@0: inline wchar_t OVR_CDECL OVR_towlower(wchar_t c) nuclear@0: { nuclear@0: return (wchar_t)towlower(c); nuclear@0: } nuclear@0: nuclear@0: inline wchar_t OVR_towupper(wchar_t c) nuclear@0: { nuclear@0: return (wchar_t)towupper(c); nuclear@0: } nuclear@0: nuclear@0: #endif // OVR_NO_WCTYPE nuclear@0: nuclear@0: // ASCII versions of tolower and toupper. Don't use "char" nuclear@0: inline int OVR_CDECL OVR_tolower(int c) nuclear@0: { nuclear@0: return (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c; nuclear@0: } nuclear@0: nuclear@0: inline int OVR_CDECL OVR_toupper(int c) nuclear@0: { nuclear@0: return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: nuclear@0: inline double OVR_CDECL OVR_wcstod(const wchar_t* string, wchar_t** tailptr) nuclear@0: { nuclear@0: #if defined(OVR_OS_OTHER) nuclear@0: OVR_UNUSED(tailptr); nuclear@0: char buffer[64]; nuclear@0: char* tp = NULL; nuclear@0: size_t max = OVR_wcslen(string); nuclear@0: if (max > 63) max = 63; nuclear@0: unsigned char c = 0; nuclear@0: for (size_t i=0; i < max; i++) nuclear@0: { nuclear@0: c = (unsigned char)string[i]; nuclear@0: buffer[i] = ((c) < 128 ? (char)c : '!'); nuclear@0: } nuclear@0: buffer[max] = 0; nuclear@0: return OVR_strtod(buffer, &tp); nuclear@0: #else nuclear@0: return wcstod(string, tailptr); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: inline long OVR_CDECL OVR_wcstol(const wchar_t* string, wchar_t** tailptr, int radix) nuclear@0: { nuclear@0: #if defined(OVR_OS_OTHER) nuclear@0: OVR_UNUSED(tailptr); nuclear@0: char buffer[64]; nuclear@0: char* tp = NULL; nuclear@0: size_t max = OVR_wcslen(string); nuclear@0: if (max > 63) max = 63; nuclear@0: unsigned char c = 0; nuclear@0: for (size_t i=0; i < max; i++) nuclear@0: { nuclear@0: c = (unsigned char)string[i]; nuclear@0: buffer[i] = ((c) < 128 ? (char)c : '!'); nuclear@0: } nuclear@0: buffer[max] = 0; nuclear@0: return strtol(buffer, &tp, radix); nuclear@0: #else nuclear@0: return wcstol(string, tailptr, radix); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: } // OVR nuclear@0: nuclear@0: #endif // OVR_Std_h