diff --git a/Cantera/src/base/ctml.cpp b/Cantera/src/base/ctml.cpp index 13c7b8adb..c5c9d3596 100755 --- a/Cantera/src/base/ctml.cpp +++ b/Cantera/src/base/ctml.cpp @@ -618,9 +618,21 @@ namespace ctml { * v. */ void getStringArray(const XML_Node& node, vector& v) { + string val = node.value(); + getStringArray(val, v); + } + + /** + * This function interprets the value portion of an XML element + * as a string. It then separates the string up into tokens + * according to the location of white space. + * The separate tokens are returned in the string vector, + * v. + */ + void getStringArray(const std::string& oval, vector& v) { + std::string val(oval); string::size_type ibegin, iend; v.clear(); - string val = node.value(); while (1 > 0) { ibegin = findFirstNotOfWS(val); //val.find_first_not_of(" \n\t"); @@ -640,10 +652,8 @@ namespace ctml { break; } } - } - void getFunction(const XML_Node& node, string& type, doublereal& xmin, doublereal& xmax, vector_fp& coeffs) { const XML_Node& c = node.child("floatArray"); diff --git a/Cantera/src/base/ctml.h b/Cantera/src/base/ctml.h index b5e49eef0..0ee3b80dd 100755 --- a/Cantera/src/base/ctml.h +++ b/Cantera/src/base/ctml.h @@ -74,6 +74,7 @@ namespace ctml { std::string nodeName = "floatArray"); void getStringArray(const Cantera::XML_Node& node, std::vector& v); + void getStringArray(const std::string& val, std::vector& v); void getMap(const Cantera::XML_Node& node, std::map& m); void getPairs(const Cantera::XML_Node& node, std::vector& key, std::vector& val); diff --git a/Cantera/src/base/stringUtils.cpp b/Cantera/src/base/stringUtils.cpp index a19ace6fa..98c7b3789 100755 --- a/Cantera/src/base/stringUtils.cpp +++ b/Cantera/src/base/stringUtils.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include "ctml.h" namespace Cantera { @@ -72,7 +74,7 @@ namespace Cantera { return std::string(" "); } - std::string lowercase(std::string s) { + std::string lowercase(const std::string &s) { int n = static_cast(s.size()); std::string lc(s); for (int i = 0; i < n; i++) lc[i] = tolower(s[i]); @@ -394,4 +396,19 @@ namespace Cantera { return rval; } + + doublereal strSItoDbl(const std::string& strSI) { + std::vector v; + ctml::getStringArray(strSI, v); + doublereal fp = 1.0; + int n = v.size(); + if (n > 2 || n < 1) { + throw CanteraError("strSItoDbl", + "number of tokens is too high"); + } else if (n == 2) { + fp = toSI(v[1]); + } + doublereal val = atofCheck(v[0].c_str()); + return (val * fp); + } } diff --git a/Cantera/src/base/stringUtils.h b/Cantera/src/base/stringUtils.h index 21a50b51c..73657202b 100755 --- a/Cantera/src/base/stringUtils.h +++ b/Cantera/src/base/stringUtils.h @@ -31,7 +31,7 @@ namespace Cantera { std::string int2str(int n); std::string stripws(std::string s); std::string stripnonprint(std::string s); - std::string lowercase(std::string s); + std::string lowercase(const std::string &s); void parseCompString(const std::string ss, compositionMap& x); void split(const std::string ss, std::vector& w); int fillArrayFromString(const std::string& str, doublereal* a, char delim = ' '); @@ -66,6 +66,7 @@ namespace Cantera { int stripLTWScstring(char str[]); double atofCheck(const char *dptr); + doublereal strSItoDbl(const std::string& strSI); }