Added substring capability to ZString.

This commit is contained in:
Brad Arant 2022-08-07 17:21:37 -07:00
parent 36348aba17
commit d0d5172afa
5 changed files with 69 additions and 6 deletions

View File

@ -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> &ZString::split(std::string delimiter, size_t maxSize) {
coreutils::ZString zDelimiter((char *)delimiter.c_str(), delimiter.size());

View File

@ -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<ZString> &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);
///

Binary file not shown.

Binary file not shown.

View File

@ -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;
}