#include "strutils.hxx"
+using std::string;
+using std::vector;
+
namespace simgear {
namespace strutils {
static string
do_strip( const string& s, int striptype )
{
- // if (s.empty())
- // return s;
-
string::size_type len = s.length();
+ if( len == 0 ) // empty string is trivial
+ return s;
string::size_type i = 0;
if (striptype != RIGHTSTRIP)
{
return do_strip( s, BOTHSTRIP );
}
+ string
+ rpad( const string & s, string::size_type length, char c )
+ {
+ string::size_type l = s.length();
+ if( l >= length ) return s;
+ string reply = s;
+ return reply.append( length-l, c );
+ }
+
+ string
+ lpad( const string & s, size_t length, char c )
+ {
+ string::size_type l = s.length();
+ if( l >= length ) return s;
+ string reply = s;
+ return reply.insert( 0, length-l, c );
+ }
+
+ bool
+ starts_with( const string & s, const string & substr )
+ {
+ return s.find( substr ) == 0;
+ }
+
+ bool
+ ends_with( const string & s, const string & substr )
+ {
+ size_t n = s.rfind( substr );
+ return (n != string::npos) && (n == s.length() - substr.length());
+ }
+
} // end namespace strutils
} // end namespace simgear