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