14#define SNPRINTF _snprintf
16#define SNPRINTF snprintf
25#include <boost/algorithm/string.hpp>
28namespace ba = boost::algorithm;
34 const std::string& sep)
38 for (
size_t i = 0; i < v.size(); i++) {
39 SNPRINTF(buf, 63,
fmt.c_str(), v[i]);
41 if (i != v.size() - 1) {
51 for (
size_t i = 0; i < s.size(); i++) {
60 const std::vector<std::string>& names)
63 for (
size_t k = 0; k < names.size(); k++) {
70 while (stop < ss.size()) {
71 size_t colon = ss.find(
':', left);
75 size_t valstart = ss.find_first_not_of(
" \t\n", colon+1);
76 stop = ss.find_first_of(
", ;\n\t", valstart);
77 std::string name = ba::trim_copy(ss.substr(start, colon-start));
78 if (!names.empty() && x.find(name) == x.end()) {
80 "unknown species '" + name +
"'");
85 value =
fpValueCheck(ss.substr(valstart, stop-valstart));
91 std::string testname = ss.substr(start, stop-start);
92 if (testname.find_first_of(
" \n\t") !=
npos) {
95 }
else if (ss.substr(valstart, stop-valstart).find(
':') !=
npos) {
103 if (
getValue(x, name, 0.0) != 0.0) {
105 "Duplicate key: '" + name +
"'.");
109 start = ss.find_first_not_of(
", ;\n\t", stop+1);
113 throw CanteraError(
"parseCompString",
"Unable to parse key-value pair:"
114 "\n'{}'", ss.substr(start, stop));
116 if (stop !=
npos && !ba::trim_copy(ss.substr(stop)).empty()) {
117 throw CanteraError(
"parseCompString",
"Found non-key:value data "
118 "in composition string: '" + ss.substr(stop) +
"'");
125 return std::atoi(ba::trim_copy(val).c_str());
131 std::stringstream ss(val);
132 ss.imbue(std::locale(
"C"));
139 std::string str = ba::trim_copy(val);
141 throw CanteraError(
"fpValueCheck",
"string has zero length");
148 if (ch ==
'+' || ch ==
'-') {
149 if (str.size() == 1) {
150 throw CanteraError(
"fpValueCheck",
"string '{}' ends in '{}'", val, ch);
154 for (
size_t i = istart; i < str.size(); i++) {
157 }
else if (ch ==
'.') {
161 "string '{}' has more than one decimal point.", val);
165 "string '{}' has decimal point in exponent", val);
167 }
else if (ch ==
'e' || ch ==
'E' || ch ==
'd' || ch ==
'D') {
172 "string '{}' has more than one exp char", val);
173 }
else if (i == str.size() - 1) {
174 throw CanteraError(
"fpValueCheck",
"string '{}' ends in '{}'", val, ch);
177 if (ch ==
'+' || ch ==
'-') {
178 if (i + 1 == str.size() - 1) {
180 "string '{}' ends in '{}'", val, ch);
185 throw CanteraError(
"fpValueCheck",
"Trouble processing string '{}'", str);
193 warn_deprecated(
"parseSpeciesName",
"To be removed after Cantera 2.6");
194 std::string s = ba::trim_copy(nameStr);
196 size_t ibegin = s.find_first_not_of(
" ;\n\t");
198 s = s.substr(ibegin,s.size());
199 size_t icolon = s.find(
':');
200 size_t iend = s.find_first_of(
" ;\n\t");
202 phaseName = s.substr(0, icolon);
203 s = s.substr(icolon+1, s.size());
204 icolon = s.find(
':');
207 "two colons in name: '{}'", nameStr);
211 throw CanteraError(
"parseSpeciesName",
"Species name has "
212 "\" ;/\n/\t\" in the middle of it: '{}'", nameStr);
220 std::vector<std::string> v;
224 if (n > 2 || n < 1) {
226 "number of tokens is too high");
236 std::string val = ba::trim_copy(in_val);
243 ba::split(v, val, ba::is_space(), ba::token_compress_on);
246size_t copyString(
const std::string& source,
char* dest,
size_t length)
248 const char* c_src = source.c_str();
249 size_t N = std::min(length, source.length()+1);
250 size_t ret = (length >= source.length() + 1) ? 0 : source.length() + 1;
251 std::copy(c_src, c_src + N, dest);
253 dest[length-1] =
'\0';
259 return ba::trim_copy(input);
263 return ba::to_lower_copy(input);
267 return ba::iequals(input, test);
Base class for exceptions thrown by Cantera classes.
This file contains definitions of constants, types and terms that are used in internal routines and a...
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles,...
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
int intValue(const std::string &val)
Translate a string into one integer value.
doublereal fpValue(const std::string &val)
Translate a string into one doublereal value.
bool caseInsensitiveEquals(const std::string &input, const std::string &test)
Case insensitive equality predicate.
std::string vec2str(const vector_fp &v, const std::string &fmt="%g", const std::string &sep=", ")
Convert a vector to a string (separated by commas)
void warn_deprecated(const std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an input file.
std::string trimCopy(const std::string &input)
Trim.
size_t copyString(const std::string &source, char *dest, size_t length)
Copy the contents of a std::string into a char array of a given length.
std::string toLowerCopy(const std::string &input)
Convert to lower case.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
std::string parseSpeciesName(const std::string &nameStr, std::string &phaseName)
Parse a name string, separating out the phase name from the species name.
doublereal toSI(const std::string &unit)
Return the conversion factor to convert unit std::string 'unit' to SI units.
doublereal fpValueCheck(const std::string &val)
Translate a string into one doublereal value, with error checking.
doublereal strSItoDbl(const std::string &strSI)
Interpret one or two token string as a single double.
void tokenizeString(const std::string &oval, std::vector< std::string > &v)
This function separates a string up into tokens according to the location of white space.
std::map< std::string, double > compositionMap
Map connecting a string name with a double.
const U & getValue(const std::map< T, U > &m, const T &key, const U &default_val)
Const accessor for a value in a std::map.
std::string stripnonprint(const std::string &s)
Strip non-printing characters wherever they are.
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names=std::vector< std::string >())
Parse a composition string into a map consisting of individual key:composition pairs.
Versions 6.2.0 and 6.2.1 of fmtlib do not include this define before they include windows....
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...