//----------------------------------------------------------------------------- // Purpose: Converts a UTF8 string into a unicode string //----------------------------------------------------------------------------- int V_UTF8ToUnicode( const char *pUTF8, wchar_t *pwchDest, int cubDestSizeInBytes ) { // pwchDest can be null to allow for getting the length of the string if ( cubDestSizeInBytes > 0 ) { AssertValidWritePtr(pwchDest); pwchDest[0] = 0; } if ( !pUTF8 ) return 0; AssertValidStringPtr(pUTF8); #ifdef _WIN32 int cchResult = MultiByteToWideChar( CP_UTF8, 0, pUTF8, -1, pwchDest, cubDestSizeInBytes / sizeof(wchar_t) ); #elif _LINUX int cchResult = mbstowcs( pwchDest, pUTF8, cubDestSizeInBytes / sizeof(wchar_t) ) + 1; #endif if ( cubDestSizeInBytes > 0 ) { pwchDest[(cubDestSizeInBytes / sizeof(wchar_t)) - 1] = 0; } return cchResult; }
void _V_strcpy (const char* file, int line, char *dest, const char *src) { AssertValidWritePtr(dest); AssertValidStringPtr(src); strcpy( dest, src ); }
void _V_memset (const char* file, int line, void *dest, int fill, int count) { Assert( count >= 0 ); AssertValidWritePtr( dest, count ); memset(dest,fill,count); }
int V_snprintf( char *pDest, int maxLen, char const *pFormat, ... ) { Assert( maxLen >= 0 ); AssertValidWritePtr( pDest, maxLen ); AssertValidStringPtr( pFormat ); va_list marker; va_start( marker, pFormat ); #ifdef _WIN32 int len = _vsnprintf( pDest, maxLen, pFormat, marker ); #elif _LINUX int len = vsnprintf( pDest, maxLen, pFormat, marker ); #else #error "define vsnprintf type." #endif va_end( marker ); // Len < 0 represents an overflow if( len < 0 ) { len = maxLen; pDest[maxLen-1] = 0; } return len; }
void _V_memmove(const char* file, int line, void *dest, const void *src, int count) { Assert( count >= 0 ); AssertValidReadPtr( src, count ); AssertValidWritePtr( dest, count ); memmove( dest, src, count ); }
void _V_memcpy (const char* file, int line, void *dest, const void *src, int count) { mxASSERT( count >= 0 ); AssertValidReadPtr( src, count ); AssertValidWritePtr( dest, count ); memcpy( dest, src, count ); }
int Q_snprintf( char *pDest, int maxLen, char const *pFormat, ... ) { Assert( maxLen >= 0 ); AssertValidWritePtr( pDest, maxLen ); AssertValidStringPtr( pFormat ); #ifdef FREEBSD const char* bit64 = "I64"; const int formatlen = strlen(pFormat); char pTempFormat[1024] ={0}; int tfidx = 0; for( int mfidx=0; mfidx<formatlen; mfidx++ ) { pTempFormat[tfidx++] = pFormat[mfidx]; if( '%' == pFormat[mfidx] ) { int bit64idx = 0; int scanidx = mfidx + 1; for( ; bit64idx<3; bit64idx++ ) { if( scanidx >= formatlen ) { break; } if( bit64[bit64idx] != pFormat[scanidx] ) { break; } scanidx++; } if( bit64idx == 3 ) { memcpy( pTempFormat+tfidx, "ll", 2 ); tfidx += 2; mfidx += 3; } } } pTempFormat[tfidx] = '\0'; #endif va_list marker; va_start( marker, pFormat ); #ifdef WIN32 int len = _vsnprintf( pDest, maxLen, pFormat, marker ); #else int len = vsnprintf( pDest, maxLen, pTempFormat, marker ); #endif va_end( marker ); // Len < 0 represents an overflow if( len < 0 ) { len = maxLen; pDest[maxLen-1] = 0; } return len; }
void Q_strncpy( char *pDest, char const *pSrc, int maxLen ) { Assert( maxLen >= 0 ); AssertValidWritePtr( pDest, maxLen ); AssertValidStringPtr( pSrc ); strncpy( pDest, pSrc, maxLen ); if( maxLen ) pDest[maxLen-1] = 0; }
void V_strncpy( char *pDest, char const *pSrc, int maxLen ) { mxASSERT( maxLen >= 0 ); AssertValidWritePtr( pDest, maxLen ); AssertValidStringPtr( pSrc ); strncpy( pDest, pSrc, maxLen ); if ( maxLen > 0 ) { pDest[maxLen-1] = 0; } }
void V_wcsncpy( wchar_t *pDest, wchar_t const *pSrc, int maxLenInBytes ) { Assert( maxLenInBytes >= 0 ); AssertValidWritePtr( pDest, maxLenInBytes ); AssertValidReadPtr( pSrc ); int maxLen = maxLenInBytes / sizeof(wchar_t); wcsncpy( pDest, pSrc, maxLen ); if( maxLen ) { pDest[maxLen-1] = 0; } }
//----------------------------------------------------------------------------- // Purpose: Converts a UTF8 string into a unicode string //----------------------------------------------------------------------------- int V_UTF8ToUnicode( const char *pUTF8, wchar_t *pwchDest, int cubDestSizeInBytes ) { AssertValidStringPtr(pUTF8); AssertValidWritePtr(pwchDest); pwchDest[0] = 0; #ifdef _WIN32 int cchResult = MultiByteToWideChar( CP_UTF8, 0, pUTF8, -1, pwchDest, cubDestSizeInBytes / sizeof(wchar_t) ); #elif _LINUX int cchResult = mbstowcs( pwchDest, pUTF8, cubDestSizeInBytes / sizeof(wchar_t) ); #endif pwchDest[(cubDestSizeInBytes / sizeof(wchar_t)) - 1] = 0; return cchResult; }
int V_vsnprintf( char *pDest, int maxLen, char const *pFormat, va_list params ) { Assert( maxLen > 0 ); AssertValidWritePtr( pDest, maxLen ); AssertValidStringPtr( pFormat ); int len = _vsnprintf( pDest, maxLen, pFormat, params ); if( len < 0 ) { len = maxLen; pDest[maxLen-1] = 0; } return len; }
int Q_vsnprintf( char *pDest, int maxLen, char const *pFormat, va_list params ) { Assert( maxLen >= 0 ); AssertValidWritePtr( pDest, maxLen ); AssertValidStringPtr( pFormat ); #ifdef WIN32 int len = _vsnprintf( pDest, maxLen, pFormat, params ); #else int len = vsnprintf( pDest, maxLen, pFormat, params ); #endif if( len < 0 ) { len = maxLen; pDest[maxLen-1] = 0; } return len; }