14 #define SNPRINTF _snprintf
16 #define SNPRINTF snprintf
25 #include <boost/algorithm/string.hpp>
28 namespace ba = boost::algorithm;
33 string vec2str(
const vector<double>& v,
const string& fmt,
const string& sep)
37 for (
size_t i = 0; i < v.size(); i++) {
38 SNPRINTF(buf, 63, fmt.c_str(), v[i]);
40 if (i != v.size() - 1) {
50 for (
size_t i = 0; i < s.size(); i++) {
61 for (
size_t k = 0; k < names.size(); k++) {
68 while (stop < ss.size()) {
69 size_t colon = ss.find(
':', left);
73 size_t valstart = ss.find_first_not_of(
" \t\n", colon+1);
74 stop = ss.find_first_of(
", ;\n\t", valstart);
75 string name = ba::trim_copy(ss.substr(start, colon-start));
76 if (!names.empty() && x.find(name) == x.end()) {
78 "unknown species '" + name +
"'");
83 value =
fpValueCheck(ss.substr(valstart, stop-valstart));
89 string testname = ss.substr(start, stop-start);
90 if (testname.find_first_of(
" \n\t") !=
npos) {
93 }
else if (ss.substr(valstart, stop-valstart).find(
':') !=
npos) {
101 if (
getValue(x, name, 0.0) != 0.0) {
103 "Duplicate key: '" + name +
"'.");
107 start = ss.find_first_not_of(
", ;\n\t", stop+1);
111 throw CanteraError(
"parseCompString",
"Unable to parse key-value pair:"
112 "\n'{}'", ss.substr(start, stop));
114 if (stop !=
npos && !ba::trim_copy(ss.substr(stop)).empty()) {
115 throw CanteraError(
"parseCompString",
"Found non-key:value data "
116 "in composition string: '" + ss.substr(stop) +
"'");
124 std::stringstream ss(val);
125 ss.imbue(std::locale(
"C"));
132 string str = ba::trim_copy(val);
134 throw CanteraError(
"fpValueCheck",
"string has zero length");
141 if (ch ==
'+' || ch ==
'-') {
142 if (str.size() == 1) {
143 throw CanteraError(
"fpValueCheck",
"string '{}' ends in '{}'", val, ch);
147 for (
size_t i = istart; i < str.size(); i++) {
150 }
else if (ch ==
'.') {
154 "string '{}' has more than one decimal point.", val);
158 "string '{}' has decimal point in exponent", val);
160 }
else if (ch ==
'e' || ch ==
'E' || ch ==
'd' || ch ==
'D') {
165 "string '{}' has more than one exp char", val);
166 }
else if (i == str.size() - 1) {
167 throw CanteraError(
"fpValueCheck",
"string '{}' ends in '{}'", val, ch);
170 if (ch ==
'+' || ch ==
'-') {
171 if (i + 1 == str.size() - 1) {
173 "string '{}' ends in '{}'", val, ch);
178 throw CanteraError(
"fpValueCheck",
"Trouble processing string '{}'", str);
186 string val = ba::trim_copy(in_val);
193 ba::split(v, val, ba::is_space(), ba::token_compress_on);
198 string val = ba::trim_copy(in_val);
200 ba::split(v, val, ba::is_any_of(
"/\\"), ba::token_compress_on);
203 size_t copyString(
const string& source,
char* dest,
size_t length)
205 const char* c_src = source.c_str();
206 size_t N = std::min(length, source.length()+1);
207 size_t ret = (length >= source.length() + 1) ? 0 : source.length() + 1;
208 std::copy(c_src, c_src + N, dest);
210 dest[length-1] =
'\0';
216 return ba::trim_copy(input);
220 return ba::to_lower_copy(input);
224 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 and logging,...
size_t copyString(const string &source, char *dest, size_t length)
Copy the contents of a string into a char array of a given length.
bool caseInsensitiveEquals(const string &input, const string &test)
Case insensitive equality predicate.
string stripnonprint(const string &s)
Strip non-printing characters wherever they are.
string vec2str(const vector< double > &v, const string &fmt, const string &sep)
Convert a vector to a string (separated by commas)
double fpValue(const string &val)
Translate a string into one double value.
string trimCopy(const string &input)
Trim.
void tokenizePath(const string &in_val, vector< string > &v)
This function separates a string up into tokens according to the location of path separators.
double fpValueCheck(const string &val)
Translate a string into one double value, with error checking.
string toLowerCopy(const string &input)
Convert to lower case.
Composition parseCompString(const string &ss, const vector< string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
void tokenizeString(const string &in_val, vector< string > &v)
This function separates a string up into tokens according to the location of white space.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
const U & getValue(const map< T, U > &m, const T &key, const U &default_val)
Const accessor for a value in a map.
map< string, double > Composition
Map from string names to doubles.
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...