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, std::string separator =
"_")
85 std::ostringstream oss;
86 for (
size_t i = 0; i < vec.size(); ++i) {
88 if (i < vec.size() - 1) {
96std::string
Join(
const std::vector<std::string> & vec,
char separator)
98 return Join(vec,std::to_string(separator));
102std::string
Join(
const std::vector<double> & vec, std::string separator =
" ")
104 std::vector<std::string> strvec;
105 for (
auto v : vec) strvec.push_back(std::to_string(v));
106 return Join(strvec,separator);
112 std::ostringstream oss;
113 for (
unsigned int i = 0; i < vec.size(); ++i) {
115 if (i < vec.size() - 1) {
125 std::ostringstream oss;
126 for (
unsigned int i = 0; i < AMREX_SPACEDIM; ++i) {
127 for (
unsigned int j = 0; j < AMREX_SPACEDIM; ++j) {
129 if (i < AMREX_SPACEDIM - 1 && j < AMREX_SPACEDIM - 1 ) {
138std::vector<std::string>
Split(std::string &str,
const char delim =
' ')
140 std::vector<std::string> ret;
141 std::stringstream ss(str);
143 while (std::getline(ss, item, delim)) {
150bool Contains(std::string &str,
const std::string find)
152 if (str.find(find) != std::string::npos)
return true;
162std::complex<int>
Parse(std::string input)
168 std::vector<std::string> tokens =
Split(input,
' ');
169 for (
unsigned int i = 0; i < tokens.size(); i++)
171 if(tokens[i]==
"")
continue;
175 im += std::stoi(tokens[i]);
179 re += std::stoi(tokens[i]);
182 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, std::string 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.