From 4b9289cfb260f4bcecaf23a810584ef6ef8e8501 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 30 Mar 2011 22:33:41 +0000 Subject: 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. --- src/string.cpp | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/string.cpp') 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, const_iterator o = begin(); while( true ) { - const_iterator i = o.find( fnd ); + const_iterator i = o.find( fnd, fnd.getSize() ); if( !i ) { out.append( o ); @@ -994,7 +994,7 @@ Bu::String::const_iterator Bu::String::find( const String &rStr, if( !iStart ) iStart = begin(); for( ; iStart; iStart++ ) { - if( iStart.compare( rStr, rStr.getSize() ) ) + if( iStart.compare( rStr ) ) return iStart; } return end(); @@ -1133,6 +1133,36 @@ void Bu::String::trimBack( long iAmnt ) core->nLength -= iAmnt; } +Bu::String Bu::String::trimWhitespace() const +{ + if( core->nLength == 0 ) + return ""; + const_iterator i = begin(); + for( ; i && (*i == ' ' || *i == '\t' || *i == '\n' || *i == '\r'); i++ ) { } + if( !i ) + return ""; + + const_iterator e = i; + for( ; e; e++ ) + { + if( *e == ' ' || *e == '\t' || *e == '\n' || *e == '\r' ) + { + const_iterator t = e; + for( ; t && (*t == ' ' || *t == '\t' || *t == '\n' || *t == '\r'); t++ ) { } + if( t ) + { + e = t; + } + else + { + break; + } + } + } + + return Bu::String( i, e ); +} + Bu::String::iterator Bu::String::begin() { if( core->nLength == 0 ) -- cgit v1.2.3