From 0495a00c88ff49b6590e1c87b44073d86aea97ac Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Sat, 10 Jan 2009 18:26:15 +0000 Subject: [PATCH] Moved a function tokenizeString from ctml to stringUtils. --- Cantera/src/base/ctml.cpp | 67 +------------------------------ Cantera/src/base/ctml.h | 12 ------ Cantera/src/base/stringUtils.cpp | 69 ++++++++++++++++++++++++++++++++ Cantera/src/base/stringUtils.h | 15 +++++++ 4 files changed, 85 insertions(+), 78 deletions(-) diff --git a/Cantera/src/base/ctml.cpp b/Cantera/src/base/ctml.cpp index c0bbebeed..54c713e13 100755 --- a/Cantera/src/base/ctml.cpp +++ b/Cantera/src/base/ctml.cpp @@ -1087,38 +1087,6 @@ namespace ctml { } - static string::size_type findFirstWS(const string& val) { - string::size_type ibegin = string::npos; - int j = 0; - std::string::const_iterator i = val.begin(); - for ( ; i != val.end(); i++) { - char ch = *i; - int ll = (int) ch; - if (isspace(ll)) { - ibegin = (string::size_type) j; - break; - } - j++; - } - return ibegin; - } - - static string::size_type findFirstNotOfWS(const string& val) { - string::size_type ibegin = string::npos; - int j = 0; - std::string::const_iterator i = val.begin(); - for ( ; i != val.end(); i++) { - char ch = *i; - int ll = (int) ch; - if (!isspace(ll)) { - ibegin = (string::size_type) j; - break; - } - j++; - } - return ibegin; - } - /** * This function interprets the value portion of an XML element * as a string. It then separates the string up into tokens @@ -1128,40 +1096,7 @@ namespace ctml { */ void getStringArray(const Cantera::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, - std::vector& v) { - std::string val(oval); - string::size_type ibegin, iend; - v.clear(); - while (1 > 0) { - ibegin = findFirstNotOfWS(val); - //val.find_first_not_of(" \n\t"); - if (ibegin != string::npos) { - val = val.substr(ibegin,val.size()); - //iend = val.find_first_of(" \n\t"); - iend = findFirstWS(val); - if (iend == string::npos) { - v.push_back(val); - break; - } else { - v.push_back(val.substr(0,iend)); - val = val.substr(iend+1,val.size()); - } - } - else { - break; - } - } + tokenizeString(val, v); } void getFunction(const Cantera::XML_Node& node, string& type, doublereal& xmin, diff --git a/Cantera/src/base/ctml.h b/Cantera/src/base/ctml.h index 93eecf757..f4ddb1e0d 100755 --- a/Cantera/src/base/ctml.h +++ b/Cantera/src/base/ctml.h @@ -374,18 +374,6 @@ namespace ctml { void getStringArray(const Cantera::XML_Node& node, std::vector& v); - - - //! This function separates a string up into tokens - //! according to the location of white space. - /*! - * The separate tokens are returned in a string vector, v. - * - * @param val String to be broken up - * @param v Output vector of tokens. - */ - void getStringArray(const std::string& val, std::vector& v); - /** * This routine is used to interpret the value portions of XML * elements that contain colon separated pairs. These are used, diff --git a/Cantera/src/base/stringUtils.cpp b/Cantera/src/base/stringUtils.cpp index f5af9025e..492ffe3f7 100755 --- a/Cantera/src/base/stringUtils.cpp +++ b/Cantera/src/base/stringUtils.cpp @@ -26,6 +26,8 @@ #include #include "ctml.h" +#include + namespace Cantera { @@ -418,4 +420,71 @@ namespace Cantera { doublereal val = atofCheck(v[0].c_str()); return (val * fp); } + + static std::string::size_type findFirstWS(const std::string& val) { + std::string::size_type ibegin = std::string::npos; + int j = 0; + std::string::const_iterator i = val.begin(); + for ( ; i != val.end(); i++) { + char ch = *i; + int ll = (int) ch; + if (isspace(ll)) { + ibegin = (std::string::size_type) j; + break; + } + j++; + } + return ibegin; + } + + static std::string::size_type findFirstNotOfWS(const std::string& val) { + std::string::size_type ibegin = std::string::npos; + int j = 0; + std::string::const_iterator i = val.begin(); + for ( ; i != val.end(); i++) { + char ch = *i; + int ll = (int) ch; + if (!isspace(ll)) { + ibegin = (std::string::size_type) j; + break; + } + j++; + } + return ibegin; + } + + // This function separates a string up into tokens + // according to the location of white space. + /* + * The separate tokens are returned in a string vector, v. + * + * @param oval String to be broken up + * @param v Output vector of tokens. + */ + void tokenizeString(const std::string& oval, + std::vector& v) { + std::string val(oval); + std::string::size_type ibegin, iend; + v.clear(); + while (1 > 0) { + ibegin = findFirstNotOfWS(val); + if (ibegin != std::string::npos) { + val = val.substr(ibegin,val.size()); + //iend = val.find_first_of(" \n\t"); + iend = findFirstWS(val); + if (iend == std::string::npos) { + v.push_back(val); + break; + } else { + v.push_back(val.substr(0,iend)); + val = val.substr(iend+1,val.size()); + } + } + else { + break; + } + } + } + + } diff --git a/Cantera/src/base/stringUtils.h b/Cantera/src/base/stringUtils.h index b502b9a5f..07fe29ffd 100755 --- a/Cantera/src/base/stringUtils.h +++ b/Cantera/src/base/stringUtils.h @@ -78,6 +78,21 @@ namespace Cantera { double atofCheck(const char *dptr); doublereal strSItoDbl(const std::string& strSI); + + //! This function separates a string up into tokens + //! according to the location of white space. + /*! + * White space includes the new line character. tokens + * are stripped of leading and trailing white space. + * + * The separate tokens are returned in a string vector, v. + * + * @param oval String to be broken up + * @param v Output vector of tokens. + */ + void tokenizeString(const std::string& oval, + std::vector& v); + } #endif