00001 00014 /*************************************************************************** 00015 * Copyright (C) 2007 by Jan Koci * 00016 * honza.koci@email.cz * 00017 * http://kengine.sourceforge.net/tutorial/ 00018 * * 00019 * This program is free software; you can redistribute it and/or modify * 00020 * it under the terms of the GNU General Public License as published by * 00021 * the Free Software Foundation; either version 2 of the License, or * 00022 * (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the * 00031 * Free Software Foundation, Inc., * 00032 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00033 ***************************************************************************/ 00034 00035 #include "K3dString.h" 00036 00037 using namespace std; 00038 00039 //K3dString::K3dString g_K3dString; 00040 00043 TString & K3dString::ToLower() 00044 { 00045 std::transform ( m_str.begin(),m_str.end(), m_str.begin(), K3dToLower() ); 00046 return m_str; 00047 } 00048 00051 void K3dString::StrLwr ( const char * _str ) 00052 { 00053 #ifndef K_WIN32 00054 m_str = _str; 00055 ToLower(); 00056 _str = m_str.c_str(); 00057 #else 00058 strlwr ( _str ); 00059 #endif 00060 } 00061 00065 size_t K3dString::Find ( const char *_str ) 00066 { 00067 return m_str.find ( _str ); 00068 } 00069 00073 size_t K3dString::RFind ( const char *_str ) 00074 { 00075 return m_str.rfind ( _str ); 00076 } 00077 00081 TString& K3dString::SetNum ( int _iVal ) 00082 { 00083 TStrStream stream; 00084 stream << _iVal; 00085 m_str = stream.str(); 00086 return m_str; 00087 } 00091 TString& K3dString::SetNum ( bool _bVal ) 00092 { 00093 if ( _bVal ) 00094 { 00095 m_str = "true"; 00096 } 00097 else 00098 { 00099 m_str = "false"; 00100 } 00101 return m_str; 00102 } 00106 TString& K3dString::SetNum ( unsigned int _uiVal ) 00107 { 00108 TStrStream stream; 00109 stream << _uiVal; 00110 stream >> m_str; 00111 return m_str; 00112 } 00116 TString& K3dString::SetNum ( float _fVal ) 00117 { 00118 TStrStream stream; 00119 stream << _fVal; 00120 stream >> m_str; 00121 return m_str; 00122 } 00123 00126 void K3dString::AddNumber ( const int _iVal ) 00127 { 00128 TString strPrev = m_str; 00129 SetNum ( _iVal ); 00130 m_str = strPrev + m_str; 00131 } 00132 00135 K3dString &K3dString::Left ( size_t _iPos ) 00136 { 00137 if ( ( _iPos >= 0 ) && ( _iPos <= m_str.length() ) ) 00138 { 00139 size_t iBegin = _iPos; 00140 size_t iNum = m_str.length() - iBegin; 00141 m_str.erase ( iBegin,iNum ); 00142 } 00143 else 00144 { 00145 cerr << "Error :: K3dString &K3dString::Left() -- Wrong position '" << _iPos << "' for erase function" << endl; 00146 } 00147 return *this; 00148 } 00149 00152 K3dString &K3dString::Right ( size_t _iPos ) 00153 { 00154 if ( ( _iPos >= 0 ) && ( _iPos <= m_str.length() ) ) 00155 { 00156 size_t iBegin = 0; 00157 size_t iNum = _iPos+1; 00158 m_str.erase ( iBegin,iNum ); 00159 } 00160 else 00161 { 00162 cerr << "Error :: K3dString &K3dString::Right() -- Wrong position '" << _iPos << "' for erase function" << endl; 00163 } 00164 return *this; 00165 } 00166 00171 K3dString &K3dString::GetStrTok ( K3dString &_strOut, const K3dString &_strSign ) 00172 { 00173 K3dString strTemp = _strOut; 00174 size_t iPos = _strOut.Find ( _strSign ); 00175 if ( iPos == string::npos ) 00176 { 00177 m_bFoundToken = false; 00178 } 00179 else 00180 { 00181 m_bFoundToken = true; 00182 // Return right string back of sign _strSign 00183 _strOut.Right ( iPos ); 00184 // Return left string front of sign _strSign 00185 m_str = strTemp.Left ( iPos ).GetString(); 00186 } 00187 return *this; 00188 }