Moved a function tokenizeString from ctml to stringUtils.
This commit is contained in:
parent
01ebc586d6
commit
0495a00c88
4 changed files with 85 additions and 78 deletions
|
|
@ -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<string>& 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<std::string>& 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,
|
||||
|
|
|
|||
|
|
@ -374,18 +374,6 @@ namespace ctml {
|
|||
|
||||
void getStringArray(const Cantera::XML_Node& node, std::vector<std::string>& 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<std::string>& v);
|
||||
|
||||
/**
|
||||
* This routine is used to interpret the value portions of XML
|
||||
* elements that contain colon separated pairs. These are used,
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
#include <cctype>
|
||||
#include "ctml.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
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<std::string>& 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<std::string>& v);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue