strvector split(string const & text, strvector const & knifes, bool const skipEmpty) { auto result = strvector(); result.reserve(30); if(knifes.empty()) { for(auto& item : text) { result.push_back(string(1, item)); } return result; } auto pos = size_t(0u); auto it = knifes.end(); while(pos != string::npos) { auto next_pos = strfind_of(text, knifes, pos, it); auto item = substrpos(text, pos, next_pos); if(!(item.empty() && skipEmpty)) { result.push_back(item); } if(next_pos != string::npos) { next_pos += it->length(); } pos = next_pos; } return result; }
strvector::const_iterator subfind(string const & text, strvector const & list, size_t const pos) { for(auto it = list.begin(); it != list.end(); it++) { if(subcmp(text, *it, pos)) { return it; } } return list.end(); }
string join(strvector const& list, string const& glue) { auto result = string(); auto it = list.begin(); while(it != list.end()) { result += *it; it++; if(it != list.end()) { result += glue; } } return result; }
void interpret(strvector& data, CTableView* pView) { bool ok = true; for (strvector::const_iterator i = data.begin(), end = data.end(); i != end && ok; ++i) { string s = *i; token_handler handler = find_handler(s); if (handler) ok = (*handler)(i, end, pView); } }
size_t strfind_of(string const & text, strvector const& list, size_t const offset, strvector::const_iterator outIt) { size_t result = string::npos; outIt = list.end(); for(auto it = list.begin(); it < list.end(); it++) { if(it->empty()) continue; auto pos = text.find(*it, offset); if(pos == string::npos) continue; if(result == string::npos || pos < result) { result = pos; outIt = it; } } return result; }
void toVector(redisReply* reply, strvector& vec) { for (unsigned int i = 0; i < reply->elements; i++) { string str(reply->element[i]->str); vec.push_back(str); } freeReplyObject(reply); }
// // If there are spaces in a coordinate entry in the // layout file, then those coordinates will be two // entries in the 'data' vector because a space is // a string separator. // // This function collapses such entries into one to // allow entries like: '13, 5' in the layout file. // void collapse(strvector& data) { strvector tmp; for (strvector::const_iterator i = data.begin(), e = data.end(); i != e; ++i) { string s = *i; int pos = s.find_first_of(','); if (pos == string::npos || pos == (s.size() - 1) && i != e) { ++i; string s2 = *i; s += s2; } tmp.push_back(s); } data = tmp; }