1#ifndef OPM_UTILITY_STRING_HPP
2#define OPM_UTILITY_STRING_HPP
16template<
typename T,
typename U >
17U& uppercase(
const T& src, U& dst ) {
18 const auto up = [](
char c ) {
return std::toupper( c ); };
19 std::transform( std::begin( src ), std::end( src ), std::begin( dst ), up );
24typename std::decay< T >::type uppercase( T&& x ) {
25 typename std::decay< T >::type t( std::forward< T >( x ) );
26 return uppercase( t, t );
30std::string ltrim_copy(
const T& s)
32 auto ret = std::string(s.c_str());
34 const auto start = ret.find_first_not_of(
" \t\n\r\f\v");
35 if (start == std::string::npos)
38 return ret.substr(start);
43std::string rtrim_copy(
const T& s)
45 auto ret = std::string(s.c_str());
47 const auto end = ret.find_last_not_of(
" \t\n\r\f\v");
48 if (end == std::string::npos)
51 return ret.substr(0, end + 1);
55std::string trim_copy(
const T& s)
57 return ltrim_copy( rtrim_copy(s) );
62void replaceAll(T& data,
const T& toSearch,
const T& replace)
65 size_t pos = data.find(toSearch);
68 while (pos != std::string::npos)
71 data.replace(pos, toSearch.size(), replace);
73 pos = data.find(toSearch, pos + replace.size());
78inline std::vector<std::string> split_string(
const std::string& input,
81 std::vector<std::string> result;
83 std::istringstream tokenStream(input);
84 while (std::getline(tokenStream, token, delimiter))
85 result.push_back(token);
91inline std::vector<std::string> split_string(
const std::string& input,
92 const std::string& delimiters)
94 std::vector<std::string> result;
95 std::string::size_type start = 0;
96 while (start < input.size()) {
97 auto end = input.find_first_of(delimiters, start);
98 if (end == std::string::npos) {
99 result.push_back(input.substr(start));
100 end = input.size() - 1;
101 }
else if (end != start)
102 result.push_back(input.substr(start, end-start));
110inline std::string format_double(
double d) {
111 double integral_part;
112 const double decimal_part = std::modf(d, &integral_part);
114 if (decimal_part == 0)
115 return std::to_string(
static_cast<int>(d));
117 return std::to_string(d);
121inline std::optional<double> try_parse_double(
const std::string& token) {
123 auto value = std::strtod(token.c_str(), &end_ptr);
124 if (std::strlen(end_ptr) == 0)
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29