12 #define SNPRINTF _snprintf
14 #define SNPRINTF snprintf
28 std::string
fp2str(
const double x,
const std::string&
fmt)
31 int n = SNPRINTF(buf, 63, fmt.c_str(), x);
34 return std::string(buf);
36 return std::string(
" ");
42 int m = SNPRINTF(buf, 30, fmt.c_str(), n);
45 return std::string(buf);
47 return std::string(
" ");
58 const std::string& sep)
62 for (
size_t i = 0; i < v.size(); i++) {
63 SNPRINTF(buf, 63, fmt.c_str(), v[i]);
65 if (i != v.size() - 1) {
76 for (
size_t i = 0; i < s.size(); i++) {
77 lc[i] = (char) tolower(s[i]);
91 int n =
static_cast<int>(s.size());
92 for (i = 0; i < n; i++) {
93 if (s[i] !=
' ' && isprint(s[i])) {
109 int n =
static_cast<int>(s.size());
110 for (i = n-1; i >= 0; i--)
111 if (s[i] !=
' ' && isprint(s[i])) {
121 return s.substr(ifirst, ilast - ifirst + 1);
127 for (
size_t i = 0; i < s.size(); i++) {
136 const std::vector<std::string>& names)
139 for (
size_t k = 0; k < names.size(); k++) {
145 while (stop < ss.size()) {
146 size_t colon = ss.find(
':', start);
150 size_t valstart = ss.find_first_not_of(
" \t\n", colon+1);
151 stop = ss.find_first_of(
", ;\n\t", valstart);
152 std::string name =
stripws(ss.substr(start, colon-start));
153 if (!names.empty() && x.find(name) == x.end()) {
155 "unknown species '" + name +
"'");
157 x[name] =
fpValueCheck(ss.substr(valstart, stop-colon-1));
158 start = ss.find_first_not_of(
", ;\n\t", stop+1);
160 if (stop !=
npos && !
stripws(ss.substr(stop)).empty()) {
161 throw CanteraError(
"parseCompString",
"Found non-key:value data "
162 "in composition string: '" + ss.substr(stop) +
"'");
167 void split(
const std::string& ss, std::vector<std::string>& w)
171 std::string::size_type ibegin, iend;
172 std::string name, num, nm;
174 ibegin = s.find_first_not_of(
", ;\n\t");
176 s = s.substr(ibegin,s.size());
177 iend = s.find_first_of(
", ;\n\t");
179 w.push_back(s.substr(0, iend));
180 s = s.substr(iend+1, s.size());
182 w.push_back(s.substr(0, s.size()));
190 doublereal*
const a,
const char delim)
192 warn_deprecated(
"fillArrayFromString",
"To be removed after Cantera 2.2.");
193 std::string::size_type iloc;
197 while (s.size() > 0) {
198 iloc = s.find(delim);
200 num = s.substr(0, iloc);
201 s = s.substr(iloc+1,s.size());
216 size_t idot = path.find_last_of(
'.');
217 size_t islash = path.find_last_of(
'/');
218 if (idot > 0 && idot < path.size()) {
219 if (islash > 0 && islash < idot) {
220 file = path.substr(islash+1, idot-islash-1);
222 file = path.substr(0,idot);
232 return std::atoi(
stripws(val).c_str());
238 std::stringstream ss(val);
239 ss.imbue(std::locale(
"C"));
246 std::string str =
stripws(val);
248 throw CanteraError(
"fpValueCheck",
"string has zero length");
255 if (ch ==
'+' || ch ==
'-') {
258 for (
size_t i = istart; i < str.size(); i++) {
261 }
else if (ch ==
'.') {
265 "string has more than one .");
269 "string has decimal point in exponent");
271 }
else if (ch ==
'e' || ch ==
'E' || ch ==
'd' || ch ==
'D') {
276 "string has more than one exp char");
279 if (ch ==
'+' || ch ==
'-') {
284 "Trouble processing string, " + str);
302 for (
size_t n = 0; n < s.size(); n++) {
308 if (count > len && s[n] ==
' ') {
319 std::string s =
stripws(nameStr);
320 std::string::size_type ibegin, iend, icolon;
322 ibegin = s.find_first_not_of(
" ;\n\t");
324 s = s.substr(ibegin,s.size());
325 icolon = s.find(
':');
326 iend = s.find_first_of(
" ;\n\t");
328 phaseName = s.substr(0, icolon);
329 s = s.substr(icolon+1, s.size());
330 icolon = s.find(
':');
332 throw CanteraError(
"parseSpeciesName()",
"two colons in name: " + nameStr);
337 "Species name has \" ;/\n/\t\" in the middle of it: " + nameStr);
345 std::vector<std::string> v;
349 if (n > 2 || n < 1) {
351 "number of tokens is too high");
371 std::string::const_iterator i = val.begin();
372 for (; i != val.end(); i++) {
376 ibegin = (std::string::size_type) j;
396 std::string::const_iterator i = val.begin();
397 for (; i != val.end(); i++) {
401 ibegin = (std::string::size_type) j;
410 std::vector<std::string>& v)
412 std::string val(oval);
413 std::string::size_type ibegin, iend;
418 val = val.substr(ibegin,val.size());
424 v.push_back(val.substr(0,iend));
425 val = val.substr(iend+1,val.size());
433 void copyString(
const std::string& source,
char* dest,
size_t length)
435 const char* c_src = source.c_str();
436 size_t N = std::min(length, source.length()+1);
437 std::copy(c_src, c_src + N, dest);
439 dest[length-1] =
'\0';
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
doublereal fpValue(const std::string &val)
Translate a string into one doublereal value.
void split(const std::string &ss, std::vector< std::string > &w)
Parse a composition string into individual key:composition pairs.
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
std::string vec2str(const vector_fp &v, const std::string &fmt, const std::string &sep)
Convert a vector to a string (separated by commas)
static int lastChar(const std::string &s)
Return the position of the last printable character in the string.
doublereal toSI(const std::string &unit)
Return the conversion factor to convert unit std::string 'unit' to SI units.
const size_t npos
index returned by functions to indicate "no position"
static std::string fmt(const std::string &r, size_t n)
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
std::string lowercase(const std::string &s)
Cast a copy of a string to lower case.
static std::string::size_type findFirstNotOfWS(const std::string &val)
Find the first non-white space in a string.
std::string getBaseName(const std::string &path)
Get the file name without the path or extension.
static std::string::size_type findFirstWS(const std::string &val)
Find the first white space in a string.
std::string stripws(const std::string &s)
Strip the leading and trailing white space from a string.
std::string logfileName(const std::string &infile)
Generate a logfile name based on an input file name.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
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...
Base class for exceptions thrown by Cantera classes.
int fillArrayFromString(const std::string &str, doublereal *const a, const char delim)
Interpret a string as a list of floats, and convert it to a vector of floats.
std::string parseSpeciesName(const std::string &nameStr, std::string &phaseName)
Parse a name string, separating out the phase name from the species name.
std::string wrapString(const std::string &s, const int len)
Line wrap a string via a copy operation.
int intValue(const std::string &val)
Translate a string into one integer value.
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Contains declarations for string manipulation functions within Cantera.
void 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.
doublereal strSItoDbl(const std::string &strSI)
Interpret one or two token string as a single double.
std::string stripnonprint(const std::string &s)
Strip non-printing characters wherever they are.
doublereal fpValueCheck(const std::string &val)
Translate a string into one doublereal value, with error checking.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
static int firstChar(const std::string &s)
Return the position of the first printable character in the string.