#include "PString.h" #include "Log.h" namespace coreutils { PString::PString() { } PString::PString(std::string pstring) { this->pstring = pstring; } std::string PString::str() { return pstring.substr(cursor); } std::vector PString::split(std::string delimiter, int maxSize) { std::vector list; size_t end, pos = cursor; while(pos < pstring.length()) { end = pstring.find(delimiter, pos); if(end == std::string::npos) end = pstring.length(); list.push_back(pstring.substr(pos, end - pos)); pos = end + delimiter.size(); if(pos > pstring.size()) break; if(maxSize != 0) { if(list.size() >= maxSize) { list.push_back(pstring.substr(pos)); break; } } } return list; } std::string PString::getTokenInclude(std::string include) { int start = cursor; cursor = pstring.find_first_not_of(include, cursor); return pstring.substr(start, cursor - start); } std::string PString::getTokenExclude(std::string exclude) { int start = cursor; cursor = pstring.find_first_of(exclude, cursor); if(cursor == -1) cursor = pstring.size(); return pstring.substr(start, cursor - start); } bool PString::ifNext(std::string value) { bool test = (value == pstring.substr(cursor, value.length())); if(test) cursor += value.size(); return test; } void PString::skipWhitespace() { cursor = pstring.find_first_not_of(" \t", cursor); } }