WarpX
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 <cstddef>
15 #include <string>
16 #include <vector>
17 
18 namespace ablastr::utils::text
19 {
34  template <typename Container>
35  auto split_string (std::string const& instr, std::string const& separator,
36  bool const trim = false, std::string const& trim_space = " \t")
37  {
38  Container cont;
39  std::size_t current = instr.find(separator);
40  std::size_t previous = 0;
41  while (current != std::string::npos) {
42  if (trim){
43  cont.push_back(amrex::trim(instr.substr(previous, current - previous),trim_space));}
44  else{
45  cont.push_back(instr.substr(previous, current - previous));}
46  previous = current + separator.size();
47  current = instr.find(separator, previous);
48  }
49  if (trim){
50  cont.push_back(amrex::trim(instr.substr(previous, current - previous),trim_space));}
51  else{
52  cont.push_back(instr.substr(previous, current - previous));}
53  return cont;
54  }
55 
64  std::vector<std::string> automatic_text_wrap(
65  const std::string& text, int max_line_length);
66 
67 }
68 
69 #endif // ABLASTR_UTILS_TEXT_STRINGUTILS_H_
Definition: StreamUtils.H:14
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:35
std::vector< std::string > automatic_text_wrap(const std::string &text, 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=" \t")