std::vector<std::string> TDDHelper::splitString(const std::string& text, const char delim, const int numToken) { std::stringstream ss(text); std::string item; std::string lastToken(""); std::vector<std::string> tokens; int count = 0; const char delimStr[2] = {delim, '\0'}; // make const char for later use while (std::getline(ss, item, delim)) { if (numToken <= 0 || count < (numToken - 1)) { // cond1: don't bound the token tokens.push_back(item); // cond2: } else { if(lastToken.length() == 0) { lastToken.append(delimStr); } lastToken.append(item); } } tokens.push_back(lastToken); return tokens; }
void Foam::IOPosition<ParticleType>::readData ( Cloud<ParticleType>& c, bool checkClass ) { Istream& is = readStream(checkClass ? typeName : ""); token firstToken(is); if (firstToken.isLabel()) { label s = firstToken.labelToken(); // Read beginning of contents is.readBeginList("Cloud<ParticleType>"); for (label i=0; i<s; i++) { // Do not read any fields, position only c.append(new ParticleType(c, is, false)); } // Read end of contents is.readEndList("Cloud<ParticleType>"); } else if (firstToken.isPunctuation()) { if (firstToken.pToken() != token::BEGIN_LIST) { FatalIOErrorIn ( "void IOPosition<ParticleType>::readData" "(Cloud<ParticleType>&, bool)", is ) << "incorrect first token, '(', found " << firstToken.info() << exit(FatalIOError); } token lastToken(is); while ( !( lastToken.isPunctuation() && lastToken.pToken() == token::END_LIST ) ) { is.putBack(lastToken); // Do not read any fields, position only c.append(new ParticleType(c, is, false)); is >> lastToken; } } else {
void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew) { is.fatalCheck ( "LPtrList<LListBase, T>::read(Istream&, const INew&)" ); token firstToken(is); is.fatalCheck ( "LPtrList<LListBase, T>::read(Istream&, const INew&) : " "reading first token" ); if (firstToken.isLabel()) { label s = firstToken.labelToken(); // Read beginning of contents char delimiter = is.readBeginList("LPtrList<LListBase, T>"); if (s) { if (delimiter == token::BEGIN_LIST) { for (label i=0; i<s; ++i) { this->append(iNew(is).ptr()); is.fatalCheck ( "LPtrList<LListBase, T>::read(Istream&, const INew&) : " "reading entry" ); } } else { T* tPtr = iNew(is).ptr(); this->append(tPtr); is.fatalCheck ( "LPtrList<LListBase, T>::read(Istream&, const INew&) : " "reading entry" ); for (label i=1; i<s; ++i) { this->append(tPtr->clone().ptr()); } } } // Read end of contents is.readEndList("LPtrList<LListBase, T>"); } else if (firstToken.isPunctuation()) { if (firstToken.pToken() != token::BEGIN_LIST) { FatalIOErrorIn ( "LPtrList<LListBase, T>::read(Istream&, const INew&)", is ) << "incorrect first token, '(', found " << firstToken.info() << exit(FatalIOError); } token lastToken(is); is.fatalCheck("LPtrList<LListBase, T>::read(Istream&, const INew&)"); while ( !( lastToken.isPunctuation() && lastToken.pToken() == token::END_LIST ) ) { is.putBack(lastToken); this->append(iNew(is).ptr()); is >> lastToken; is.fatalCheck ( "LPtrList<LListBase, T>::read(Istream&, const INew&)" ); } } else {