9 #ifndef WARPX_UTILS_STRINGS_STRINGUTILS_H_ 10 #define WARPX_UTILS_STRINGS_STRINGUTILS_H_ 33 template <
typename Container>
34 auto split (std::string
const& instr, std::string
const& separator,
35 bool const trim =
false, std::string
const& trim_space =
" \t")
38 std::size_t current = instr.find(separator);
39 std::size_t previous = 0;
40 while (current != std::string::npos) {
42 cont.push_back(
amrex::trim(instr.substr(previous, current - previous),trim_space));}
44 cont.push_back(instr.substr(previous, current - previous));}
45 previous = current + separator.size();
46 current = instr.find(separator, previous);
49 cont.push_back(
amrex::trim(instr.substr(previous, current - previous),trim_space));}
51 cont.push_back(instr.substr(previous, current - previous));}
64 const std::string& text,
const int max_line_length);
68 #endif //WARPX_UTILS_STRINGS_STRINGUTILS_H_
auto split(std::string const &instr, std::string const &separator, bool const trim=false, std::string const &trim_space=" \)
Splits a string using a string separator. This is somewhat similar to amrex::Tokenize. The main difference is that, if the separator ":" is used, amrex::Tokenize will split ":3::2" into ["3","2"] while this functio will split ":3::2" into ["","3","","2"]. This function can also perform a trimming to remove whitespaces (or any other arbitrary string) from the split string.
Definition: StringUtils.H:34
std::vector< std::string > automatic_text_wrap(const std::string &text, const int max_line_length)
This function performs automatic text wrapping on a string, returning an array of strings each not ex...
Definition: StringUtils.cpp:13
std::string trim(std::string s, std::string const &space=" \")
Definition: StringUtils.H:17