68 lines
1.7 KiB
C++
68 lines
1.7 KiB
C++
#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> PString::split(std::string delimiter, int maxSize) {
|
|
std::vector<PString> 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(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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
int PString::size() {
|
|
return pstring.size() - cursor;
|
|
}
|
|
|
|
} |