diff --git a/ZString.cpp b/ZString.cpp index dc21d06..81c5c9f 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -68,6 +68,10 @@ namespace coreutils { return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) == 0); } + bool ZString::operator==(const char *valuex) const { + return (strncmp(data, valuex, length) == 0); + } + bool ZString::operator!=(const ZString &valuex) const { // if(length != valuex.getLength()) // return false; @@ -75,9 +79,8 @@ namespace coreutils { } bool ZString::operator!=(const char *valuex) const { - size_t len = strlen(valuex); - if(length != len) - return true; + if(strlen(valuex) != length) + return true; return (strncmp(data, valuex, length) != 0); } @@ -124,6 +127,19 @@ namespace coreutils { cdata[length] = '\0'; return cdata; } + + ZString ZString::substring(int start) { + char *end = data + length; + char *startChar = data + start; + if(startChar < end) { + return ZString(startChar, end - startChar); + } + return ZString(); + } + + ZString ZString::substring(int start, int len) { + return ZString(); + } std::vector &ZString::split(std::string delimiter, size_t maxSize) { coreutils::ZString zDelimiter((char *)delimiter.c_str(), delimiter.size()); diff --git a/ZString.h b/ZString.h index 3987b4c..b7790e7 100644 --- a/ZString.h +++ b/ZString.h @@ -42,7 +42,7 @@ namespace coreutils { ZString(); /// - /// + /// Constructor wrapping a null terminated buffer to a ZString. /// ZString(const char *data); @@ -53,6 +53,10 @@ namespace coreutils { ZString(char *data, size_t length); + /// + /// + /// + ZString(const char *data, size_t length); /// @@ -74,8 +78,8 @@ namespace coreutils { ~ZString(); /// - /// A friend method used to write the value of the ZString from the cursor - /// point to an ostream using the << syntax. + /// A friend method used to write the value of the ZString + /// to an ostream using the << syntax. /// friend std::ostream& operator<<(std::ostream& os, const ZString& zstring); @@ -83,9 +87,19 @@ namespace coreutils { friend std::ostream& operator+(std::ostream& os, const ZString& zstring); friend std::ostream& operator+(std::ostream& os, const char *value); + /// + /// + /// + bool operator<(const ZString &valuex) const; + + /// + /// + /// + bool operator>(const ZString &valuex) const; bool operator==(const ZString &valuex) const; + bool operator==(const char *valuex) const; bool operator!=(const ZString &valuex) const; bool operator!=(const char *valuex) const; @@ -146,6 +160,18 @@ namespace coreutils { /// /// + ZString substring(int start); + + /// + /// + /// + + ZString substring(int start, int len); + + /// + /// + /// + std::vector &split(ZString &delimiter, size_t maxSize = 0); /// @@ -168,6 +194,10 @@ namespace coreutils { ZString getTokenExclude(const char *exclude); + /// + /// + /// + ZString getTokenExclude(std::string exclude); /// @@ -219,8 +249,16 @@ namespace coreutils { bool ifNext(const char *value); + /// + /// + /// + bool ifNext(ZString &value); + /// + /// + /// + int ifEqualsCount(ZString &comparator); /// @@ -255,6 +293,10 @@ namespace coreutils { char* getCursor(); + /// + /// + /// + void setCursor(char *cursor); /// diff --git a/testing/mstring_test b/testing/mstring_test index c42765e..01f0d21 100755 Binary files a/testing/mstring_test and b/testing/mstring_test differ diff --git a/testing/zstring_test b/testing/zstring_test index d84faa0..5d13824 100755 Binary files a/testing/zstring_test and b/testing/zstring_test differ diff --git a/testing/zstring_test.cpp b/testing/zstring_test.cpp index 5cacf58..e18dd76 100644 --- a/testing/zstring_test.cpp +++ b/testing/zstring_test.cpp @@ -22,4 +22,9 @@ int main(int argc, char **argv) { for(int ix = 0; ix < test.getList().size(); ++ix) std::cout << ix << ":" << test[ix] << std::endl; + // Test substring operations. + + coreutils::ZString test2("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + std::cout << "substring: [" << test2.substring(10) << "]" << std::endl; + }