Its working!!!
This commit is contained in:
1 parent
a3ba545c59
commit
1632a41b3e
5 files changed
+67
-59
No files matched your search
+45
-35
@@ -4,7 +4,9 @@
|
||||
namespace coreutils {
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const ZString &zstring) {
|
||||
os << zstring;
|
||||
for(int ix = 0; ix < zstring.length; ++ix) {
|
||||
os << zstring.data[ix];
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -24,28 +26,30 @@ namespace coreutils {
|
||||
cursor = data;
|
||||
}
|
||||
|
||||
ZString::ZString(const ZString&) {}
|
||||
ZString::ZString(const char *data) : data((char *)data), length(strlen(data)), cursor((char *)data) {}
|
||||
|
||||
ZString::ZString(const char *data) : data((char *)data), length(strlen(data)), cursor((char *)data) {}
|
||||
|
||||
ZString::ZString(char *data, size_t length) : data(data), length(length), cursor(data) {}
|
||||
|
||||
ZString::ZString(ZString &zstring) {
|
||||
data = zstring.getData();
|
||||
length = zstring.getLength();
|
||||
}
|
||||
|
||||
std::vector<ZString> & ZString::getList() {
|
||||
ZString::ZString(const char *data, size_t length) : data((char *)data), length(length), cursor((char *)data) {}
|
||||
|
||||
ZString::ZString(const ZString &zstring) {
|
||||
data = zstring.data;
|
||||
length = zstring.length;
|
||||
cursor = zstring.cursor;
|
||||
Log(LOG_DEBUG_2) << "ZSrting Copy Constructor: ";
|
||||
}
|
||||
|
||||
std::vector<ZString> &ZString::getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
int ZString::asInteger() {
|
||||
int ZString::asInteger() {
|
||||
std::stringstream temp(std::string(data, length));
|
||||
int tempInt = 0;
|
||||
temp >> tempInt;
|
||||
return tempInt;
|
||||
}
|
||||
|
||||
|
||||
std::string ZString::str() {
|
||||
return std::string(data, length);
|
||||
}
|
||||
@@ -54,49 +58,55 @@ namespace coreutils {
|
||||
return std::string(data, len);
|
||||
}
|
||||
|
||||
std::vector<ZString> ZString::split(std::string &delimiter, size_t maxSize) {
|
||||
return split(ZString(delimiter.c_str()), maxSize);
|
||||
}
|
||||
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) {
|
||||
std::vector<ZString> &ZString::split(ZString &delimiter, size_t maxSize) {
|
||||
list.clear();
|
||||
if(length == 0) {
|
||||
list.push_back(ZString((char *)""));
|
||||
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;
|
||||
}
|
||||
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;
|
||||
return list;
|
||||
}
|
||||
|
||||
ZString ZString::getTokenInclude(char *include) {
|
||||
|
||||
ZString ZString::getTokenInclude(const char *include) {
|
||||
char *start = cursor;
|
||||
int len = strcspn(cursor, include);
|
||||
cursor += len;
|
||||
return ZString(start, len);
|
||||
}
|
||||
|
||||
ZString ZString::getTokenExclude(char *exclude) {
|
||||
|
||||
ZString ZString::getTokenExclude(const char *exclude) {
|
||||
char *start = cursor;
|
||||
int len = strspn(cursor, exclude);
|
||||
cursor += len;
|
||||
return ZString(start, len);
|
||||
}
|
||||
|
||||
ZString ZString::operator[](int index) {
|
||||
|
||||
ZString ZString::getTokenExclude(std::string exclude) {
|
||||
return getTokenExclude(exclude.c_str());
|
||||
}
|
||||
|
||||
ZString &ZString::operator[](int index) {
|
||||
return list[index];
|
||||
}
|
||||
|
||||
@@ -108,14 +118,14 @@ namespace coreutils {
|
||||
return strncmp(data, value, length) == 0;
|
||||
}
|
||||
|
||||
bool ZString::equals(ZString zstring) {
|
||||
bool ZString::equals(ZString &zstring) {
|
||||
if(zstring.getLength() != getLength())
|
||||
return false;
|
||||
return strncmp(data, zstring.getData(), getLength()) == 0;
|
||||
}
|
||||
|
||||
bool ZString::equals(std::string string) {
|
||||
return strncmp(string.c_str(), getData(), getLength()) == 0;
|
||||
bool ZString::equals(std::string &string) {
|
||||
return string == std::string(data, length);
|
||||
}
|
||||
|
||||
bool ZString::ifNext(char *value) {
|
||||
|
||||
Reference in new issue
Block a user