add padding function lpad and rpad to strutils

This commit is contained in:
Torsten Dreyer
2010-08-12 13:02:16 +02:00
parent 49887ff06e
commit c0e20ad56b
2 changed files with 36 additions and 0 deletions
+18
View File
@@ -183,5 +183,23 @@ namespace simgear {
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 );
}
} // end namespace strutils
} // end namespace simgear