12 #define SNPRINTF _snprintf
14 #define SNPRINTF snprintf
29 std::string
fp2str(
const double x,
const std::string& fmt)
32 int n = SNPRINTF(buf, 63, fmt.c_str(), x);
35 return std::string(buf);
37 return std::string(
" ");
40 std::string
int2str(
const int n,
const std::string& fmt)
43 int m = SNPRINTF(buf, 30, fmt.c_str(), n);
46 return std::string(buf);
48 return std::string(
" ");
60 int n =
static_cast<int>(s.size());
62 for (
int i = 0; i < n; i++) {
63 lc[i] = (char) tolower(s[i]);
77 int n =
static_cast<int>(s.size());
78 for (i = 0; i < n; i++) {
79 if (s[i] !=
' ' && isprint(s[i])) {
95 int n =
static_cast<int>(s.size());
96 for (i = n-1; i >= 0; i--)
97 if (s[i] !=
' ' && isprint(s[i])) {
107 return s.substr(ifirst, ilast - ifirst + 1);
113 int n =
static_cast<int>(s.size());
115 for (i = 0; i < n; i++) {
124 const std::vector<std::string>& names)
127 for (
size_t k = 0; k < names.size(); k++) {
133 size_t ibegin = s.find_first_not_of(
", ;\n\t");
135 s = s.substr(ibegin,s.size());
136 size_t icolon = s.find(
':');
137 size_t iend = s.find_first_of(
", ;\n\t");
140 std::string name =
stripws(s.substr(0, icolon));
142 num = s.substr(icolon+1, iend-icolon-1);
143 s = s.substr(iend+1, s.size());
145 num = s.substr(icolon+1, s.size());
148 if (x.find(name) == x.end()) {
150 "unknown species " + name);
161 void split(
const std::string& ss, std::vector<std::string>& w)
164 std::string::size_type ibegin, iend;
165 std::string name, num, nm;
167 ibegin = s.find_first_not_of(
", ;\n\t");
169 s = s.substr(ibegin,s.size());
170 iend = s.find_first_of(
", ;\n\t");
172 w.push_back(s.substr(0, iend));
173 s = s.substr(iend+1, s.size());
175 w.push_back(s.substr(0, s.size()));
183 doublereal*
const a,
const char delim)
185 std::string::size_type iloc;
189 while (s.size() > 0) {
190 iloc = s.find(delim);
192 num = s.substr(0, iloc);
193 s = s.substr(iloc+1,s.size());
207 size_t idot = path.find_last_of(
'.');
208 size_t islash = path.find_last_of(
'/');
209 if (idot > 0 && idot < path.size()) {
210 if (islash > 0 && islash < idot) {
211 file = path.substr(islash+1, idot-islash-1);
213 file = path.substr(0,idot);
223 return std::atoi(
stripws(val).c_str());
229 std::stringstream ss(val);
230 ss.imbue(std::locale(
"C"));
237 std::string str =
stripws(val);
239 throw CanteraError(
"fpValueCheck",
"string has zero length");
246 if (ch ==
'+' || ch ==
'-') {
249 for (
size_t i = istart; i < str.size(); i++) {
252 }
else if (ch ==
'.') {
256 "string has more than one .");
258 }
else if (ch ==
'e' || ch ==
'E' || ch ==
'd' || ch ==
'D') {
263 "string has more than one exp char");
266 if (ch ==
'+' || ch ==
'-') {
271 "Trouble processing string, " + str);
288 for (
size_t n = 0; n < s.size(); n++) {
294 if (count > len && s[n] ==
' ') {
305 std::string s =
stripws(nameStr);
306 std::string::size_type ibegin, iend, icolon;
308 ibegin = s.find_first_not_of(
" ;\n\t");
310 s = s.substr(ibegin,s.size());
311 icolon = s.find(
':');
312 iend = s.find_first_of(
" ;\n\t");
314 phaseName = s.substr(0, icolon);
315 s = s.substr(icolon+1, s.size());
316 icolon = s.find(
':');
318 throw CanteraError(
"parseSpeciesName()",
"two colons in name: " + nameStr);
323 "Species name has \" ;/\n/\t\" in the middle of it: " + nameStr);
334 const char COM_CHAR=
'\0';
338 if ((str == 0) || (str[0] ==
'\0')) {
343 while (((ch = str[i]) !=
'\0') && isspace(ch)) {
354 while ((ch = str[j+i]) !=
'\0' &&
362 while ((j != -1) && isspace(str[j])) {
372 std::vector<std::string> v;
376 if (n > 2 || n < 1) {
378 "number of tokens is too high");
398 std::string::const_iterator i = val.begin();
399 for (; i != val.end(); i++) {
403 ibegin = (std::string::size_type) j;
423 std::string::const_iterator i = val.begin();
424 for (; i != val.end(); i++) {
428 ibegin = (std::string::size_type) j;
437 std::vector<std::string>& v)
439 std::string val(oval);
440 std::string::size_type ibegin, iend;
445 val = val.substr(ibegin,val.size());
451 v.push_back(val.substr(0,iend));
452 val = val.substr(iend+1,val.size());
460 void copyString(
const std::string& source,
char* dest,
size_t length)
462 const char* c_src = source.c_str();
463 size_t N = std::min(length, source.length()+1);
464 std::copy(c_src, c_src + N, dest);
466 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...
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"
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.
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, HTML_logs (see Input File Handling, Diagnostic Output, Writing messages to the screen and Writing HTML Logfiles).
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.
int stripLTWScstring(char str[])
Routine strips off white space from a c character string.
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.
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.
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.
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.