31 char const SPACE(
' ' );
42 return ( std::tolower( c ) == std::tolower( d ) );
48 equali( std::string
const &
s, std::string
const & t )
50 if ( s.length() != t.length() ) {
62 if ( s.length() != std::strlen( t ) ) {
74 if ( std::strlen( s ) != t.length() ) {
84 has_prefix( std::string
const &
s, std::string
const & pre,
bool const exact_case )
86 string::size_type
const pre_len( pre.length() );
89 }
else if ( s.length() < pre_len ) {
91 }
else if ( exact_case ) {
92 return ( s.find( pre ) == 0 );
101 has_suffix( std::string
const &
s, std::string
const & suf,
bool const exact_case )
103 string::size_type
const suf_len( suf.length() );
104 if ( suf_len == 0 ) {
107 string::size_type
const s_len( s.length() );
108 if ( s_len < suf_len ) {
110 }
else if ( exact_case ) {
111 return ( s.rfind( suf ) == s_len - suf_len );
126 string::size_type
const s_len( s.length() );
127 for ( string::size_type i = 0; i < s_len; ++i ) {
128 s[ i ] = std::tolower( s[ i ] );
138 string::size_type
const s_len( s.length() );
139 for ( string::size_type i = 0; i < s_len; ++i ) {
140 s[ i ] = std::toupper( s[ i ] );
150 string::size_type
const off( s.find_first_not_of(
SPACE ) );
151 if ( ( off > 0 ) && ( off != string::npos ) ) {
152 s.erase( 0, off ).append( off,
SPACE );
162 string::size_type
const s_len_trim(
len_trim( s ) );
163 string::size_type
const off( s.length() - s_len_trim );
165 s.erase( s_len_trim ).insert( 0, off,
SPACE );
176 string::size_type
const ie( s.find_last_not_of(
SPACE ) );
177 if ( ie == string::npos ) {
179 }
else if ( ie + 1 < s.length() ) {
192 string::size_type
const ie( s.find_last_not_of(
WHITESPACE ) );
193 if ( ie == string::npos ) {
195 }
else if ( ie + 1 < s.length() ) {
205 strip( std::string &
s, std::string
const & chars )
208 string::size_type
const ib( s.find_first_not_of( chars ) );
209 string::size_type
const ie( s.find_last_not_of( chars ) );
210 if ( ( ib == string::npos ) || ( ie == string::npos ) ) {
213 if ( ie < s.length() - 1 ) s.erase( ie + 1 );
214 if ( ib > 0 ) s.erase( 0, ib );
223 lstrip( std::string &
s, std::string
const & chars )
226 string::size_type
const ib( s.find_first_not_of( chars ) );
227 if ( ib == string::npos ) {
229 }
else if ( ib > 0 ) {
239 rstrip( std::string &
s, std::string
const & chars )
242 string::size_type
const ie( s.find_last_not_of( chars ) );
243 if ( ie == string::npos ) {
246 if ( ie < s.length() - 1 ) s.erase( ie + 1 );
258 string::size_type
const ib( s.find_first_not_of(
SPACE ) );
259 string::size_type
const ie( s.find_last_not_of(
SPACE ) );
260 if ( ( ib == string::npos ) || ( ie == string::npos ) ) {
263 if ( ie < s.length() - 1 ) s.erase( ie + 1 );
264 if ( ib > 0 ) s.erase( 0, ib );
276 string::size_type
const ib( s.find_first_not_of(
SPACE ) );
277 if ( ib == string::npos ) {
279 }
else if ( ib > 0 ) {
292 string::size_type
const ie( s.find_last_not_of(
SPACE ) );
293 if ( ie == string::npos ) {
296 if ( ie < s.length() - 1 ) s.erase( ie + 1 );
308 string::size_type
const ib( s.find_first_not_of(
WHITESPACE ) );
309 string::size_type
const ie( s.find_last_not_of(
WHITESPACE ) );
310 if ( ( ib == string::npos ) || ( ie == string::npos ) ) {
313 if ( ie < s.length() - 1 ) s.erase( ie + 1 );
314 if ( ib > 0 ) s.erase( 0, ib );
326 string::size_type
const ib( s.find_first_not_of(
WHITESPACE ) );
327 if ( ib == string::npos ) {
329 }
else if ( ib > 0 ) {
342 string::size_type
const ie( s.find_last_not_of(
WHITESPACE ) );
343 if ( ie == string::npos ) {
346 if ( ie < s.length() - 1 ) s.erase( ie + 1 );
355 pad( std::string &
s, std::string::size_type
const len )
357 string::size_type
const s_len( s.length() );
359 s.append( len - s_len,
SPACE );
367 lpad( std::string &
s, std::string::size_type
const len )
369 string::size_type
const s_len( s.length() );
371 s.insert( static_cast< string::size_type >( 0 ), len - s_len,
SPACE );
379 rpad( std::string &
s, std::string::size_type
const len )
381 string::size_type
const s_len( s.length() );
383 s.append( len - s_len,
SPACE );
391 size( std::string &
s, std::string::size_type
const len )
393 string::size_type
const s_len( s.length() );
395 s.append( len - s_len,
SPACE );
396 }
else if ( s_len > len ) {
407 string::size_type
const s_len( s.length() );
417 string::size_type
const s_len( s.length() );
419 string::size_type
const off( ( len - s_len ) / 2 );
420 s = string( off,
SPACE ).append( s ).append(
string( len - s_len - off,
SPACE ) );
421 }
else if ( s_len > len ) {
433 string::size_type
const s_len( s.length() );
434 for ( string::size_type i = 0; i < s_len; ++i ) {
435 if ( u.find( s[ i ] ) == string::npos ) {
436 u.push_back( s[ i ] );
446 overlay( std::string &
s, std::string
const & t, std::string::size_type
const pos )
448 std::string::size_type
const t_len( t.length() );
449 std::string::size_type
const l_len( pos + t_len );
450 if ( l_len > s.length() ) s.resize( l_len,
' ' );
451 s.replace( pos, t_len, t );
464 string::size_type
const t_len( t.length() );
465 for ( string::size_type i = 0; i < t_len; ++i ) {
466 t[ i ] = std::tolower( t[ i ] );
477 string::size_type
const t_len( t.length() );
478 for ( string::size_type i = 0; i < t_len; ++i ) {
479 t[ i ] = std::toupper( t[ i ] );
489 string::size_type
const off( s.find_first_not_of(
SPACE ) );
490 if ( ( off > 0 ) && ( off != string::npos ) ) {
491 return s.substr( off ).append( off,
SPACE );
502 string::size_type
const s_len_trim(
len_trim( s ) );
503 string::size_type
const off( s.length() - s_len_trim );
505 return string( off,
SPACE ).append( s.substr( 0, s_len_trim ) );
519 string::size_type
const ie( s.find_last_not_of(
SPACE ) );
520 if ( ie == string::npos ) {
522 }
else if ( ie < s.length() - 1 ) {
523 return s.substr( 0, ie + 1 );
538 string::size_type
const ie( s.find_last_not_of(
WHITESPACE ) );
539 if ( ie == string::npos ) {
541 }
else if ( ie < s.length() - 1 ) {
542 return s.substr( 0, ie + 1 );
552 stripped( std::string
const &
s, std::string
const & chars )
557 string::size_type
const ib( s.find_first_not_of( chars ) );
558 string::size_type
const ie( s.find_last_not_of( chars ) );
559 if ( ( ib == string::npos ) || ( ie == string::npos ) ) {
562 return s.substr( ib, ie - ib + 1 );
570 lstripped( std::string
const &
s, std::string
const & chars )
575 string::size_type
const ib( s.find_first_not_of( chars ) );
576 if ( ib == string::npos ) {
578 }
else if ( ib > 0 ) {
579 return s.substr( ib );
589 rstripped( std::string
const &
s, std::string
const & chars )
594 string::size_type
const ie( s.find_last_not_of( chars ) );
595 if ( ie == string::npos ) {
598 return s.substr( 0, ie + 1 );
611 string::size_type
const ib( s.find_first_not_of(
SPACE ) );
612 string::size_type
const ie( s.find_last_not_of(
SPACE ) );
613 if ( ( ib == string::npos ) || ( ie == string::npos ) ) {
616 return s.substr( ib, ie - ib + 1 );
629 string::size_type
const ib( s.find_first_not_of(
SPACE ) );
630 if ( ib == string::npos ) {
632 }
else if ( ib > 0 ) {
633 return s.substr( ib );
648 string::size_type
const ie( s.find_last_not_of(
SPACE ) );
649 if ( ie == string::npos ) {
652 return s.substr( 0, ie + 1 );
665 string::size_type
const ib( s.find_first_not_of(
WHITESPACE ) );
666 string::size_type
const ie( s.find_last_not_of(
WHITESPACE ) );
667 if ( ( ib == string::npos ) || ( ie == string::npos ) ) {
670 return s.substr( ib, ie - ib + 1 );
683 string::size_type
const ib( s.find_first_not_of(
WHITESPACE ) );
684 if ( ib == string::npos ) {
686 }
else if ( ib > 0 ) {
687 return s.substr( ib );
702 string::size_type
const ie( s.find_last_not_of(
WHITESPACE ) );
703 if ( ie == string::npos ) {
706 return s.substr( 0, ie + 1 );
714 padded( std::string
const &
s, std::string::size_type
const len )
716 string::size_type
const s_len( s.length() );
718 return s + string( len - s_len,
SPACE );
727 lpadded( std::string
const &
s, std::string::size_type
const len )
729 string::size_type
const s_len( s.length() );
731 return string( len - s_len,
SPACE ).append( s );
740 rpadded( std::string
const &
s, std::string::size_type
const len )
742 string::size_type
const s_len( s.length() );
744 return s + string( len - s_len,
SPACE );
753 sized( std::string
const &
s, std::string::size_type
const len )
755 string::size_type
const s_len( s.length() );
757 return s + string( len - s_len,
SPACE );
758 }
else if ( s_len == len ) {
761 return s.substr( 0, len );
778 string::size_type
const s_len( s.length() );
780 string::size_type
const off( ( len - s_len ) / 2 );
781 return string( off,
SPACE ).append( s ).append(
string( len - s_len - off,
SPACE ) );
782 }
else if ( s_len == len ) {
785 return s.substr( 0, len );
795 string::size_type
const s_len( s.length() );
796 for ( string::size_type i = 0; i < s_len; ++i ) {
797 if ( u.find( s[ i ] ) == string::npos ) {
798 u.push_back( s[ i ] );
812 string::size_type
const ie( s.find(
SPACE ) );
813 if ( ie == string::npos ) {
816 return s.substr( 0, ie );
825 bool string_is_ok(
false );
833 bool string_is_ok(
false );
834 return ints_of( s, string_is_ok );
840 ints_of( std::string
const & s_input,
bool & string_is_ok ){
842 std::vector< int > vals;
843 string_is_ok =
false;
845 std::string
s( s_input );
848 while( s.find(
',' ) != std::string::npos ){
849 std::vector< int > vals_up_to_comma =
ints_of( s.substr( 0, s.find(
',' ) ) );
850 for (
unsigned n = 0; n < vals_up_to_comma.size(); n++ ) vals.push_back( vals_up_to_comma[ n ] );
851 s = s.substr( s.find(
',' )+1 );
854 size_t found_dash = s.find(
"-" );
855 if ( found_dash == 0 ) found_dash = s.substr(1).find(
"-") + 1;
856 if ( found_dash == std::string::npos || found_dash == 0 ){
858 string_is_ok =
is_int( s );
859 if ( string_is_ok ) vals.push_back(
int_of( s ) );
862 std::string
const start_val_string = s.substr(0,found_dash );
863 std::string
const end_val_string = s.substr(found_dash+1, s.size() );
864 string_is_ok =
is_int( start_val_string ) &&
is_int( end_val_string);
866 int start_val =
int_of( start_val_string );
867 int end_val =
int_of( end_val_string );
868 for (
int n = start_val; n <= end_val; n++ ) vals.push_back( n );
std::string & size(std::string &s, std::string::size_type const len)
Size a string to a Specified Length.
bool char_equali(char const c, char const d)
char == char Case-Insensitively (non-inline for use by equali below)?
char lowercased(char const c)
Lowercased Copy of a Character.
bool has_suffix(std::string const &s, std::string const &suf, bool const exact_case)
Has a Suffix Case-Optionally?
std::string stripped_whitespace(std::string const &s)
Whitespace Stripped from a string's Tails Copy of a string.
std::string & strip_whitespace(std::string &s)
Strip Whitespace from a string's Tails.
std::string & trim_whitespace(std::string &s)
Trim Trailing Whitespace from a string.
std::string & overlay(std::string &s, std::string const &t, std::string::size_type const pos)
Overlay a string With Another string, Expanding Size as Needed.
std::string rstripped(std::string const &s, std::string const &chars)
Specified Characters Stripped from a string's Right Tail Copy of a string.
bool has_prefix(std::string const &s, std::string const &pre, bool const exact_case)
Has a Prefix Case-Optionally?
char & lowercase(char &c)
Lowercase a Character.
std::string & lstrip_whitespace(std::string &s)
Strip Whitespace from a string's Left Tail.
Fstring::size_type len(Fstring const &s)
Length.
bool is_ints(std::string const &s)
ints of a string (e.g., allowing "5-8" to represent "5 6 7 8").
bool equali(char const c, char const d)
char == char Case-Insensitively
std::string & rstrip_whitespace(std::string &s)
Strip Whitespace from a string's Right Tail.
std::string padded(std::string const &s, std::string::size_type const len)
Padded to a Specified Length Copy of a string.
std::string & pad(std::string &s, std::string::size_type const len)
Pad a string to a Specified Length.
std::string & strip(std::string &s, std::string const &chars)
Strip Specified Characters from a string's Tails.
std::string head(std::string const &s)
Space-Free Head Copy of a string.
std::string trimmed_whitespace(std::string const &s)
Trailing Whitespace Trimmed Copy of a string.
std::string rpadded(std::string const &s, std::string::size_type const len)
Right-Padded to a Specified Length Copy of a string.
bool equal(char const c, char const d, bool const exact_case)
char == char Case-Optionally?
std::string & trim(std::string &s)
Trim Trailing Space from a string.
Fstring::size_type len_trim(Fstring const &s)
Length Space-Trimmed.
std::string & lpad(std::string &s, std::string::size_type const len)
Left-Pad a string to a Specified Length.
std::string uniqued(std::string const &s)
Removed Repeat Characters from a Possibly Unsorted string Preserving Order Copy of a string...
std::string & unique(std::string &s)
Remove Repeat Characters from a Possibly Unsorted string Preserving Order.
std::string left_justified(std::string const &s)
Left-Justified Copy of a string.
std::string & rpad(std::string &s, std::string::size_type const len)
Right-Pad a string to a Specified Length.
std::string & lstrip(std::string &s, std::string const &chars)
Strip Specified Characters from a string's Left Tail.
std::vector< int > ints_of(std::string const &s)
ints of a string (e.g., allowing "5-8" to represent "5 6 7 8").
std::string stripped(std::string const &s, std::string const &chars)
Specified Characters Stripped from a string's Tails Copy of a string.
bool is_int(Fstring const &s)
Fstring is Readable as an int?
std::string lpadded(std::string const &s, std::string::size_type const len)
Left-Padded to a Specified Length Copy of a string.
std::string centered(std::string const &s)
Centered wrt Whitespace Copy of a string.
Fstring center(Fstring const &s)
Centered Copy.
std::string & right_justify(std::string &s)
Right Justify a string.
std::string rstripped_whitespace(std::string const &s)
Whitespace Stripped from a string's Right Tail Copy of a string.
int int_of(Fstring const &s)
int of an Fstring
std::string lstripped(std::string const &s, std::string const &chars)
Specified Characters Stripped from a string's Left Tail Copy of a string.
Fstring trimmed(Fstring const &s)
Space-Trimmed Copy.
std::string & rstrip(std::string &s, std::string const &chars)
Strip Specified Characters from a string's Right Tail.
std::string sized(std::string const &s, std::string::size_type const len)
Sized to a Specified Length Copy of a string.
char uppercased(char const c)
Uppercased Copy of a Character.
char & uppercase(char &c)
Uppercase a Character.
std::string right_justified(std::string const &s)
Right-Justified Copy of a string.
std::string lstripped_whitespace(std::string const &s)
Whitespace Stripped from a string's Left Tail Copy of a string.
std::string & left_justify(std::string &s)
Left Justify a string.
std::string const WHITESPACE(" \t\0", 3)