Rosetta  2020.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Namespaces | Functions
string_util.hh File Reference

Some std::string helper functions. More...

#include <utility/vector1.hh>
#include <utility/exit.hh>
#include <ObjexxFCL/string.functions.hh>
#include <utility/stream_util.hh>
#include <boost/algorithm/string/erase.hpp>
#include <list>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <tuple>
#include <typeinfo>

Namespaces

 utility
 unresizable vector whose size is known at compile time, which may be allocated on the stack, and which indexes from 0.
 

Functions

template<class T >
std::string utility::to_string (const T &t)
 
template<>
std::string utility::to_string< char > (const char &t)
 
template<class T >
T const utility::from_string (std::string const &s, T)
 
utility::vector1< std::string > utility::string_vector_from_char_vector (utility::vector1< char > const &char_vect)
 
template<class T >
utility::vector1< T > const utility::string_split (std::string const &in, char splitchar, T)
 
template<class T >
void utility::parse_out (std::stringstream &stream, T &recipient, std::string const &errmsg)
 Parse out some data of type T from a stringstream, and throw an error with a message if the operation fails. More...
 
template<class T >
void utility::parse_out (std::stringstream &stream, T &recipient)
 Parse out some data of type T from a stringstream, and throw an error with a message if the operation fails. More...
 
bool utility::parse_boolean (std::stringstream &stream, std::string const &errmsg)
 Given a stringstream in which the next block of text is any string representing "true" or any string representing "false", parse this as a Boolean, and return an informative error message if we fail. More...
 
utility::vector1< std::string > utility::split (std::string const &s)
 split given std::string using ' ' symbol. More...
 
