ARTEMIS
StringUtils.H
Go to the documentation of this file.
1 /* Copyright 2022 Andrew Myers, Luca Fedeli, Maxence Thevenet
2  * Revathi Jambunathan
3  *
4  * This file is part of WarpX.
5  *
6  * License: BSD-3-Clause-LBNL
7  */
8 
9 #ifndef ABLASTR_UTILS_TEXT_STRINGUTILS_H_
10 #define ABLASTR_UTILS_TEXT_STRINGUTILS_H_
11 
12 #include <AMReX_Utility.H>
13 
14 #include <string>
15 #include <vector>
16 
18 {
33  template <typename Container>
34  auto split_string (std::string const& instr, std::string const& separator,
35  bool const trim = false, std::string const& trim_space = " \t")
36  {
37  Container cont;
38  std::size_t current = instr.find(separator);
39  std::size_t previous = 0;
40  while (current != std::string::npos) {
41  if (trim){
42  cont.push_back(amrex::trim(instr.substr(previous, current - previous),trim_space));}
43  else{
44  cont.push_back(instr.substr(previous, current - previous));}
45  previous = current + separator.size();
46  current = instr.find(separator, previous);
47  }
48  if (trim){
49  cont.push_back(amrex::trim(instr.substr(previous, current - previous),trim_space));}
50  else{
51  cont.push_back(instr.substr(previous, current - previous));}
52  return cont;
53  }
54 
63  std::vector<std::string> automatic_text_wrap(
64  const std::string& text, const int max_line_length);
65 
66 }
67 
68 #endif // ABLASTR_UTILS_TEXT_STRINGUTILS_H_
Definition: StringUtils.H:18
auto split_string(std::string const &instr, std::string const &separator, bool const trim=false, std::string const &trim_space=" \t")
Splits a string using a string separator. This is somewhat similar to amrex::Tokenize....
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:14
std::string trim(std::string s, std::string const &space)