32 #if !defined( ID_REDIRECT_NEWDELETE ) && !defined( MACOS_X )
33 #define USE_STRING_DATA_ALLOCATOR
36 #ifdef USE_STRING_DATA_ALLOCATOR
62 {
"B",
"KB",
"MB",
"GB" },
63 {
"B/s",
"KB/s",
"MB/s",
"GB/s" }
72 return g_color_table[ i & 15 ];
97 #ifdef USE_STRING_DATA_ALLOCATOR
100 newbuffer =
new char[
alloced ];
102 if ( keepold &&
data ) {
104 strcpy( newbuffer,
data );
108 #ifdef USE_STRING_DATA_ALLOCATOR
125 #ifdef USE_STRING_DATA_ALLOCATOR
152 if ( text ==
data ) {
160 assert( strlen( text ) < (
unsigned)
len );
162 for ( i = 0; text[
i ]; i++ ) {
163 data[
i ] = text[
i ];
175 strcpy(
data, text );
190 end = strlen( str ) - 1;
192 for ( i = start; i <=
end; i++ ) {
213 l = end - strlen( text );
214 for ( i = start; i <=
l; i++ ) {
215 if ( casesensitive ) {
216 for ( j = 0; text[
j]; j++ ) {
217 if ( str[i+j] != text[j] ) {
222 for ( j = 0; text[
j]; j++ ) {
223 if ( ::toupper( str[i+j] ) != ::toupper( text[j] ) ) {
254 if (*filter ==
'*') {
257 for (i = 0; *
filter; i++) {
258 if ( *filter ==
'*' || *filter ==
'?' || (*filter ==
'[' && *(filter+1) !=
'[') ) {
262 if ( *filter ==
'[' ) {
268 index =
idStr(name).Find( buf.
c_str(), casesensitive );
272 name += index + strlen(buf);
275 else if (*filter ==
'?') {
279 else if (*filter ==
'[') {
280 if ( *(filter+1) ==
'[' ) {
281 if ( *name !=
'[' ) {
290 while(*filter && !found) {
291 if (*filter ==
']' && *(filter+1) !=
']') {
294 if (*(filter+1) ==
'-' && *(filter+2) && (*(filter+2) !=
']' || *(filter+3) ==
']')) {
296 if (*name >= *filter && *name <= *(filter+2)) {
301 if ( ::toupper(*name) >= ::toupper(*filter) && ::toupper(*name) <= ::toupper(*(filter+2)) ) {
309 if (*filter == *name) {
314 if ( ::toupper(*filter) == ::toupper(*name) ) {
325 if ( *filter ==
']' && *(filter+1) !=
']' ) {
336 if (*filter != *name) {
341 if ( ::toupper(*filter) != ::toupper(*name) ) {
364 for ( c = *name;
c; c = *(++
name) ) {
384 const char *s1 = name +
Length( name ) - 1;
385 const char *s2 = ext +
Length( ext ) - 1;
394 if ( c1 <= 'Z' && c1 >=
'A' ) {
400 if ( c2 <= 'Z' && c2 >=
'A' ) {
408 }
while( s1 > name && s2 > ext );
410 return ( s1 >= name );
419 static int index = 0;
420 static char str[4][16384];
426 index = (index + 1) & 3;
430 if ( precision > 0 ) {
431 while( n > 0 && s[n-1] ==
'0' ) s[--
n] =
'\0';
432 while( n > 0 && s[n-1] ==
'.' ) s[--
n] =
'\0';
435 for ( i = 1; i <
length; i++ ) {
437 if ( precision > 0 ) {
438 while( n > 0 && s[n-1] ==
'0' ) s[--
n] =
'\0';
439 while( n > 0 && s[n-1] ==
'.' ) s[--
n] =
'\0';
455 for( i =
Length(); i > 0; i-- ) {
456 if (
data[ i - 1 ] == c ) {
470 while(
data[ 0 ] == c ) {
484 l = strlen(
string );
486 while ( !
Cmpn(
string, l ) ) {
501 l = strlen(
string );
502 if ( ( l > 0 ) && !
Cmpn(
string, l ) ) {
518 for( i =
Length(); i > 0 &&
data[ i - 1 ] ==
c; i-- ) {
519 data[ i - 1 ] =
'\0';
532 l = strlen(
string );
549 l = strlen(
string );
550 if ( ( l > 0 ) && (
len >= l ) && !
Cmpn(
string,
data +
len - l, l ) ) {
564 int oldLen, newLen,
i,
j,
count;
567 oldLen = strlen( old );
568 newLen = strlen( nw );
572 for( i = 0; i < oldString.
Length(); i++ ) {
583 for( i = 0, j = 0; i < oldString.
Length(); i++ ) {
585 memcpy(
data + j, nw, newLen );
613 if ( start + len >= i ) {
635 if ( start + len >= i ) {
652 for( i =
Length(); i > 0 && (
unsigned char)(
data[ i - 1 ]) <=
' '; i-- ) {
653 data[ i - 1 ] =
'\0';
667 if (
data[0] !=
'\"' )
707 while(
data[i] !=
'\0' ) {
709 if ( letter ==
'.' ) {
712 if ( letter ==
'\\' ) {
715 hash += (long)(letter)*(i+119);
730 for ( i = 0; i <
len; i++ ) {
731 if (
data[ i ] ==
'\\' ) {
745 if ( *extension !=
'.' ) {
760 for ( i =
len-1; i >= 0; i-- ) {
761 if (
data[i] ==
'.' ) {
778 for ( i = 0; i <
len; i++ ) {
779 if (
data[i] ==
'.' ) {
798 for ( i =
len-1; i >= 0; i-- ) {
799 if (
data[i] ==
'.' ) {
803 if ( *extension !=
'.' ) {
816 if ( ( ( *
this )[ 0 ] ==
'/' ) || ( ( *
this )[ 0 ] ==
'\\' ) ) {
821 *
this = basepath + *
this;
834 if ( text && text[i] ) {
839 if (
data[ pos-1 ] !=
'/' ) {
843 if ( text[i] ==
'/' ) {
847 for ( ; text[
i ]; i++ ) {
848 if ( text[ i ] ==
'\\' ) {
851 data[ pos++ ] = text[
i ];
868 while( ( pos > 0 ) && ( ( *
this )[ pos ] !=
'/' ) && ( ( *
this )[ pos ] !=
'\\' ) ) {
889 while( ( pos > 0 ) && ( ( *
this )[ pos - 1 ] !=
'/' ) && ( ( *
this )[ pos - 1 ] !=
'\\' ) ) {
909 while( ( pos > 0 ) && ( ( *
this )[ pos - 1 ] !=
'/' ) && ( ( *
this )[ pos - 1 ] !=
'\\' ) ) {
928 while( ( pos > 0 ) && ( ( *
this )[ pos - 1 ] !=
'/' ) && ( ( *
this )[ pos - 1 ] !=
'\\' ) ) {
948 while( ( pos > 0 ) && ( ( *
this )[ pos - 1 ] !=
'/' ) && ( ( *
this )[ pos - 1 ] !=
'\\' ) ) {
953 while( ( pos <
Length() ) && ( ( *
this )[ pos ] !=
'.' ) ) {
957 Mid( start, pos - start, dest );
972 while( ( pos > 0 ) && ( ( *
this )[ pos - 1 ] !=
'.' ) ) {
1009 for ( i = 0; s[
i]; i++ ) {
1010 if ( !isdigit( s[i] ) ) {
1011 if ( ( s[ i ] ==
'.' ) && !dot ) {
1128 if ( c1 <= 'Z' && c1 >=
'A' ) {
1134 if ( c2 <= 'Z' && c2 >=
'A' ) {
1167 if ( c1 <= 'Z' && c1 >=
'A' ) {
1173 if ( c2 <= 'Z' && c2 >=
'A' ) {
1206 if ( c1 <= 'Z' && c1 >=
'A' ) {
1212 if ( c2 <= 'Z' && c2 >=
'A' ) {
1244 if ( c1 <= 'Z' && c1 >=
'A' ) {
1256 if ( c2 <= 'Z' && c2 >=
'A' ) {
1270 if ( c1 ==
'/' || c1 ==
'\\' ) {
1276 if ( c2 ==
'/' || c2 ==
'\\' ) {
1283 }
else if ( !c1 && c2 ) {
1319 if ( c1 <= 'Z' && c1 >=
'A' ) {
1331 if ( c2 <= 'Z' && c2 >=
'A' ) {
1345 if ( c1 ==
'/' || c1 ==
'\\' ) {
1351 if ( c2 ==
'/' || c2 ==
'\\' ) {
1358 }
else if ( !c1 && c2 ) {
1381 if ( destsize < 1 ) {
1386 strncpy( dest, src, destsize-1 );
1387 dest[destsize-1] = 0;
1400 l1 = strlen( dest );
1446 while( (c = *s) != 0 ) {
1470 va_start( argptr, fmt );
1471 len =
vsprintf( buffer, fmt, argptr );
1473 if ( len >=
sizeof( buffer ) ) {
1476 if ( len >= size ) {
1507 ret =
_vsnprintf( dest, size-1, fmt, argptr );
1508 #define _vsnprintf use_idStr_vsnPrintf
1511 ret =
vsnprintf( dest, size, fmt, argptr );
1512 #define vsnprintf use_idStr_vsnPrintf
1514 dest[size-1] =
'\0';
1515 if ( ret < 0 || ret >= size ) {
1533 va_start( argptr, fmt );
1536 buffer[
sizeof(
buffer)-1] =
'\0';
1554 buffer[
sizeof(
buffer)-1] =
'\0';
1568 char *
va(
const char *fmt, ... ) {
1570 static int index = 0;
1571 static char string[4][16384];
1574 buf =
string[
index];
1575 index = (index + 1) & 3;
1577 va_start( argptr, fmt );
1593 while ( unit <= 3 && ( 1 << ( unit * 10 ) < value ) ) {
1597 value /= 1 << ( unit * 10 );
1598 sprintf( *
this, format, value );
1600 *
this +=
units[ measure ][ unit ];
1610 value /= 1 << ( unit * 10 );
1611 sprintf( *
this, format, value );
1613 *
this +=
units[ measure ][ unit ];
1622 #ifdef USE_STRING_DATA_ALLOCATOR
1623 stringDataAllocator.
Init();
1633 #ifdef USE_STRING_DATA_ALLOCATOR
1644 #ifdef USE_STRING_DATA_ALLOCATOR
1655 #ifdef USE_STRING_DATA_ALLOCATOR
1656 idLib::common->
Printf(
"%6d KB string memory (%d KB free in %d blocks, %d empty base blocks)\n",
1699 if ( number >= li->
gran ) {
1716 string +=
va(
"%i,", li->
count );
1718 string +=
va(
"%3.3i,", li->
count );
1723 string +=
va(
"%3.3i,", li->
count );
1728 string +=
va(
"%3.3i", number );
1731 string +=
va(
"%i", number );
1735 int count = 11 -
string.Length();
1737 for (
int i = 0;
i <
count;
i++ ) {
1738 string.Insert(
" ", 0 );
static int snPrintf(char *dest, int size, const char *fmt,...) id_attribute((format(printf
GLsizei const GLfloat * value
idStr & SetFileExtension(const char *extension)
static bool CharIsUpper(int c)
void FreeEmptyBaseBlocks(void)
assert(prefInfo.fullscreenBtn)
int Cmp(const char *text) const
void StripLeading(const char c)
idStr & DefaultPath(const char *basepath)
GLenum GLsizei GLenum format
idStr & StripQuotes(void)
bool Filter(const char *filter, bool casesensitive) const
bool StripTrailingOnce(const char *string)
void StripTrailingWhitespace(void)
void StripTrailing(const char c)
int GetFreeBlockMemory(void) const
void ExtractFileBase(idStr &dest) const
static const char * FloatArrayToString(const float *array, const int length, const int precision)
static void StripMediaName(const char *name, idStr &mediaName)
GLenum GLsizei const GLvoid * string
const char * Left(int len, idStr &result) const
static void ShowMemoryUsage_f(const idCmdArgs &args)
idStr & DefaultFileExtension(const char *extension)
type * Alloc(const int num)
int Cmpn(const char *text, int n) const
int IcmpNoColor(const char *text) const
static idVec4 & ColorForIndex(int i)
friend int sprintf(idStr &dest, const char *fmt,...)
int Icmp(const char *text) const
int BestUnit(const char *format, float value, Measure_t measure)
idStr & BackSlashesToSlashes(void)
bool HasLower(void) const
void ExtractFilePath(idStr &dest) const
static bool CharIsLower(int c)
void ReAllocate(int amount, bool keepold)
int Icmpn(const char *text, int n) const
bool CheckExtension(const char *ext)
void ExtractFileName(idStr &dest) const
GLuint GLuint GLsizei count
idStr & StripFileExtension(void)
static idStr FormatNumber(int number)
int GetNumEmptyBaseBlocks(void) const
#define INTSIGNBITNOTSET(i)
static void InitMemory(void)
void EnsureAlloced(int amount, bool keepold=true)
GLsizei GLsizei GLenum GLenum const GLvoid * data
idStr & StripAbsoluteFileExtension(void)
static void Copynz(char *dest, const char *src, int destsize)
static int FindText(const char *str, const char *text, bool casesensitive=true, int start=0, int end=-1)
const char * Right(int len, idStr &result) const
idStr & RemoveColors(void)
int GetBaseBlockMemory(void) const
virtual void Printf(const char *fmt,...) id_attribute((format(printf
void AppendPath(const char *text)
friend int vsprintf(idStr &dest, const char *fmt, va_list ap)
int FileNameHash(void) const
int IcmpnPath(const char *text, int n) const
bool IsNumeric(void) const
static int FindChar(const char *str, const char c, int start=0, int end=-1)
void operator=(const idStr &text)
static void ShutdownMemory(void)
const char * Mid(int start, int len, idStr &result) const
static int static int vsnPrintf(char *dest, int size, const char *fmt, va_list argptr)
int GetNumFreeBlocks(void) const
void Append(const char a)
int Last(const char c) const
GLsizei const GLcharARB const GLint * length
int vsprintf(idStr &string, const char *fmt, va_list argptr)
const char * c_str(void) const
void SetUnit(const char *format, float value, int unit, Measure_t measure)
float dot(float a[], float b[])
char * va(const char *fmt,...)
void ExtractFileExtension(idStr &dest) const
char baseBuffer[STR_ALLOC_BASE]
bool HasUpper(void) const
virtual void Error(const char *fmt,...) id_attribute((format(printf
void Replace(const char *old, const char *nw)
virtual void virtual void Warning(const char *fmt,...) id_attribute((format(printf
int sprintf(idStr &string, const char *fmt,...)
int LengthWithoutColors(void) const
idStr & StripFilename(void)
static void PurgeMemory(void)
formatList_t formatList[]
int IcmpPath(const char *text) const
bool StripLeadingOnce(const char *string)
static class idCommon * common