16#ifndef UTILS_STDSTRINGUTILS_HPP
17#define UTILS_STDSTRINGUTILS_HPP
29 std::string
toUpper(
const std::string &input);
34 std::string
toLower(
const std::string &input);
47 std::string
stringReplace(
const std::string &source,
const std::string &orig_str,
const std::string &new_str);
62 std::string
strip(
const std::string& input);
80 int splitString(
const std::string& text,
const std::string& delimiter,
81 std::vector<std::string>& tokens);
99 template <
typename T,
long unsigned int N>
102 if(s.size() < 2 || s.front() !=
'[' || s.back() !=
']') {
107 std::vector<unsigned int> comma_indices;
108 unsigned int start_idx = 0;
109 std::size_t found = s.find(
",", start_idx);
110 while(found != std::string::npos) {
111 comma_indices.push_back(found);
112 start_idx = found + 1;
113 found = s.find(
",", start_idx);
115 comma_indices.push_back(s.size() - 1);
118 if(comma_indices.size() != N) {
123 unsigned int idx = 0;
125 for(
unsigned int i = 0; i < comma_indices.size(); i++) {
127 num_str = s.substr(idx+1, comma_indices[i] - idx - 1);
131 retval[i] = (T)stod(num_str);
136 idx = comma_indices[i];
147 template <
typename T>
150 if(s.size() < 2 || s.front() !=
'[' || s.back() !=
']') {
155 std::vector<unsigned int> comma_indices;
156 unsigned int start_idx = 0;
157 std::size_t found = s.find(
",", start_idx);
158 while(found != std::string::npos) {
159 comma_indices.push_back(found);
160 start_idx = found + 1;
161 found = s.find(
",", start_idx);
163 comma_indices.push_back(s.size() - 1);
166 unsigned int idx = 0;
168 for(
unsigned int i = 0; i < comma_indices.size(); i++) {
170 num_str = s.substr(idx+1, comma_indices[i] - idx - 1);
174 if(retval.size() > i) {
175 retval[i] = (T)stod(num_str);
177 retval.push_back((T)stod(num_str));
183 idx = comma_indices[i];
#define ERROR_DIMENSIONS
Definition clockwerkerrors.h:41
#define ERROR_CANNOT_CONVERT_STRING
Error in the case where dynamics model overruns steps or gets out of whack.
Definition clockwerkerrors.h:182
Class to propagate CR3BP dynamics in characteristic units.
Definition statistics.hpp:22
std::string strip(const std::string &input)
Removes leading and trailing whitespace characters from a string.
Definition stdstringutils.cpp:60
bool caseInsensitiveEqual(const std::string &in_a, const std::string &in_b)
Function to compare two strings independent of case.
Definition stdstringutils.cpp:43
int splitString(const std::string &text, const std::string &delimiter, std::vector< std::string > &tokens)
Splits a string into a vector of substrings based on a specified string delimiter.
Definition stdstringutils.cpp:110
bool isValidNumber(const std::string &s)
Checks if the given string is a valid numeric representation.
Definition stdstringutils.cpp:92
std::string toUpper(const std::string &input)
Function to convert a string to all upper case.
Definition stdstringutils.cpp:23
std::string stringReplace(const std::string &source, const std::string &orig_str, const std::string &new_str)
Replace the first element of a source string with a new element.
Definition stdstringutils.cpp:77
const int NO_ERROR
Definition simlicense.cpp:30
int setArrayFromString(const std::string &s, std::array< T, N > &retval)
Set a std::array from a string.
Definition stdstringutils.hpp:100
std::string toLower(const std::string &input)
Function to convert a string to all lower case.
Definition stdstringutils.cpp:33
int setVectorFromString(const std::string &s, std::vector< T > &retval)
Set a std::array from a string.
Definition stdstringutils.hpp:148