utility::vector1< std::string > utility::split_whitespace (std::string const &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. More...
 
std::vector< std::string > utility::split_by_newlines (std::string const &s)
 
std::string utility::upper (std::string const &s)
 Make a string Uppercase. More...
 
std::string utility::lower (std::string const &s)
 Make a string Lowercase More...
 
utility::vector1< std::string > utility::quoted_split (std::string const &s)
 
std::string utility::join (utility::vector1< std::string > const &s, std::string const &connector)
 combine strings with anything More...
 
template<class T >
std::string utility::join (utility::vector1< T > const &vector, std::string const &connector)
 combine vector with anything More...
 
std::string utility::join (std::vector< std::string > const &s, std::string const &connector)
 combine strings with anything More...
 
template<platform::SSize L>
std::string utility::join (vectorL< L, std::string > const &s, std::string const &connector)
 Join vector of strings in to single string. More...
 
std::string utility::replace_spaces (std::string const &string_w_spaces, std::string const &replacement)
 replace space separations in a string with a connector such as '_' More...
 
std::list< std::string > utility::split_to_list (const std::string &s)
 split given std::string using ' ' symbol. More...
 
std::set< std::string > utility::split_to_set (std::string const &s)
 split given std::string to a set using ' ' symbol. More...
 
utility::vector1< std::string > utility::string_split (std::string const &in, char splitchar)
 
utility::vector1< std::string > utility::string_split_simple (std::string const &in, char splitchar= ' ')
 split to vector1< std::string > using arbitrary split character, but no empty strings (closer to python string::split) More...
 
utility::vector1< std::string > utility::string_split_multi_delim (std::string const &in, std::string splitchars)
 
float utility::string2float (std::string st)
 convert a string to a float, returns -1 on failure More...
 
int utility::string2int (std::string st)
 convert a string to an int, returns -1 on failure More...
 
platform::Size utility::string2Size (std::string st)
 convert a string to a Size, returns numeric::get_undefined_size() on failure More...
 
platform::Real utility::string2Real (std::string st)
 convert a string to a Real, returns numeric::get_undefined_real() on failure More...
 
std::string utility::Real2string (platform::Real, std::size_t const decimal_places)
 convert a Real to string at a number of decimal places, optionally pad left. More...
 
std::string utility::fmt_real (platform::Real, platform::Size const pad_left_newlen, 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 pad_lef_n More...
 
void utility::string2uint (const std::string &x, unsigned int *const y)
 
bool utility::startswith (std::string const &haystack, std::string const &needle)
 True iff haystack starts with needle. More...
 
bool utility::endswith (std::string const &haystack, std::string const &needle)
 True iff haystack ends with needle. More...
 
bool utility::contains (std::string const &haystack, std::string const &needle)
 Does the string contain the other string? This is purely convenience as I hate the C++ syntax to do this. More...
 
void utility::slurp (std::istream &in, std::string &out)
 Take all of the contents from the std::istream "in" and put them in the std::string "out". More...
 
void utility::ltrim (std::string &s, const std::string &drop)
 Remove any characters in "drop" from the front of the string. More...
 
void utility::rtrim (std::string &s, const std::string &drop)
 Remove any characters in "drop" from the back of the string. More...
 
void utility::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-return version. More...
 
std::string utility::strip (std::string const &source, char c=' ')
 Return a copy of the string with leading and trailing characters removed. More...
 
std::string utility::strip (std::string const &source, std::string const &drop)
 Return a copy of the string with leading and trailing characters removed Any charachters in drop will be removed For the in place version, see trim() More...
 
std::string utility::trim (std::string const &s, std::string const &drop=" ")
 Ambiguious with the trim( std::string & s ) – Deprecated: use strip() instead for return-value trimming. More...
 
bool utility::trimmed_compare (std::string const &s1, std::string const &s2)
 compares two strings ignoring leading and trailing spaces More...
 
std::string utility::pad_atom_name (std::string const &s)
 Pad an atom name to the pdb format. More...
 
std::string utility::pad_left (std::string const &s, platform::Size const newlen, char pad_with=' ')
 Add char to the left of the string. More...
 
std::string utility::pad_right (std::string const &s, platform::Size const newlen, char pad_with=' ')
 Add char to the right of a string. More...
 
template<class T >
std::string utility::pad_left (const T &t, platform::Size const newlen, char pad_width= ' ')
 Add char to the left of the string. More...
 
template<class T >
std::string utility::pad_right (const T &t, platform::Size const newlen, char pad_width= ' ')
 Add char to the right of a string. More...
 
bool utility::is_string_numeric (std::string const &input)
 
std::string utility::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". Throws a utility::excn::EXCN_msg_exception if the file cannot be opened. More...
 
std::string utility::file_basename (const std::string &full_path)
 
std::string utility::filename (const std::string &path)
 
std::string utility::pathname (const std::string &path)
 
std::string utility::replace_environment_variables (std::string input)
 find all environment variables with the form ${VARIABLE} and replace with the contents of that environment variable. if the environment variable does not exist, return string::npos More...
 
bool utility::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-alignment built into them. Slightly dangerous if you consider the fact that atom names in the PDB are different for different indentation rules: ' CA ' is c-alpha. 'CA ' is calcium. More...
 
std::string utility::string_to_sha1 (std::string const &input_string)
 
void utility::replace_in (std::string &s, const char from, const char *to)
 
std::string utility::replace_in (std::string const &source, std::string const &from, std::string const &to)
 Generate new string from 'source' by replacing all occurrences of 'from' to 'to' string. More...
 
std::string utility::remove_from_string (std::string const &source, std::string const &erase_str)
 Call boost to erase all instances of erase_str from source. More...
 
bool utility::is_true_string (std::string const &value_str)
 String accepted as a true value? More...
 
bool utility::is_false_string (std::string const &value_str)
 String accepted as a false value? More...
 
std::string utility::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". More...
 
std::string utility::make_tag_with_dashes (utility::vector1< int > res_vector, utility::vector1< char > chain_vector, utility::vector1< std::string > segid_vector, char const delimiter)
 
std::string utility::make_segtag_with_dashes (utility::vector1< int > res_vector, utility::vector1< std::string > segid_vector, char const delimiter)
 
std::string utility::make_tag (utility::vector1< int > res_vector)
 
std::tuple< std::vector< int >
, std::vector< char >
, std::vector< std::string > > 
utility::get_resnum_and_chain_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. More...
 
std::tuple< std::vector< int >
, std::vector< char >
, std::vector< std::string > > 
utility::get_resnum_and_chain (std::string const &s)
 for those who have a legacy interface that can't touch segids. More...
 
bool utility::get_resnum_and_chain_from_one_tag (std::string const &tag, std::vector< int > &resnum, std::vector< char > &chains, std::vector< std::string > &segids)
 helper function for get_resnum_and_chain More...
 
std::pair< std::vector< int >
, std::vector< std::string > > 
utility::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. More...
 
bool utility::get_resnum_and_segid_from_one_tag (std::string const &tag, std::vector< int > &resnum, std::vector< std::string > &chains)
 helper function for get_resnum_and_chain More...
 
platform::Size utility::get_num_digits (platform::Size value)
 
void utility::copy_to_cstr_buffer (std::string const &str, char *buffer, platform::Size buffer_length)
 Copy the contents of a string to a given C-style string buffer (with the given maximum length) The output will be truncated if greater than length, and null terminator will be added. More...
 

Detailed Description

Some std::string helper functions.

Author
Sergey Lyskov Jared Adolf-Bryfogle (jadol.nosp@m.fbr@.nosp@m.gmail.nosp@m..com)