1 #ifndef __GNUC__ 2 #pragma once 3 #endif 4 #ifndef __XR_STRING_UTILS_H__ 5 #define __XR_STRING_UTILS_H__ 6 7 #include <string> 8 #include <cstring> 9 #include <cctype> 10 11 namespace xray_re { 12 xr_strlwr(std::string & s)13static inline void xr_strlwr(std::string& s) 14 { 15 for (std::string::iterator it = s.begin(), end = s.end(); it != end; ++it) 16 *it = char(std::tolower(*it)); 17 } 18 xr_strlwr(char * s,size_t n)19static inline void xr_strlwr(char* s, size_t n) 20 { 21 #if defined(_MSC_VER) && _MSC_VER >= 1400 22 _strlwr_s(s, n); 23 #else 24 for (int c; (c = *s) != 0;) 25 *s++ = std::tolower(c); 26 #endif 27 } 28 xr_stricmp(const char * s1,const char * s2)29static inline int xr_stricmp(const char* s1, const char* s2) 30 { 31 return strcasecmp(s1, s2); 32 } 33 34 #if defined(_MSC_VER) && _MSC_VER >= 1400 35 #define xr_snprintf sprintf_s 36 #else 37 // FIXME: snprintf has different semantics really!!! 38 #define xr_snprintf snprintf 39 #endif 40 41 /* 42 static char* xr_strdup(const char* string) 43 { 44 xr_assert(string); 45 uint32_t len = uint32_t(strlen(string)) + 1; 46 47 char* mem = (char*)malloc(len); 48 CopyMemory(mem, string, len); 49 50 return mem; 51 } 52 */ 53 54 } // end of namespace xray_re 55 56 #endif 57