/* ************************************************************************* ArmageTron -- Just another Tron Lightcycle Game in 3D. Copyright (C) 2000 Manuel Moos (manuel@moosnet.de) ************************************************************************** This program 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. This program 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *************************************************************************** */ #include "tMemManager.h" #include "tString.h" #include "tLocale.h" #include #include #include tString::tString(){ operator[](0)='\0'; } tString::tString(const char *x){ operator[](0)='\0'; operator+=(x); } tString::tString(const tString &x){ operator[](0)='\0'; operator=(x); tASSERT( (*this) == x ); } tString::tString(const tOutput &x){ operator[](0)='\0'; operator=(x); } void tString::ReadLine(std::istream &s){ char c=' '; int i=0; SetLen(0); while(c!='\n' && isspace(c) && s.good() && !s.eof()){ c=s.get(); } s.putback(c); c='x'; while(c!='\n' && s.good() && !s.eof()){ c=s.get(); operator[](i++)=c; } if (i>0) operator[](i-1)='\0'; else operator[](0)='\0'; } tString & tString::operator<<(const char *c){ return operator+=(c); } tString & tString::operator+=(const char *c){ if (c){ if ( Len() == 0 ) operator[](0)='\0'; int i=Len()-1; if (i<0) i=0; while (*c!='\0'){ operator[](i)=*c; i++; c++; } operator[](i)='\0'; } return *this; } tString & tString::operator=(const char *c){ Clear(); return operator+=(c); } tString & tString::operator=(const tOutput& o){ Clear(); return operator <<(o); } tString tString::operator+(const char *c) const{ tString s(*this); return s+=c; //return s; } tString::operator const char *() const{ if (Len()) return &operator()(0); else return ""; } tString & tString::operator<<(char c){ return operator+=(c); } tString & tString::operator+=(char c){ if ( Len() == 0 ) operator[](0)='\0'; int i=Len(); if (i<=0) i=1; operator[](i-1)=c; operator[](i)='\0'; return *this; } tString tString::operator+(char c) const{ tString s(*this); return s+=c; //return s; } std::ostream & operator<< (std::ostream &s,const tString &x){ if(x.Len()) return s << &(x(0)); else return s; } std::istream & operator>> (std::istream &s,tString &x){ char c=' '; int i=0; x.SetLen(0); while(isspace(c) && s.good() && !s.eof()) c=s.get(); while(!isspace(c) && s.good() && !s.eof()){ x[i++]=c; c=s.get(); } s.putback(c); x[i]='\0'; return s; } void tString::SetPos(int l, bool cut){ int i; if ( l < Len() ) { if ( cut ) { if ( l > 0 ) { SetLen( l - 1 ); operator+=(' '); } else { SetLen( 0 ); } } else { operator+=(' '); } } for(i=Len();i 47 && oldname(i) < 58) { // std::cout << oldname(i) << std::endl; colorcodelength++; } else { break; } } unsigned short int c = 0; for (i=colorcodelength+2; i=oldS.Len()){ break; } } } newS << oldS[i]; } // for (i=0; i Len()) { return false; } for (int i=0; i=0; i--) if (other(i) != (*this)(i)) return false; return true; } */ // Original ge2, didn't compile under linux, some stupid overload or something, so we now have ge2 /*bool tString::operator>=(const tString &other) const { if (other.Len() > Len()) { // std::cout << "lenissue\n"; return false; } for (int i=0; i(s) << static_cast(t); return s; } /* std::stringstream& operator<<(std::stringstream& s, const int &t) { static_cast(s) << static_cast(t); return s; } std::stringstream& operator<<(std::stringstream& s, const float &t) { static_cast(s) << static_cast(t); return s; } std::stringstream& operator<<(std::stringstream& s, const short unsigned int &t) { static_cast(s) << static_cast(t); return s; } std::stringstream& operator<<(std::stringstream& s, const short int &t) { static_cast(s) << static_cast(t); return s; } std::stringstream& operator<<(std::stringstream& s, const unsigned int &t) { static_cast(s) << static_cast(t); return s; } std::stringstream& operator<<(std::stringstream& s, const unsigned long &t) { static_cast(s) << static_cast(t); return s; } std::stringstream& operator<<(std::stringstream& s, char t) { static_cast(s) << t; return s; } std::stringstream& operator<<(std::stringstream& s, bool t) { static_cast(s) << static_cast(t); return s; } std::stringstream& operator<<(std::stringstream& s, const char * const &t) { static_cast(s) << static_cast(t); return s; } */ tString & tString::operator=(const tString &s) { Clear(); for (int i = s.Len()-1; i>=0; i--) operator[](i) = s(i); tASSERT( (*this) == s ); return *this; } tString & tString::operator+=(const tString &s) { if (Len() > 0 && operator()(Len()-1) == 0) SetLen(Len()-1); for (int i = 0; i< s.Len(); i++) operator[](Len()) = s(i); if (Len() > 0 && operator()(Len()-1) != 0) operator[](Len()) = 0; return *this; } /* //static char* st_TempString = NULL; #ifdef DEBUG //static int st_TempStringLength = 10; #else //static int st_TempStringLength = 1000; #endif // static int class tTempStringCleanup { public: ~tTempStringCleanup() { if (st_TempString) free( st_TempString ); st_TempString = NULL; } }; static tTempStringCleanup cleanup; char * tString::ReserveTempString() { if (!st_TempString) st_TempString = reinterpret_cast( malloc(st_TempStringLength) ); st_TempString[st_TempStringLength-1] = 0; st_TempString[st_TempStringLength-2] = 0; return st_TempString; } int tString::TempStringLength() { return st_TempStringLength; } void tString::MakeTempStringLonger() { free(st_TempString); st_TempString = NULL; st_TempStringLength *= 2; } */ int tString::GetInt( int& pos ) const { int ret = 0; int digit = 0; while ( pos < Len() && digit >= 0 && digit <= 9 ) { ret = ret*10 + digit; digit = (*this)[pos] - '0'; pos++; } if ( ret > 0 ) { return ret + 0x10000; } else { return digit + '0'; } } int tString::CompareAlphaNumerical( const tString& a, const tString &b) { int apos = 0; int bpos = 0; while ( apos < a.Len() && bpos < b.Len() ) { int adigit = a.GetInt( apos ); int bdigit = b.GetInt( bpos ); if ( adigit < bdigit ) return 1; else if ( adigit > bdigit ) return -1; } if ( a.Len() - apos < b.Len() - bpos ) return 1; else if ( a.Len() - apos > b.Len() - bpos ) return 1; else return 0; } // ********************************************************************************************************** // * // * Compare // * // ********************************************************************************************************** //! //! @param other the string to compare with //! @return negative if *this is lexicograhically less that other, 0 if they are equal, positive otherwise //! // ********************************************************************************************************** int tString::Compare( const char* other ) const { if ( !other ) return 1; return strcmp( *this, other ); } // ********************************************************************************************************** // * // * operator == // * // ********************************************************************************************************** //! //! @param other the string to compare with //! @return true only if the two strings are equal //! // ********************************************************************************************************** bool tString::operator ==( const char* other ) const { return Compare( other ) == 0; } // ********************************************************************************************************** // * // * operator != // * // ********************************************************************************************************** //! //! @param other the string to compare with //! @return true only if the two strings are not equal //! // ********************************************************************************************************** bool tString::operator !=( const char* other ) const { return Compare( other ) != 0; } // ********************************************************************************************************** // * // * operator < // * // ********************************************************************************************************** //! //! @param other the string to compare with //! @return true only if *this is lexicographically before other //! // ********************************************************************************************************** bool tString::operator <( const char* other ) const { return Compare( other ) < 0; } // ********************************************************************************************************** // * // * operator> // * // ********************************************************************************************************** //! //! @param other the string to compare with //! @return true only if *this is lexicographically after other //! // ********************************************************************************************************** bool tString::operator>( const char* other ) const { return Compare( other ) > 0; } // ********************************************************************************************************** // * // * operator <= // * // ********************************************************************************************************** //! //! @param other the string to compare with //! @return true only if *this is not lexicographically after other //! // ********************************************************************************************************** bool tString::operator <=( const char* other ) const { return Compare( other ) <= 0; } // ********************************************************************************************************** // * // * operator >= // * // ********************************************************************************************************** //! //! @param other the string to compare with //! @return true only if *this is not lexicographically before other //! // ********************************************************************************************************** bool tString::operator >=( const char* other ) const { return Compare( other ) >= 0; } bool operator==( const char* first, const tString& second ) { return second == first; } bool operator!=( const char* first, const tString& second ) { return second != first; } bool operator<( const char* first, const tString& second ) { return second > first; } bool operator>( const char* first, const tString& second ) { return second < first; } bool operator<=( const char* first, const tString& second ) { return second >= first; } bool operator>=( const char* first, const tString& second ) { return second <= first; } bool operator==( const tString& first, const tString& second ) { return first.operator==( second ); } bool operator!=( const tString& first, const tString& second ) { return first.operator!=( second ); } bool operator<( const tString& first, const tString& second ) { return first.operator<( second ); } bool operator>( const tString& first, const tString& second ) { return first.operator>( second ); } bool operator<=( const tString& first, const tString& second ) { return first.operator<=( second ); } bool operator>=( const tString& first, const tString& second ) { return first.operator>=( second ); }