12#include "AMReX_Config.H"
23int ReplaceAll(std::string &str,
const std::string before,
const std::string after)
26 while((start_pos = str.find(before, start_pos)) != std::string::npos) {
27 str.replace(start_pos, before.length(), after);
28 start_pos += after.length();
34int ReplaceAll(std::string &str,
const char before,
const std::string after)
37 while((start_pos = str.find(before, start_pos)) != std::string::npos) {
38 str.replace(start_pos, 1, after);
39 start_pos += after.length();
45std::string
Wrap(std::string text,
unsigned per_line)
47 unsigned line_begin = 0;
49 while (line_begin < text.size())
51 const unsigned ideal_end = line_begin + per_line ;
52 unsigned line_end = ideal_end <= text.size() ? ideal_end : text.size()-1;
54 if (line_end == text.size() - 1)
56 else if (std::isspace(text[line_end]))
58 text[line_end] =
'\n';
63 unsigned end = line_end;
64 while ( end > line_begin && !std::isspace(text[end]))
67 if (end != line_begin)
70 text[line_end++] =
'\n';
73 text.insert(line_end++, 1,
'\n');
76 line_begin = line_end;
83std::string
Join(
const std::vector<std::string> & vec,
char separator =
'_')
85 std::ostringstream oss;
86 for (
size_t i = 0; i < vec.size(); ++i) {
88 if (i < vec.size() - 1) {
98 std::ostringstream oss;
99 for (
unsigned int i = 0; i < vec.size(); ++i) {
101 if (i < vec.size() - 1) {
111 std::ostringstream oss;
112 for (
unsigned int i = 0; i < AMREX_SPACEDIM; ++i) {
113 for (
unsigned int j = 0; j < AMREX_SPACEDIM; ++j) {
115 if (i < AMREX_SPACEDIM - 1 && j < AMREX_SPACEDIM - 1 ) {
124std::vector<std::string>
Split(std::string &str,
const char delim =
' ')
126 std::vector<std::string> ret;
127 std::stringstream ss(str);
129 while (std::getline(ss, item, delim)) {
136bool Contains(std::string &str,
const std::string find)
138 if (str.find(find) != std::string::npos)
return true;
148std::complex<int>
Parse(std::string input)
154 std::vector<std::string> tokens =
Split(input,
' ');
155 for (
unsigned int i = 0; i < tokens.size(); i++)
157 if(tokens[i]==
"")
continue;
161 im += std::stoi(tokens[i]);
165 re += std::stoi(tokens[i]);
168 return std::complex<int>(re,im);
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, AMREX_SPACEDIM > Matrix
AMREX_FORCE_INLINE int ReplaceAll(std::string &str, const std::string before, const std::string after)
AMREX_FORCE_INLINE std::string Wrap(std::string text, unsigned per_line)
AMREX_FORCE_INLINE std::string Join(const std::vector< std::string > &vec, char separator='_')
AMREX_FORCE_INLINE T Parse(std::string)
AMREX_FORCE_INLINE bool Contains(std::string &str, const std::string find)
AMREX_FORCE_INLINE std::vector< std::string > Split(std::string &str, const char delim=' ')
A collection of utility routines.