52#ifndef UTILS_STRINGUTILS_HPP
53#define UTILS_STRINGUTILS_HPP
67 std::string
UpperCase(
const std::string& S);
76 int findBegin(std::istream& theStream,
const char* startText);
87 bool CaseInsensitiveEquals(
char ch1,
char ch2);
89 size_t CaseInsensitiveFind(
const std::string& str1,
const std::string& str2);
99 std::ostringstream oss;
100 if (!(oss << v)) { std::cerr <<
"toString Error" << std::endl; }
105 T lexi_cast(
const std::string& str) {
107 std::istringstream iss(str);
108 if (!(iss >> result)) { std::cerr <<
"lexi_cast Error" << std::endl; }
113 bool isType(
const std::string& str) {
115 std::istringstream iss(str);
117 if (!(iss >> result)) { ret =
false; }
121 bool isInteger(
const std::string& str);
123 std::string OpenMD_itoa(
int value,
unsigned int base = 10);
126 std::string
getPrefix(
const std::string& str);
128 template<
class ContainerType>
129 std::string containerToString(
const ContainerType& cont) {
130 std::ostringstream oss;
132 typename ContainerType::const_iterator i = cont.begin();
133 if (i != cont.end()) {
137 for (; i != cont.end(); ++i) {
145 enum class StringState :
char { SlashOC, StarIC, SingleLineComment,
146 MultiLineComment, NotAComment };
148 template <
typename InputIt,
typename OutputIt>
149 constexpr OutputIt copyWithoutComments(InputIt first, InputIt last,
151 StringState state = StringState::NotAComment;
152 while (first != last) {
154 case StringState::SlashOC:
155 if (*first ==
'/') state = StringState::SingleLineComment;
156 else if (*first ==
'*') state = StringState::MultiLineComment;
158 state = StringState::NotAComment;
163 case StringState::StarIC:
164 if (*first ==
'/') state = StringState::NotAComment;
165 else state = StringState::MultiLineComment;
167 case StringState::NotAComment:
168 if (*first ==
'#') state = StringState::SingleLineComment;
169 else if (*first ==
'/') state = StringState::SlashOC;
170 else *out++ = *first;
172 case StringState::SingleLineComment:
173 if (*first ==
'\n') {
174 state = StringState::NotAComment;
178 case StringState::MultiLineComment:
179 if (*first ==
'*') state = StringState::StarIC;
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
std::string UpperCase(const std::string &S)
Converts a string to UPPER CASE.
int findBegin(std::istream &theStream, const char *startText)
Finds the location of the string "begin <startText>" in an input stream.
std::string getPrefix(const std::string &str)
std::string toString(const T &v)
Convert a variable to a string.
int isEndLine(char *line)
discovers whether or not the line contains the "end" token