12 #define SNPRINTF _snprintf
14 #define SNPRINTF snprintf
42 std::string
fp2str(
const double x,
const std::string& fmt)
45 int n = SNPRINTF(buf, 63, fmt.c_str(), x);
48 return std::string(buf);
50 return std::string(
" ");
55 int n = SNPRINTF(buf, 64,
"%g" , x);
58 return std::string(buf);
60 return std::string(
" ");
66 std::string
int2str(
const int n,
const std::string& fmt)
69 int m = SNPRINTF(buf, 30, fmt.c_str(), n);
72 return std::string(buf);
74 return std::string(
" ");
84 int m = SNPRINTF(buf, 30,
"%d", n);
87 return std::string(buf);
89 return std::string(
" ");
105 int n =
static_cast<int>(s.size());
107 for (
int i = 0; i < n; i++) {
108 lc[i] = (char) tolower(s[i]);
124 int n =
static_cast<int>(s.size());
125 for (i = 0; i < n; i++) {
126 if (s[i] !=
' ' && isprint(s[i])) {
144 int n =
static_cast<int>(s.size());
145 for (i = n-1; i >= 0; i--)
146 if (s[i] !=
' ' && isprint(s[i])) {
166 return s.substr(ifirst, ilast - ifirst + 1);
178 int n =
static_cast<int>(s.size());
180 for (i = 0; i < n; i++) {
211 std::string::size_type icolon, ibegin, iend;
212 std::string name, num, nm;
214 ibegin = s.find_first_not_of(
", ;\n\t");
216 s = s.substr(ibegin,s.size());
217 icolon = s.find(
':');
218 iend = s.find_first_of(
", ;\n\t");
221 name = s.substr(0, icolon);
223 num = s.substr(icolon+1, iend-icolon);
224 s = s.substr(iend+1, s.size());
226 num = s.substr(icolon+1, s.size());
230 if (x.find(nm) == x.end()) {
232 "unknown species " + nm);
234 x[nm] = atof(num.c_str());
251 void split(
const std::string& ss, std::vector<std::string>& w)
254 std::string::size_type ibegin, iend;
255 std::string name, num, nm;
257 ibegin = s.find_first_not_of(
", ;\n\t");
259 s = s.substr(ibegin,s.size());
260 iend = s.find_first_of(
", ;\n\t");
262 w.push_back(s.substr(0, iend));
263 s = s.substr(iend+1, s.size());
265 w.push_back(s.substr(0, s.size()));
273 doublereal*
const a,
const char delim)
275 std::string::size_type iloc;
279 while (s.size() > 0) {
280 iloc = s.find(delim);
282 num = s.substr(0, iloc);
283 s = s.substr(iloc+1,s.size());
304 size_t idot = path.find_last_of(
'.');
305 size_t islash = path.find_last_of(
'/');
306 if (idot > 0 && idot < path.size()) {
307 if (islash > 0 && islash < idot) {
308 file = path.substr(islash+1, idot-islash-1);
310 file = path.substr(0,idot);
320 return std::atoi(
stripws(val).c_str());
325 return std::atof(
stripws(val).c_str());
359 for (
size_t n = 0; n < s.size(); n++) {
365 if (count > len && s[n] ==
' ') {
390 std::string s =
stripws(nameStr);
391 std::string::size_type ibegin, iend, icolon;
393 ibegin = s.find_first_not_of(
" ;\n\t");
395 s = s.substr(ibegin,s.size());
396 icolon = s.find(
':');
397 iend = s.find_first_of(
" ;\n\t");
399 phaseName = s.substr(0, icolon);
400 s = s.substr(icolon+1, s.size());
401 icolon = s.find(
':');
403 throw CanteraError(
"parseSpeciesName()",
"two colons in name: " + nameStr);
408 "Species name has \" ;/\n/\t\" in the middle of it: " + nameStr);
434 const char COM_CHAR=
'\0';
438 if ((str == 0) || (str[0] ==
'\0')) {
443 while (((ch = str[i]) !=
'\0') && isspace(ch)) {
454 while ((ch = str[j+i]) !=
'\0' &&
462 while ((j != -1) && isspace(str[j])) {
497 throw CanteraError(
"atofCheck",
"null pointer to string");
499 char* eptr = (
char*) malloc(strlen(dptr)+1);
503 throw CanteraError(
"atofCheck",
"string has zero length");
510 if (ch ==
'+' || ch ==
'-') {
513 for (
int i = istart; i < ll; i++) {
516 }
else if (ch ==
'.') {
521 "string has more than one .");
523 }
else if (ch ==
'e' || ch ==
'E' || ch ==
'd' || ch ==
'D') {
529 "string has more than one exp char");
532 if (ch ==
'+' || ch ==
'-') {
536 std::string hh(dptr);
539 "Trouble processing string, " + hh);
542 doublereal rval = atof(eptr);
564 std::vector<std::string> v;
568 if (n > 2 || n < 1) {
570 "number of tokens is too high");
574 doublereal val =
atofCheck(v[0].c_str());
590 std::string::const_iterator i = val.begin();
591 for (; i != val.end(); i++) {
595 ibegin = (std::string::size_type) j;
615 std::string::const_iterator i = val.begin();
616 for (; i != val.end(); i++) {
620 ibegin = (std::string::size_type) j;
637 std::vector<std::string>& v)
639 std::string val(oval);
640 std::string::size_type ibegin, iend;
645 val = val.substr(ibegin,val.size());
651 v.push_back(val.substr(0,iend));
652 val = val.substr(iend+1,val.size());