Added testing function for ZString.

This commit is contained in:
Brad Arant committed 2021-09-22 18:01:54 -07:00
1 parent 191899fbb7
commit a0129273b3
8 files changed
+99 -70

No files matched your search

+28 -28
View File
@@ -36,7 +36,7 @@ namespace coreutils {
data = zstring.data;
length = zstring.length;
cursor = zstring.cursor;
// Log(LOG_DEBUG_2) << "ZSrting Copy Constructor: ";
// Log(LOG_DEBUG_2) << "ZString Copy Constructor: ";
}
std::vector<ZString> &ZString::getList() {
@@ -49,93 +49,93 @@ namespace coreutils {
temp >> tempInt;
return tempInt;
}
std::string ZString::str() {
return std::string(data, length);
}
std::string ZString::str(int len) {
return std::string(data, len);
}
std::vector<ZString> &ZString::split(std::string delimiter, size_t maxSize) {
coreutils::ZString zDelimiter((char *)delimiter.c_str(), delimiter.size());
return split(zDelimiter, maxSize);
}
std::vector<ZString> &ZString::split(ZString &delimiter, size_t maxSize) {
list.clear();
if(length == 0) {
list.push_back(ZString((char *)""));
list.push_back(ZString(""));
return list;
}
char *end = data + length;
char *pos = cursor;
while(pos < end) {
if(strncmp(pos, delimiter.getData(), delimiter.getLength()) == 0) {
list.push_back(ZString(cursor, pos - cursor));
cursor = pos + delimiter.getLength();
pos = cursor;
}
else {
++pos;
}
list.push_back(ZString(cursor, pos - cursor));
cursor = pos + delimiter.getLength();
pos = cursor;
}
else {
++pos;
}
}
list.push_back(ZString(cursor, pos - cursor));
cursor = pos;
return list;
}
ZString ZString::getTokenInclude(const char *include) {
char *start = cursor;
int len = strcspn(cursor, include);
cursor += len;
return ZString(start, len);
}
ZString ZString::getTokenExclude(const char *exclude) {
char *start = cursor;
int len = strspn(cursor, exclude);
cursor += len;
return ZString(start, len);
}
ZString ZString::getTokenExclude(std::string exclude) {
return getTokenExclude(exclude.c_str());
}
ZString &ZString::operator[](int index) {
return list[index];
}
bool ZString::eod() {
return cursor >= data + length;
}
bool ZString::equals(const char *value) {
if(strlen(value) != length)
return false;
return strncmp(data, value, length) == 0;
}
bool ZString::equals(char *value) {
if(strlen(value) != length)
return false;
return strncmp(data, value, length) == 0;
}
bool ZString::equals(ZString &zstring) {
if(zstring.getLength() != getLength())
return false;
return false;
return strncmp(data, zstring.getData(), getLength()) == 0;
}
bool ZString::equals(std::string &string) {
return string == std::string(data, length);
}
bool ZString::ifNext(const char *value) {
bool test = (strncmp(cursor, value, strlen(value)) == 0);
if(test)
@@ -168,11 +168,11 @@ namespace coreutils {
size_t ZString::getLength() {
return length;
}
void ZString::setZString(ZString zstring) {
data = zstring.getData();
length = zstring.getLength();
cursor = data;
}
}
}