#include "PString.h" #include "Log.h" namespace coreutils { PString::PString() { } PString::PString(std::string pstring) { this->pstring = pstring; } std::vector & PString::getList() { return list; } std::string PString::str() { return pstring.substr(cursor); } std::vector PString::split(std::string delimiter, int maxSize) { list.clear(); if(pstring.size() == 0) { list.push_back(PString("")); return list; } size_t end; size_t pos = cursor; while(pos < pstring.length()) { end = pstring.find(delimiter, pos); if(end == std::string::npos) end = pstring.length(); list.push_back(PString(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(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); } coreutils::PString PString::operator[](int index) { return list[index]; } bool PString::eod() { return cursor >= pstring.size(); } bool PString::ifNext(std::string value) { bool test = (value == pstring.substr(cursor, value.length())); if(test) cursor += value.size(); return test; } int PString::skipWhitespace() { size_t found = pstring.find_first_not_of(" \t", cursor); return found != cursor::npos ? cursor + found: 0; } int PString::size() { return pstring.size() - cursor; } }