Updated and working.
This commit is contained in:
1 parent
d4148b0ab4
commit
a37c4e6829
30 files changed
+422
-226
No files matched your search
+128
-50
@@ -4,8 +4,8 @@
|
||||
namespace coreutils {
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const ZString &zstring) {
|
||||
for(int ix = 0; ix < zstring.length; ++ix) {
|
||||
os << zstring.data[ix];
|
||||
for(int ix = 0; ix < (zstring.length - (zstring.cursor - zstring.data)); ++ix) {
|
||||
os << zstring.cursor[ix];
|
||||
}
|
||||
return os;
|
||||
}
|
||||
@@ -39,6 +39,24 @@ namespace coreutils {
|
||||
// Log(LOG_DEBUG_2) << "ZString Copy Constructor: ";
|
||||
}
|
||||
|
||||
ZString::ZString(std::string data) {
|
||||
this->data = (char *)data.c_str();
|
||||
length = data.length();
|
||||
cursor = (char *)data.c_str();
|
||||
}
|
||||
|
||||
bool ZString::operator<(const ZString &valuex) const {
|
||||
return (strncmp(cursor, valuex.cursor, (valuex.length <= length ? valuex.length: length) < 0));
|
||||
}
|
||||
|
||||
bool ZString::operator>(const ZString &valuex) const {
|
||||
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length: length) > 0);
|
||||
}
|
||||
|
||||
bool ZString::operator==(const ZString &valuex) const {
|
||||
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length: length) == 0);
|
||||
}
|
||||
|
||||
std::vector<ZString> &ZString::getList() {
|
||||
return list;
|
||||
}
|
||||
@@ -49,130 +67,190 @@ 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(""));
|
||||
return list;
|
||||
list.push_back(ZString(""));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
char *end = data + length;
|
||||
char *pos = cursor;
|
||||
|
||||
while(pos < end) {
|
||||
while((pos + delimiter.getLength()) < 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;
|
||||
}
|
||||
}
|
||||
pos += delimiter.getLength();
|
||||
list.push_back(ZString(cursor, pos - cursor));
|
||||
cursor = pos;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
bool ZString::isCharacter(char ch, const char *string) {
|
||||
int len = strlen(string);
|
||||
for(int ix = 0; ix < len; ++ix) {
|
||||
if(ch == string[ix])
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ZString ZString::getTokenInclude(const char *include) {
|
||||
char *start = cursor;
|
||||
int len = strcspn(cursor, include);
|
||||
cursor += len;
|
||||
return ZString(start, len);
|
||||
while((cursor <= (data + length)) && isCharacter(*cursor, include))
|
||||
++cursor;
|
||||
return ZString(start, cursor - start);
|
||||
}
|
||||
|
||||
|
||||
ZString ZString::getTokenExclude(const char *exclude) {
|
||||
char *start = cursor;
|
||||
int len = strspn(cursor, exclude);
|
||||
cursor += len;
|
||||
return ZString(start, len);
|
||||
while((cursor <= (data + length)) && !isCharacter(*cursor, exclude))
|
||||
++cursor;
|
||||
return ZString(start, cursor - start);
|
||||
}
|
||||
|
||||
|
||||
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 strncmp(data, zstring.getData(), getLength()) == 0;
|
||||
if(zstring.getLength() != length)
|
||||
return false;
|
||||
return strncmp(data, zstring.getData(), length) == 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(((data + length) - cursor) < strlen(value))
|
||||
return false;
|
||||
bool test = (strncmp(cursor, value, strlen(value)) == 0);
|
||||
if(test)
|
||||
cursor += strlen(value);
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
int ZString::ifEqualsCount(ZString &comparator) {
|
||||
int count = 0;
|
||||
while(cursor < (data + length)) {
|
||||
if(*cursor == *comparator.cursor) {
|
||||
++count;
|
||||
++cursor;
|
||||
++comparator.cursor;
|
||||
}
|
||||
else {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int ZString::skipWhitespace() {
|
||||
int len = strspn(cursor, " \t");
|
||||
cursor += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
ZString ZString::goeol() {
|
||||
char* temp = cursor;
|
||||
cursor += strspn(cursor, "\r\n");
|
||||
return ZString(temp, cursor-- - temp);
|
||||
bool set = false;
|
||||
char *temp = cursor;
|
||||
char *tempend = data + length;
|
||||
while(cursor <= (data + length)) {
|
||||
if(*cursor == '\r') {
|
||||
tempend = cursor++;
|
||||
set = true;
|
||||
}
|
||||
if(*cursor == '\n') {
|
||||
if(!set)
|
||||
tempend = cursor;
|
||||
++cursor;
|
||||
break;
|
||||
}
|
||||
++cursor;
|
||||
}
|
||||
return ZString(temp, tempend - temp);
|
||||
}
|
||||
|
||||
|
||||
ZString ZString::readBlock(size_t size) {
|
||||
char *temp = cursor;
|
||||
cursor += size;
|
||||
return ZString(temp, size);
|
||||
}
|
||||
|
||||
|
||||
char* ZString::getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
size_t ZString::getLength() {
|
||||
return length;
|
||||
return length - (cursor - data);
|
||||
}
|
||||
|
||||
|
||||
void ZString::setZString(ZString zstring) {
|
||||
data = zstring.getData();
|
||||
length = zstring.getLength();
|
||||
length = zstring.getLength();
|
||||
cursor = data;
|
||||
}
|
||||
|
||||
|
||||
void ZString::reset() {
|
||||
cursor = data;
|
||||
}
|
||||
|
||||
char ZString::charAt(int index) {
|
||||
return *(data + index);
|
||||
}
|
||||
|
||||
bool ZString::ifCRLF() {
|
||||
int len = length;
|
||||
if(*(data + length - 1) == '\n')
|
||||
--length;
|
||||
if(*(data + length - 1) == '\r')
|
||||
--length;
|
||||
if(cursor > (data + length))
|
||||
cursor = data + length;
|
||||
return len != length;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user