1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdgeorgesconvert.h"
18 #include "string_ex.h"
20 namespace NLOLDGEORGES
23 //////////////////////////////////////////////////////////////////////
24 // Construction/Destruction
25 //////////////////////////////////////////////////////////////////////
27 CStringEx::~CStringEx()
32 void CStringEx::remove( const char _c
)
36 iterator it
= begin();
46 void CStringEx::remove()
53 void CStringEx::make_lower( )
55 for( iterator it
= begin(); it
!= end(); ++it
)
56 if( (*it
>= 'A')&&(*it
<= 'Z') )
60 void CStringEx::make_upper( )
62 for( iterator it
= begin(); it
!= end(); ++it
)
63 if( (*it
>= 'a')&&(*it
<= 'z') )
67 void CStringEx::trim_left( )
72 for( it
= begin(); (it
!= end())&&( (*it
==' ')||(*it
=='\t')||(*it
=='\n') ); ++it
);
76 void CStringEx::trim_left( const char _c
)
81 for( it
= begin(); (it
!= end())&&( *it
== _c
); ++it
);
85 void CStringEx::trim_right( )
91 while( it
!= begin() )
94 if( (*i
==' ')||(*i
=='\t')||(*i
=='\n') )
99 if( (*it
==' ')||(*it
=='\t')||(*it
=='\n') )
103 void CStringEx::trim_right( char c
)
108 while( it
!= begin() )
120 void CStringEx::trim()
126 void CStringEx::purge()
134 void CStringEx::trim( const char _c
)
140 void CStringEx::mid( const int nFirst
)
142 CStringEx
s( *this );
144 append( s
.get_mid( nFirst
));
147 void CStringEx::mid( const int nFirst
, const int nCount
)
149 CStringEx
s( *this );
151 append( s
.get_mid( nFirst
, nCount
));
154 void CStringEx::left( const int nCount
)
156 CStringEx
s( *this );
158 append( s
.get_left( nCount
));
161 void CStringEx::right( const int nCount
)
163 CStringEx
s( *this );
165 append( s
.get_right( nCount
));
169 CStringEx
CStringEx::get_remove( const char _c
) const
171 CStringEx
s( *this );
176 CStringEx
CStringEx::get_remove() const
178 CStringEx
s( *this );
183 CStringEx
CStringEx::get_make_lower() const
185 CStringEx
s( *this );
190 CStringEx
CStringEx::get_make_upper() const
192 CStringEx
s( *this );
197 CStringEx
CStringEx::get_trim_left() const
199 CStringEx
s( *this );
204 CStringEx
CStringEx::get_trim_left( const char _c
) const
206 CStringEx
s( *this );
211 CStringEx
CStringEx::get_trim_right() const
213 CStringEx
s( *this );
218 CStringEx
CStringEx::get_trim_right( const char _c
) const
220 CStringEx
s( *this );
225 CStringEx
CStringEx::get_trim() const
227 CStringEx
s( *this );
232 CStringEx
CStringEx::get_purge() const
234 CStringEx
s( *this );
239 CStringEx
CStringEx::get_trim( const char _c
) const
241 CStringEx
s( *this );
246 CStringEx
CStringEx::get_mid( const int nFirst
) const
253 return( get_right( size()-nFirst
) );
256 CStringEx
CStringEx::get_mid( const int nFirst
, const int nCount
) const
263 return( substr( nFirst
, nCount
) );
266 CStringEx
CStringEx::get_left( const int nCount
) const
273 return( substr( 0, nCount
) );
276 CStringEx
CStringEx::get_right( const int nCount
) const
283 return( substr( size()-nCount
, nCount
) );
287 bool CStringEx::operator <= ( const CStringEx
& s
) const
289 const_iterator it
= begin();
290 const_iterator is
= s
.begin();
291 while( ( it
!= end() )&&( is
!= s
.end() ) )
298 return( ( it
== end() )&&( is
== s
.end() ) );
301 bool CStringEx::operator < ( const CStringEx
& s
) const
303 const_iterator it
= begin();
304 const_iterator is
= s
.begin();
305 while( ( it
!= end() )&&( is
!= s
.end() ) )
312 return( is
!= s
.end() );
315 std::string::size_type
CStringEx::reverse_find( const char _c
) const
317 size_type i
= length();
318 const_iterator it
= end();
319 while( it
!= begin() )
329 void CStringEx::format( const char* s
, ... )
331 char *p
= new char[256];
334 int x
= vsprintf( p
, s
, ap
);
344 char *newfmt(const char *fmt, ...)
348 if ((p = malloc(128)) == NULL)
351 (void) vsnprintf(p, 128, fmt, ap);