14 #ifndef INCLUDED_utility_string_util_hh
15 #define INCLUDED_utility_string_util_hh
27 #include <boost/algorithm/string/erase.hpp>
67 std::ostringstream os;
70 for ( ; begin != vector.end(); ++
begin ) {
71 os<< connector<< *
begin;
77 std::string
join(std::vector<std::string>
const &
s, std::string
const & connector);
80 template< platform::SSize L>
82 std::ostringstream os;
85 for ( ; begin != s.end(); ++
begin ) {
86 os<< connector<< *
begin;
93 std::string
replace_spaces(std::string
const & string_w_spaces, std::string
const & replacement);
103 string_split( std::string
const & in,
char splitchar =
' ' );
132 bool startswith(std::string
const & haystack, std::string
const & needle);
135 bool endswith(std::string
const & haystack, std::string
const & needle);
137 void slurp(std::istream & in, std::string & out);
139 void trim( std::string &
s,
const std::string & drop =
" " );
144 trim( std::string
const &
s, std::string
const & drop =
" " );
147 bool trimmed_compare( std::string
const & s1, std::string
const & s2 );
183 std::string t1 = boost::algorithm::erase_all_copy(s1,
" ");
184 std::string t2 = boost::algorithm::erase_all_copy(s2,
" ");
192 void replace_in( std::string &
s,
const char from,
const char *to )
195 for (
unsigned int c = 0; c < s.length(); ++c ) {
196 if ( s[c] == from ) s.replace(c,1,to);
201 std::string
replace_in( std::string
const & source, std::string
const & from, std::string
const & to );
207 std::ostringstream ss;
216 std::istringstream ss(s);
230 if ( in.size()==0 ) {
235 while ( j != std::string::npos ) {
236 j = in.find( splitchar, i );
237 std::string item = in.substr(i,j-i);
239 std::istringstream ss(item);
246 parts.push_back( t );
257 ( value_str ==
"true" ) ||
258 ( value_str ==
"True" ) ||
259 ( value_str ==
"TRUE" ) ||
260 ( value_str ==
"t" ) ||
261 ( value_str ==
"T" ) ||
262 ( value_str ==
"1" ) ||
263 ( value_str ==
"on" ) ||
264 ( value_str ==
"On" ) ||
265 ( value_str ==
"ON" ) ||
266 ( value_str ==
"y" ) ||
267 ( value_str ==
"Y" ) ||
268 ( value_str ==
"yes" ) ||
269 ( value_str ==
"Yes" ) ||
270 ( value_str ==
"YES" ) );
278 ( value_str ==
"false" ) ||
279 ( value_str ==
"False" ) ||
280 ( value_str ==
"FALSE" ) ||
281 ( value_str ==
"f" ) ||
282 ( value_str ==
"F" ) ||
283 ( value_str ==
"0" ) ||
284 ( value_str ==
"off" ) ||
285 ( value_str ==
"Off" ) ||
286 ( value_str ==
"OFF" ) ||
287 ( value_str ==
"n" ) ||
288 ( value_str ==
"N" ) ||
289 ( value_str ==
"no" ) ||
290 ( value_str ==
"No" ) ||
291 ( value_str ==
"NO" ) );
297 char const delimiter =
' ' );
303 char const delimiter =
' ' );
308 char const delimiter =
' ');
314 std::pair< std::vector< int >, std::vector< char > >
318 std::pair< std::vector< int >, std::vector< char > >
324 std::vector< int > &
resnum,
325 std::vector< char > &
chains );
328 std::pair< std::vector< int >, std::vector< std::string > >
334 std::vector< int > &
resnum,
335 std::vector< std::string > &
chains );
342 std::string
strip(std::string
const & source,
char c=
' ');
346 #endif // INCLUDED_utility_string_util_HH
super::const_iterator const_iterator
#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.
void trim(std::string &s, const std::string &drop)
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 strip(std::string const &source, char c)
Return a copy of the string with leading and trailing characters removed.
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.
Program exit functions and macros.
void add_spaces_left_align(std::string &st, std::size_t const newlen)
adds spaces to a left aligned string until a given length is reached
std::string make_segtag_with_dashes(utility::vector1< int > res_vector, utility::vector1< std::string > segid_vector, char const delimiter)
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
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.
void ReadFromFileOrDie(const std::string &filename, std::string *contents)
Reads the contents of into , preserving newline characters. Aborts if an error i...
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...
void add_spaces_right_align(std::string &st, std::size_t const newlen)
adds spaces to a right aligned string until a given length is reached
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.