add padding function lpad and rpad to strutils
This commit is contained in:
@@ -183,5 +183,23 @@ namespace simgear {
|
|||||||
return do_strip( s, BOTHSTRIP );
|
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 strutils
|
||||||
} // end namespace simgear
|
} // end namespace simgear
|
||||||
|
|||||||
@@ -64,6 +64,24 @@ namespace simgear {
|
|||||||
std::string rstrip( const std::string& s );
|
std::string rstrip( const std::string& s );
|
||||||
std::string strip( const std::string& s );
|
std::string strip( const std::string& s );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Right-padding of a string to a given length
|
||||||
|
* @param s String to pad
|
||||||
|
* @param length The total length of the resulting string
|
||||||
|
* @param c The character to pad with
|
||||||
|
* @return The padded string
|
||||||
|
*/
|
||||||
|
std::string rpad( const std::string & s, size_t length, char c );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Left-padding of a string to a given length
|
||||||
|
* @param s String to pad
|
||||||
|
* @param length The total length of the resulting string
|
||||||
|
* @param c The character to pad with
|
||||||
|
* @return The padded string
|
||||||
|
*/
|
||||||
|
std::string lpad( const std::string & s, size_t length, char c );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split a string into a words using 'sep' as the delimiter string.
|
* Split a string into a words using 'sep' as the delimiter string.
|
||||||
* Produces a result similar to the perl and python functions of the
|
* Produces a result similar to the perl and python functions of the
|
||||||
|
|||||||
Reference in New Issue
Block a user