14#define SNPRINTF _snprintf
16#define SNPRINTF snprintf
25#include <boost/algorithm/string.hpp>
28namespace ba = boost::algorithm;
33string 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 static const auto locale = std::locale(
"C");
125 std::stringstream ss(val);
133 string str = ba::trim_copy(val);
135 throw CanteraError(
"fpValueCheck",
"string has zero length");
142 if (ch ==
'+' || ch ==
'-') {
143 if (str.size() == 1) {
144 throw CanteraError(
"fpValueCheck",
"string '{}' ends in '{}'", val, ch);
148 for (
size_t i = istart; i < str.size(); i++) {
151 }
else if (ch ==
'.') {
155 "string '{}' has more than one decimal point.", val);
159 "string '{}' has decimal point in exponent", val);
161 }
else if (ch ==
'e' || ch ==
'E' || ch ==
'd' || ch ==
'D') {
166 "string '{}' has more than one exp char", val);
167 }
else if (i == str.size() - 1) {
168 throw CanteraError(
"fpValueCheck",
"string '{}' ends in '{}'", val, ch);
171 if (ch ==
'+' || ch ==
'-') {
172 if (i + 1 == str.size() - 1) {
174 "string '{}' ends in '{}'", val, ch);
179 throw CanteraError(
"fpValueCheck",
"Trouble processing string '{}'", str);
187 string val = ba::trim_copy(in_val);
194 ba::split(v, val, ba::is_space(), ba::token_compress_on);
200 string val = ba::trim_copy(in_val);
202 ba::split(v, val, ba::is_any_of(
"/\\"), ba::token_compress_on);
206size_t copyString(
const string& source,
char* dest,
size_t length)
208 const char* c_src = source.c_str();
209 size_t N = std::min(length, source.length()+1);
210 size_t ret = (length >= source.length() + 1) ? 0 : source.length() + 1;
211 std::copy(c_src, c_src + N, dest);
213 dest[length-1] =
'\0';
219 return ba::trim_copy(input);
223 return ba::to_lower_copy(input);
227 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,...
vector< string > tokenizeString(const string &in_val)
This function separates a string up into tokens according to the location of white space.
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.
vector< string > tokenizePath(const string &in_val)
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.
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...