Added substring capability to ZString.
This commit is contained in:
parent
36348aba17
commit
d0d5172afa
22
ZString.cpp
22
ZString.cpp
@ -68,6 +68,10 @@ namespace coreutils {
|
|||||||
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) == 0);
|
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 {
|
bool ZString::operator!=(const ZString &valuex) const {
|
||||||
// if(length != valuex.getLength())
|
// if(length != valuex.getLength())
|
||||||
// return false;
|
// return false;
|
||||||
@ -75,9 +79,8 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::operator!=(const char *valuex) const {
|
bool ZString::operator!=(const char *valuex) const {
|
||||||
size_t len = strlen(valuex);
|
if(strlen(valuex) != length)
|
||||||
if(length != len)
|
return true;
|
||||||
return true;
|
|
||||||
return (strncmp(data, valuex, length) != 0);
|
return (strncmp(data, valuex, length) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +128,19 @@ namespace coreutils {
|
|||||||
return cdata;
|
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) {
|
std::vector<ZString> &ZString::split(std::string delimiter, size_t maxSize) {
|
||||||
coreutils::ZString zDelimiter((char *)delimiter.c_str(), delimiter.size());
|
coreutils::ZString zDelimiter((char *)delimiter.c_str(), delimiter.size());
|
||||||
return split(zDelimiter, maxSize);
|
return split(zDelimiter, maxSize);
|
||||||
|
48
ZString.h
48
ZString.h
@ -42,7 +42,7 @@ namespace coreutils {
|
|||||||
ZString();
|
ZString();
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
/// Constructor wrapping a null terminated buffer to a ZString.
|
||||||
///
|
///
|
||||||
|
|
||||||
ZString(const char *data);
|
ZString(const char *data);
|
||||||
@ -53,6 +53,10 @@ namespace coreutils {
|
|||||||
|
|
||||||
ZString(char *data, size_t length);
|
ZString(char *data, size_t length);
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
ZString(const char *data, size_t length);
|
ZString(const char *data, size_t length);
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -74,8 +78,8 @@ namespace coreutils {
|
|||||||
~ZString();
|
~ZString();
|
||||||
|
|
||||||
///
|
///
|
||||||
/// A friend method used to write the value of the ZString from the cursor
|
/// A friend method used to write the value of the ZString
|
||||||
/// point to an ostream using the << syntax.
|
/// to an ostream using the << syntax.
|
||||||
///
|
///
|
||||||
|
|
||||||
friend std::ostream& operator<<(std::ostream& os, const ZString& zstring);
|
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 ZString& zstring);
|
||||||
friend std::ostream& operator+(std::ostream& os, const char *value);
|
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 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 ZString &valuex) const;
|
||||||
bool operator!=(const char *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);
|
std::vector<ZString> &split(ZString &delimiter, size_t maxSize = 0);
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -168,6 +194,10 @@ namespace coreutils {
|
|||||||
|
|
||||||
ZString getTokenExclude(const char *exclude);
|
ZString getTokenExclude(const char *exclude);
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
ZString getTokenExclude(std::string exclude);
|
ZString getTokenExclude(std::string exclude);
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -219,8 +249,16 @@ namespace coreutils {
|
|||||||
|
|
||||||
bool ifNext(const char *value);
|
bool ifNext(const char *value);
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
bool ifNext(ZString &value);
|
bool ifNext(ZString &value);
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
int ifEqualsCount(ZString &comparator);
|
int ifEqualsCount(ZString &comparator);
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -255,6 +293,10 @@ namespace coreutils {
|
|||||||
|
|
||||||
char* getCursor();
|
char* getCursor();
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
void setCursor(char *cursor);
|
void setCursor(char *cursor);
|
||||||
|
|
||||||
///
|
///
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -22,4 +22,9 @@ int main(int argc, char **argv) {
|
|||||||
for(int ix = 0; ix < test.getList().size(); ++ix)
|
for(int ix = 0; ix < test.getList().size(); ++ix)
|
||||||
std::cout << ix << ":" << test[ix] << std::endl;
|
std::cout << ix << ":" << test[ix] << std::endl;
|
||||||
|
|
||||||
|
// Test substring operations.
|
||||||
|
|
||||||
|
coreutils::ZString test2("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
|
std::cout << "substring: [" << test2.substring(10) << "]" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user