summaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-03-30 22:33:41 +0000
committerMike Buland <eichlan@xagasoft.com>2011-03-30 22:33:41 +0000
commit4b9289cfb260f4bcecaf23a810584ef6ef8e8501 (patch)
tree79136af08c7e42ba3322f0d73e9779e4354b318a /src/string.cpp
parentc7636dc954eddfe58f7959392602fbc9072d77e7 (diff)
downloadlibbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.gz
libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.bz2
libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.xz
libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.zip
Ok, string stuff is working much, much better, a load of new unit tests have
been added, and I deleted a whole slew of stupid old tests that I don't need.
Diffstat (limited to 'src/string.cpp')
-rw-r--r--src/string.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/string.cpp b/src/string.cpp
index 5834da1..edc45f9 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -443,7 +443,7 @@ Bu::String Bu::String::replace( const Bu::String &fnd,
443 const_iterator o = begin(); 443 const_iterator o = begin();
444 while( true ) 444 while( true )
445 { 445 {
446 const_iterator i = o.find( fnd ); 446 const_iterator i = o.find( fnd, fnd.getSize() );
447 if( !i ) 447 if( !i )
448 { 448 {
449 out.append( o ); 449 out.append( o );
@@ -994,7 +994,7 @@ Bu::String::const_iterator Bu::String::find( const String &rStr,
994 if( !iStart ) iStart = begin(); 994 if( !iStart ) iStart = begin();
995 for( ; iStart; iStart++ ) 995 for( ; iStart; iStart++ )
996 { 996 {
997 if( iStart.compare( rStr, rStr.getSize() ) ) 997 if( iStart.compare( rStr ) )
998 return iStart; 998 return iStart;
999 } 999 }
1000 return end(); 1000 return end();
@@ -1133,6 +1133,36 @@ void Bu::String::trimBack( long iAmnt )
1133 core->nLength -= iAmnt; 1133 core->nLength -= iAmnt;
1134} 1134}
1135 1135
1136Bu::String Bu::String::trimWhitespace() const
1137{
1138 if( core->nLength == 0 )
1139 return "";
1140 const_iterator i = begin();
1141 for( ; i && (*i == ' ' || *i == '\t' || *i == '\n' || *i == '\r'); i++ ) { }
1142 if( !i )
1143 return "";
1144
1145 const_iterator e = i;
1146 for( ; e; e++ )
1147 {
1148 if( *e == ' ' || *e == '\t' || *e == '\n' || *e == '\r' )
1149 {
1150 const_iterator t = e;
1151 for( ; t && (*t == ' ' || *t == '\t' || *t == '\n' || *t == '\r'); t++ ) { }
1152 if( t )
1153 {
1154 e = t;
1155 }
1156 else
1157 {
1158 break;
1159 }
1160 }
1161 }
1162
1163 return Bu::String( i, e );
1164}
1165
1136Bu::String::iterator Bu::String::begin() 1166Bu::String::iterator Bu::String::begin()
1137{ 1167{
1138 if( core->nLength == 0 ) 1168 if( core->nLength == 0 )