2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//need to rewrite this
|
|
|
|
|
|
|
|
#ifndef __UTIL_STR_H__
|
|
|
|
#define __UTIL_STR_H__
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma warning(disable : 4710) // function 'blah' not inlined
|
|
|
|
#endif
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void TestStringClass();
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
class strdata
|
2012-03-17 20:01:54 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
strdata () : len( 0 ), refcount( 0 ), data( NULL ), alloced( 0 ) {}
|
|
|
|
~strdata (){
|
|
|
|
if ( data ) {
|
|
|
|
delete [] data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddRef() { refcount++; }
|
|
|
|
bool DelRef(){ // True if killed
|
|
|
|
refcount--;
|
|
|
|
if ( refcount < 0 ) {
|
|
|
|
delete this;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int len;
|
|
|
|
int refcount;
|
|
|
|
char *data;
|
|
|
|
int alloced;
|
|
|
|
};
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
class idStr {
|
|
|
|
protected:
|
2012-03-17 20:01:54 +00:00
|
|
|
strdata *m_data;
|
|
|
|
void EnsureAlloced( int, bool keepold = true );
|
|
|
|
void EnsureDataWritable();
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
public:
|
2012-03-17 20:01:54 +00:00
|
|
|
~idStr();
|
|
|
|
idStr();
|
|
|
|
idStr( const char *text );
|
|
|
|
idStr( const idStr& string );
|
|
|
|
idStr( const idStr string, int start, int end );
|
|
|
|
idStr( const char ch );
|
|
|
|
idStr( const int num );
|
|
|
|
idStr( const float num );
|
|
|
|
idStr( const unsigned num );
|
|
|
|
int length( void ) const;
|
|
|
|
int allocated( void ) const;
|
|
|
|
const char * c_str( void ) const;
|
|
|
|
|
|
|
|
void append( const char *text );
|
|
|
|
void append( const idStr& text );
|
|
|
|
char operator[]( int index ) const;
|
|
|
|
char& operator[]( int index );
|
|
|
|
|
|
|
|
void operator=( const idStr& text );
|
|
|
|
void operator=( const char *text );
|
|
|
|
|
|
|
|
friend idStr operator+( const idStr& a, const idStr& b );
|
|
|
|
friend idStr operator+( const idStr& a, const char *b );
|
|
|
|
friend idStr operator+( const char *a, const idStr& b );
|
|
|
|
|
|
|
|
friend idStr operator+( const idStr& a, const float b );
|
|
|
|
friend idStr operator+( const idStr& a, const int b );
|
|
|
|
friend idStr operator+( const idStr& a, const unsigned b );
|
|
|
|
friend idStr operator+( const idStr& a, const bool b );
|
|
|
|
friend idStr operator+( const idStr& a, const char b );
|
|
|
|
|
|
|
|
idStr& operator+=( const idStr& a );
|
|
|
|
idStr& operator+=( const char *a );
|
|
|
|
idStr& operator+=( const float a );
|
|
|
|
idStr& operator+=( const char a );
|
|
|
|
idStr& operator+=( const int a );
|
|
|
|
idStr& operator+=( const unsigned a );
|
|
|
|
idStr& operator+=( const bool a );
|
|
|
|
|
|
|
|
friend bool operator==( const idStr& a, const idStr& b );
|
|
|
|
friend bool operator==( const idStr& a, const char *b );
|
|
|
|
friend bool operator==( const char *a, const idStr& b );
|
|
|
|
|
|
|
|
friend bool operator!=( const idStr& a, const idStr& b );
|
|
|
|
friend bool operator!=( const idStr& a, const char *b );
|
|
|
|
friend bool operator!=( const char *a, const idStr& b );
|
|
|
|
|
|
|
|
operator const char *() const;
|
|
|
|
operator const char *();
|
|
|
|
|
|
|
|
int icmpn( const char *text, int n ) const;
|
|
|
|
int icmpn( const idStr& text, int n ) const;
|
|
|
|
int icmp( const char *text ) const;
|
|
|
|
int icmp( const idStr& text ) const;
|
|
|
|
int cmpn( const char *text, int n ) const;
|
|
|
|
int cmpn( const idStr& text, int n ) const;
|
|
|
|
int cmp( const char *text ) const;
|
|
|
|
int cmp( const idStr& text ) const;
|
|
|
|
|
|
|
|
void tolower( void );
|
|
|
|
void toupper( void );
|
|
|
|
|
|
|
|
static char *tolower( char *s1 );
|
|
|
|
static char *toupper( char *s1 );
|
|
|
|
|
|
|
|
static int icmpn( const char *s1, const char *s2, int n );
|
|
|
|
static int icmp( const char *s1, const char *s2 );
|
|
|
|
static int cmpn( const char *s1, const char *s2, int n );
|
|
|
|
static int cmp( const char *s1, const char *s2 );
|
|
|
|
|
|
|
|
static void snprintf( char *dst, int size, const char *fmt, ... );
|
|
|
|
|
|
|
|
static bool isNumeric( const char *str );
|
|
|
|
bool isNumeric( void ) const;
|
|
|
|
|
|
|
|
void CapLength( int );
|
|
|
|
|
|
|
|
void BackSlashesToSlashes();
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
inline idStr::~idStr(){
|
|
|
|
if ( m_data ) {
|
|
|
|
m_data->DelRef();
|
|
|
|
m_data = NULL;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
inline idStr::idStr() : m_data( NULL ){
|
|
|
|
EnsureAlloced( 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
m_data->data[ 0 ] = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr::idStr
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const char *text
|
2012-03-17 20:01:54 +00:00
|
|
|
) : m_data( NULL ){
|
|
|
|
int len;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
assert( text );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( text ) {
|
|
|
|
len = strlen( text );
|
|
|
|
EnsureAlloced( len + 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
strcpy( m_data->data, text );
|
2012-03-17 20:01:54 +00:00
|
|
|
m_data->len = len;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
else
|
2012-03-17 20:01:54 +00:00
|
|
|
{
|
|
|
|
EnsureAlloced( 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
m_data->data[ 0 ] = 0;
|
|
|
|
m_data->len = 0;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr::idStr
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const idStr& text
|
2012-03-17 20:01:54 +00:00
|
|
|
) : m_data( NULL ){
|
|
|
|
m_data = text.m_data;
|
|
|
|
m_data->AddRef();
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr::idStr
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const idStr text,
|
2007-11-04 03:34:51 +00:00
|
|
|
int start,
|
|
|
|
int end
|
2012-03-17 20:01:54 +00:00
|
|
|
) : m_data( NULL ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int i;
|
2012-03-17 20:01:54 +00:00
|
|
|
int len;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( end > text.length() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
end = text.length();
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( start > text.length() ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
start = text.length();
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
len = end - start;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( len < 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
len = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
EnsureAlloced( len + 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < len; i++ )
|
|
|
|
{
|
2007-11-04 03:34:51 +00:00
|
|
|
m_data->data[ i ] = text[ start + i ];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
m_data->data[ len ] = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
m_data->len = len;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr::idStr
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const char ch
|
|
|
|
) : m_data( NULL ){
|
|
|
|
EnsureAlloced( 2 );
|
|
|
|
|
|
|
|
m_data->data[ 0 ] = ch;
|
|
|
|
m_data->data[ 1 ] = 0;
|
|
|
|
m_data->len = 1;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
inline idStr::idStr
|
|
|
|
(
|
|
|
|
const float num
|
|
|
|
) : m_data( NULL ){
|
|
|
|
char text[ 32 ];
|
|
|
|
int len;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( text, "%.3f", num );
|
|
|
|
len = strlen( text );
|
|
|
|
EnsureAlloced( len + 1 );
|
|
|
|
strcpy( m_data->data, text );
|
|
|
|
m_data->len = len;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr::idStr
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const int num
|
|
|
|
) : m_data( NULL ){
|
|
|
|
char text[ 32 ];
|
|
|
|
int len;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( text, "%d", num );
|
|
|
|
len = strlen( text );
|
|
|
|
EnsureAlloced( len + 1 );
|
|
|
|
strcpy( m_data->data, text );
|
|
|
|
m_data->len = len;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr::idStr
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const unsigned num
|
|
|
|
) : m_data( NULL ){
|
|
|
|
char text[ 32 ];
|
|
|
|
int len;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( text, "%u", num );
|
|
|
|
len = strlen( text );
|
|
|
|
EnsureAlloced( len + 1 );
|
|
|
|
strcpy( m_data->data, text );
|
|
|
|
m_data->len = len;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
inline int idStr::length( void ) const {
|
|
|
|
return ( m_data != NULL ) ? m_data->len : 0;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
inline int idStr::allocated( void ) const {
|
|
|
|
return ( m_data != NULL ) ? m_data->alloced + sizeof( *m_data ) : 0;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
inline const char *idStr::c_str( void ) const {
|
2007-11-04 03:34:51 +00:00
|
|
|
assert( m_data );
|
|
|
|
|
|
|
|
return m_data->data;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline void idStr::append
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const char *text
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
|
|
|
int len;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
assert( text );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( text ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
len = length() + strlen( text );
|
|
|
|
EnsureAlloced( len + 1 );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strcat( m_data->data, text );
|
|
|
|
m_data->len = len;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline void idStr::append
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const idStr& text
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
|
|
|
int len;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
len = length() + text.length();
|
|
|
|
EnsureAlloced( len + 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
strcat( m_data->data, text.c_str() );
|
|
|
|
m_data->len = len;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
inline char idStr::operator[]( int index ) const {
|
|
|
|
assert( m_data );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !m_data ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// don't include the '/0' in the test, because technically, it's out of bounds
|
|
|
|
assert( ( index >= 0 ) && ( index < m_data->len ) );
|
|
|
|
|
|
|
|
// In release mode, give them a null character
|
|
|
|
// don't include the '/0' in the test, because technically, it's out of bounds
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( index < 0 ) || ( index >= m_data->len ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return m_data->data[ index ];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline char& idStr::operator[]
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
int index
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
// Used for result for invalid indices
|
|
|
|
static char dummy = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
assert( m_data );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// We don't know if they'll write to it or not
|
|
|
|
// if it's not a const object
|
|
|
|
EnsureDataWritable();
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !m_data ) {
|
|
|
|
return dummy;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// don't include the '/0' in the test, because technically, it's out of bounds
|
|
|
|
assert( ( index >= 0 ) && ( index < m_data->len ) );
|
|
|
|
|
|
|
|
// In release mode, let them change a safe variable
|
|
|
|
// don't include the '/0' in the test, because technically, it's out of bounds
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( index < 0 ) || ( index >= m_data->len ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return dummy;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return m_data->data[ index ];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline void idStr::operator=
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const idStr& text
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
|
|
|
// adding the reference before deleting our current reference prevents
|
|
|
|
// us from deleting our string if we are copying from ourself
|
|
|
|
text.m_data->AddRef();
|
|
|
|
m_data->DelRef();
|
|
|
|
m_data = text.m_data;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline void idStr::operator=
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const char *text
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
|
|
|
int len;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
assert( text );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !text ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// safe behaviour if NULL
|
2012-03-17 20:01:54 +00:00
|
|
|
EnsureAlloced( 1, false );
|
|
|
|
m_data->data[0] = 0;
|
|
|
|
m_data->len = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !m_data ) {
|
|
|
|
len = strlen( text );
|
|
|
|
EnsureAlloced( len + 1, false );
|
|
|
|
strcpy( m_data->data, text );
|
|
|
|
m_data->len = len;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( text == m_data->data ) {
|
|
|
|
return; // Copying same thing. Punt.
|
|
|
|
|
|
|
|
}
|
|
|
|
// If we alias and I don't do this, I could corrupt other strings... This
|
|
|
|
// will get called with EnsureAlloced anyway
|
|
|
|
EnsureDataWritable();
|
|
|
|
|
|
|
|
// Now we need to check if we're aliasing..
|
|
|
|
if ( text >= m_data->data && text <= m_data->data + m_data->len ) {
|
|
|
|
// Great, we're aliasing. We're copying from inside ourselves.
|
|
|
|
// This means that I don't have to ensure that anything is alloced,
|
|
|
|
// though I'll assert just in case.
|
|
|
|
int diff = text - m_data->data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert( strlen( text ) < (unsigned) m_data->len );
|
|
|
|
|
|
|
|
for ( i = 0; text[i]; i++ )
|
|
|
|
{
|
|
|
|
m_data->data[i] = text[i];
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
m_data->data[i] = 0;
|
|
|
|
|
|
|
|
m_data->len -= diff;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
len = strlen( text );
|
2012-03-17 20:01:54 +00:00
|
|
|
EnsureAlloced( len + 1, false );
|
2007-11-04 03:34:51 +00:00
|
|
|
strcpy( m_data->data, text );
|
2012-03-17 20:01:54 +00:00
|
|
|
m_data->len = len;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr operator+
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const idStr& a,
|
|
|
|
const idStr& b
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
idStr result( a );
|
|
|
|
|
|
|
|
result.append( b );
|
|
|
|
|
|
|
|
return result;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr operator+
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const idStr& a,
|
|
|
|
const char *b
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
idStr result( a );
|
|
|
|
|
|
|
|
result.append( b );
|
|
|
|
|
|
|
|
return result;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr operator+
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const char *a,
|
|
|
|
const idStr& b
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
idStr result( a );
|
|
|
|
|
|
|
|
result.append( b );
|
|
|
|
|
|
|
|
return result;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr operator+
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const idStr& a,
|
|
|
|
const bool b
|
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
idStr result( a );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
result.append( b ? "true" : "false" );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return result;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr operator+
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const idStr& a,
|
2007-11-04 03:34:51 +00:00
|
|
|
const char b
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
|
|
|
char text[ 2 ];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
text[ 0 ] = b;
|
|
|
|
text[ 1 ] = 0;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return a + text;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr& idStr::operator+=
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const idStr& a
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
append( a );
|
|
|
|
return *this;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr& idStr::operator+=
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const char *a
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
append( a );
|
|
|
|
return *this;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr& idStr::operator+=
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const char a
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
|
|
|
char text[ 2 ];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
text[ 0 ] = a;
|
|
|
|
text[ 1 ] = 0;
|
2007-11-04 03:34:51 +00:00
|
|
|
append( text );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr& idStr::operator+=
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const bool a
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
|
|
|
append( a ? "true" : "false" );
|
2007-11-04 03:34:51 +00:00
|
|
|
return *this;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline bool operator==
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const idStr& a,
|
|
|
|
const idStr& b
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
return ( !strcmp( a.c_str(), b.c_str() ) );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline bool operator==
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const idStr& a,
|
|
|
|
const char *b
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
assert( b );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !b ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
return ( !strcmp( a.c_str(), b ) );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline bool operator==
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const char *a,
|
|
|
|
const idStr& b
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
assert( a );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !a ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
return ( !strcmp( a, b.c_str() ) );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline bool operator!=
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const idStr& a,
|
|
|
|
const idStr& b
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
return !( a == b );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline bool operator!=
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const idStr& a,
|
|
|
|
const char *b
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
return !( a == b );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline bool operator!=
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
2007-11-04 03:34:51 +00:00
|
|
|
const char *a,
|
|
|
|
const idStr& b
|
2012-03-17 20:01:54 +00:00
|
|
|
){
|
2007-11-04 03:34:51 +00:00
|
|
|
return !( a == b );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline int idStr::icmpn
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const char *text,
|
|
|
|
int n
|
|
|
|
) const {
|
2007-11-04 03:34:51 +00:00
|
|
|
assert( m_data );
|
|
|
|
assert( text );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return idStr::icmpn( m_data->data, text, n );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline int idStr::icmpn
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const idStr& text,
|
|
|
|
int n
|
|
|
|
) const {
|
2007-11-04 03:34:51 +00:00
|
|
|
assert( m_data );
|
|
|
|
assert( text.m_data );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return idStr::icmpn( m_data->data, text.m_data->data, n );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline int idStr::icmp
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const char *text
|
|
|
|
) const {
|
2007-11-04 03:34:51 +00:00
|
|
|
assert( m_data );
|
|
|
|
assert( text );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return idStr::icmp( m_data->data, text );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline int idStr::icmp
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const idStr& text
|
|
|
|
) const {
|
|
|
|
assert( c_str() );
|
|
|
|
assert( text.c_str() );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return idStr::icmp( c_str(), text.c_str() );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline int idStr::cmp
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const char *text
|
|
|
|
) const {
|
2007-11-04 03:34:51 +00:00
|
|
|
assert( m_data );
|
|
|
|
assert( text );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return idStr::cmp( m_data->data, text );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline int idStr::cmp
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const idStr& text
|
|
|
|
) const {
|
|
|
|
assert( c_str() );
|
|
|
|
assert( text.c_str() );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return idStr::cmp( c_str(), text.c_str() );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline int idStr::cmpn
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const char *text,
|
|
|
|
int n
|
|
|
|
) const {
|
|
|
|
assert( c_str() );
|
2007-11-04 03:34:51 +00:00
|
|
|
assert( text );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return idStr::cmpn( c_str(), text, n );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline int idStr::cmpn
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
const idStr& text,
|
|
|
|
int n
|
|
|
|
) const {
|
|
|
|
assert( c_str() );
|
|
|
|
assert( text.c_str() );
|
|
|
|
|
|
|
|
return idStr::cmpn( c_str(), text.c_str(), n );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline void idStr::tolower
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
void
|
|
|
|
){
|
|
|
|
assert( m_data );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
EnsureDataWritable();
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
idStr::tolower( m_data->data );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline void idStr::toupper
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
void
|
|
|
|
){
|
|
|
|
assert( m_data );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
EnsureDataWritable();
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
idStr::toupper( m_data->data );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline bool idStr::isNumeric
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
void
|
|
|
|
) const {
|
|
|
|
assert( m_data );
|
|
|
|
return idStr::isNumeric( m_data->data );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
inline idStr::operator const char *() {
|
|
|
|
return c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline idStr::operator const char *
|
2012-03-17 20:01:54 +00:00
|
|
|
(
|
|
|
|
void
|
|
|
|
) const {
|
|
|
|
return c_str();
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#endif
|