87 lines
2.1 KiB
C++
87 lines
2.1 KiB
C++
#include "PString.h"
|
|
#include "Log.h"
|
|
|
|
namespace coreutils {
|
|
|
|
PString::PString() {
|
|
}
|
|
|
|
PString::PString(std::string pstring) {
|
|
this->pstring = pstring;
|
|
}
|
|
|
|
std::vector<PString> & PString::getList() {
|
|
return list;
|
|
}
|
|
|
|
std::string PString::str() {
|
|
return pstring.substr(cursor);
|
|
}
|
|
|
|
std::vector<PString> 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;
|
|
}
|
|
|
|
void PString::skipWhitespace() {
|
|
cursor = pstring.find_first_not_of(" \t", cursor);
|
|
}
|
|
|
|
int PString::size() {
|
|
return pstring.size() - cursor;
|
|
}
|
|
|
|
} |