Developed MString.

This commit is contained in:
Brad Arant committed 2022-03-15 20:07:43 -07:00
1 parent 91286649cc
commit 59228ad356
4 files changed
+195 -13

No files matched your search

+32 -7
View File
@@ -6,9 +6,9 @@ namespace coreutils
std::ostream &operator<<(std::ostream &os, const ZString &zstring)
{
for (int ix = 0; ix < (zstring.length - (zstring.cursor - zstring.data)); ++ix)
for (char *ix = zstring.cursor; ix < (zstring.data + zstring.length); ++ix)
{
os << zstring.cursor[ix];
os << *ix;
}
return os;
}
@@ -53,9 +53,8 @@ namespace coreutils
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(cursor, valuex.cursor, (valuex.length <= length ? valuex.length : length)) < 0);
}
bool ZString::operator>(const ZString &valuex) const
@@ -166,6 +165,10 @@ namespace coreutils
return cursor >= data + length;
}
bool ZString::startsWith(const char *value) {
return strncmp(cursor, value, strlen(value)) == 0;
}
bool ZString::equals(const char *value)
{
if (strlen(value) != length)
@@ -202,6 +205,15 @@ namespace coreutils
return test;
}
bool ZString::ifNext(ZString &value) {
if (((data + length) - cursor) < value.getLength())
return false;
bool test = (strncmp(cursor, value.getCursor(), value.getLength()) == 0);
if (test)
cursor += value.getLength();
return test;
}
int ZString::ifEqualsCount(ZString &comparator)
{
int count = 0;
@@ -223,7 +235,7 @@ namespace coreutils
int ZString::skipWhitespace()
{
int len = strspn(cursor, " \t");
int len = strspn(cursor, " \n\t");
cursor += len;
return len;
}
@@ -264,6 +276,10 @@ namespace coreutils
return data;
}
char *ZString::getCursor() {
return cursor;
}
size_t ZString::getLength()
{
return length - (cursor - data);
@@ -276,6 +292,10 @@ namespace coreutils
cursor = data;
}
ZString ZString::getParsed() {
return ZString(data, cursor - data);
}
void ZString::reset()
{
cursor = data;
@@ -283,7 +303,7 @@ namespace coreutils
char ZString::charAt(int index)
{
return *(data + index);
return *(cursor + index);
}
bool ZString::ifCRLF()
@@ -298,4 +318,9 @@ namespace coreutils
return len != length;
}
void ZString::nextChar() {
if(!eod())
++cursor;
}
}