16 #ifndef INCLUDED_utility_string_util_hh
17 #define INCLUDED_utility_string_util_hh
29 #include <boost/algorithm/string/erase.hpp>
54 std::ostringstream ss;
64 std::istringstream ss(s);
84 while ( j != std::string::npos ) {
85 j = in.find( splitchar, i );
86 std::string item = in.substr(i,j-i);
88 std::istringstream ss(item);
104 split(
const std::string &
s);
121 std::ostringstream os;
124 for ( ; begin != vector.end(); ++
begin ) {
125 os<< connector<< *
begin;
131 std::string
join(std::vector<std::string>
const &
s, std::string
const & connector);
134 template< platform::SSize L>
136 std::ostringstream os;
139 for ( ; begin != s.end(); ++
begin ) {
140 os<< connector<< *
begin;
148 replace_spaces(std::string
const & string_w_spaces, std::string
const & replacement);
151 std::list< std::string >
155 std::set< std::string >
160 string_split( std::string
const & in,
char splitchar =
' ' );
203 startswith(std::string
const & haystack, std::string
const & needle);
207 endswith(std::string
const & haystack, std::string
const & needle);
210 slurp(std::istream & in, std::string & out);
214 void trim( std::string &
s,
const std::string & drop =
" " );
217 std::string
strip(std::string
const & source,
char c=
' ');
222 std::string
strip(std::string
const & source, std::string
const & drop);
228 trim( std::string
const &
s, std::string
const & drop =
" " ) {
229 return strip( s, drop );
250 return pad_left( s, newlen, pad_width );
296 std::string t1 = boost::algorithm::erase_all_copy(s1,
" ");
297 std::string t2 = boost::algorithm::erase_all_copy(s2,
" ");
310 for (
unsigned int c = 0; c < s.length(); ++c ) {
311 if ( s[c] == from ) s.replace(c,1,to);
317 replace_in( std::string
const & source, std::string
const & from, std::string
const & to );
327 ( value_str ==
"true" ) ||
328 ( value_str ==
"True" ) ||
329 ( value_str ==
"TRUE" ) ||
330 ( value_str ==
"t" ) ||
331 ( value_str ==
"T" ) ||
332 ( value_str ==
"1" ) ||
333 ( value_str ==
"on" ) ||
334 ( value_str ==
"On" ) ||
335 ( value_str ==
"ON" ) ||
336 ( value_str ==
"y" ) ||
337 ( value_str ==
"Y" ) ||
338 ( value_str ==
"yes" ) ||
339 ( value_str ==
"Yes" ) ||
340 ( value_str ==
"YES" ) );
348 ( value_str ==
"false" ) ||
349 ( value_str ==
"False" ) ||
350 ( value_str ==
"FALSE" ) ||
351 ( value_str ==
"f" ) ||
352 ( value_str ==
"F" ) ||
353 ( value_str ==
"0" ) ||
354 ( value_str ==
"off" ) ||
355 ( value_str ==
"Off" ) ||
356 ( value_str ==
"OFF" ) ||
357 ( value_str ==
"n" ) ||
358 ( value_str ==
"N" ) ||
359 ( value_str ==
"no" ) ||
360 ( value_str ==
"No" ) ||
361 ( value_str ==
"NO" ) );
367 char const delimiter =
' ' );
373 char const delimiter =
' ' );
378 char const delimiter =
' ');
384 std::pair< std::vector< int >, std::vector< char > >
388 std::pair< std::vector< int >, std::vector< char > >
394 std::vector< int > &
resnum,
395 std::vector< char > &
chains );
398 std::pair< std::vector< int >, std::vector< std::string > >
404 std::vector< int > &
resnum,
405 std::vector< std::string > &
chains );
412 #endif // INCLUDED_utility_string_util_HH
super::const_iterator const_iterator
void trim(std::string &s, const std::string &drop)
Remove any charachters in "drop" from the front and back of the string. Use strip() for the value-ret...
#define utility_exit_with_message(m)
Exit with file + line + message.
char lowercased(char const c)
Lowercased Copy of a Character.
void slurp(std::istream &in, std::string &out)
platform::Size string2Size(std::string st)
convert a string to a Size, returns numeric::get_undefined_size() on failure
std::string stripped_whitespace(std::string const &s)
Whitespace Stripped from a string's Tails Copy of a string.
float string2float(std::string st)
convert a string to a float, returns -1 on failure
void string2uint(const std::string &x, unsigned int *y)
std::string & strip_whitespace(std::string &s)
Strip Whitespace from a string's Tails.
bool same_ignoring_spaces(std::string const &s1, std::string const &s2)
Compares two strings, ignoring spaces. Useful for comparing atom name strings which have pdb-alignmen...
utility::vector1< std::string > string_split_multi_delim(std::string const &in, std::string splitchars)
bool endswith(std::string const &haystack, std::string const &needle)
True iff haystack ends with needle.
std::pair< std::vector< int >, std::vector< std::string > > get_resnum_and_segid(std::string const &s, bool &string_is_ok)
converts string like "1-3 20-22" or "A:1-5 B:20-22" to vectors containing resnums and chains...
std::vector with L-based indexing
std::string Real2string(platform::Real num, std::size_t const decimal_places)
convert a Real to string at a number of decimal places, optionally pad left.
std::set< std::string > split_to_set(const std::string &s)
split given std::string to a set using ' ' symbol.
char & lowercase(char &c)
Lowercase a Character.
utility::vector1< std::string > string_split(std::string const &in, char splitchar)
utility::vector1< std::string > split_whitespace(const std::string &s)
split given std::string using whitespace as a separator. Unlike string_split_multi_delim(), any group of mixed whitespace counts only as a single seperator.
bool get_resnum_and_segid_from_one_tag(std::string const &tag, std::vector< int > &resnum, std::vector< std::string > &segids)
helper function for get_resnum_and_chain
std::string replace_spaces(std::string const &string_w_spaces, std::string const &replacement)
replace space separations in a string with a connector such as '_'
utility::vector1< std::string > split(const std::string &s)
split given std::string using ' ' symbol.
std::string file_basename(const std::string &full_path)
platform::Real string2Real(std::string st)
convert a string to a Real, returns numeric::get_undefined_real() on failure
std::string join(utility::vector1< std::string > const &s, std::string const &connector)
combine strings with anything
T const from_string(std::string const &s, T)
std::string string_to_sha1(std::string const &input_string)
bool trimmed_compare(std::string const &s1, std::string const &s2)
compares two strings ignoring leading and trailing spaces
std::list< std::string > split_to_list(const std::string &s)
split given std::string using ' ' symbol.
std::string pad_left(std::string s, platform::Size const newlen, char pad_with)
Add char to the left of the string.
Program exit functions and macros.
std::vector< std::string > split_by_newlines(std::string const &s)
std::string make_segtag_with_dashes(utility::vector1< int > res_vector, utility::vector1< std::string > segid_vector, char const delimiter)
std::string pad_right(std::string s, platform::Size const newlen, char pad_with)
Add char to the right of a string.
std::string make_tag_with_dashes(utility::vector1< int > res_vector, char const delimiter)
Compactifies vectors of ints: 1 2 3 9 10 11 to "1-3 9-11".
bool is_false_string(std::string const &value_str)
String accepted as a false value?
bool get_resnum_and_chain_from_one_tag(std::string const &tag, std::vector< int > &resnum, std::vector< char > &chains)
helper function for get_resnum_and_chain
std::string fmt_real(platform::Real num, platform::Size pad_left_n, std::size_t const decimal_places)
convert a Real to a string, padding left with spaces until total number of char on left is equal to p...
bool is_string_numeric(std::string const &input)
std::string replace_in(std::string const &name_in, std::string const &find_string, std::string const &replace_string)
Generate new string from 'source' by replacing all occurrences of 'from' to 'to' string.
std::string filename(const std::string &path)
super::const_iterator const_iterator
list resnum
if line_edit[13:14]=='P': #Nucleic acid? Skip.
utility::vector1< std::string > string_split_simple(std::string const &in, char splitchar)
split to vector1< std::string > using arbitrary split character, but no empty strings (closer to pyth...
int string2int(std::string st)
convert a string to an int, returns -1 on failure
std::string pathname(const std::string &path)
std::string replace_environment_variables(std::string input)
find all environment variables with the form ${VARIABLE} and replace with the contents of that enviro...
vector1: std::vector with 1-based indexing
bool startswith(std::string const &haystack, std::string const &needle)
True iff haystack starts with needle.
platform::Size get_num_digits(platform::Size value)
utility::keys::lookup::begin< KeyType > const begin
std::string file_contents(std::string const &file_name)
Read the entire contents of a file into a string. All end-of-line characters are replaced by "\n"...
rule< Scanner, string_closure::context_t > name
std::string make_tag(utility::vector1< int > res_vector)
bool is_true_string(std::string const &value_str)
String accepted as a true value?
std::string to_string(const T &t)
std::pair< std::vector< int >, std::vector< char > > get_resnum_and_chain(std::string const &s, bool &string_is_ok)
converts string like "1-3 20-22" or "A:1-5 B:20-22" to vectors containing resnums and chains...
rule< Scanner, tag_closure::context_t > tag
Implemention of ostream operator << for various common types.
char uppercased(char const c)
Uppercased Copy of a Character.
char & uppercase(char &c)
Uppercase a Character.
std::string strip(std::string const &s, std::string const &drop)
Return a copy of the string with leading and trailing characters removed Any charachters in drop will...