Added != operator functions.
This commit is contained in:
parent
d8df083d6b
commit
d2f13c192c
120
ZString.cpp
120
ZString.cpp
@ -55,23 +55,28 @@ namespace coreutils {
|
|||||||
return (strncmp(cursor, valuex.cursor, (valuex.length <= length ? valuex.length : length)) < 0);
|
return (strncmp(cursor, valuex.cursor, (valuex.length <= length ? valuex.length : length)) < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::operator>(const ZString &valuex) const
|
bool ZString::operator>(const ZString &valuex) const {
|
||||||
{
|
|
||||||
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 ZString &valuex) const
|
bool ZString::operator==(const ZString &valuex) const {
|
||||||
{
|
|
||||||
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) == 0);
|
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ZString> &ZString::getList()
|
bool ZString::operator!=(const ZString &valuex) const {
|
||||||
{
|
return (strncmp(data, valuex.data, valuex.length <= length ? valuex.length : length) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ZString::operator!=(const char *valuex) const {
|
||||||
|
size_t len = strlen(valuex);
|
||||||
|
return (strncmp(data, valuex, len <= length ? len : length) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ZString> &ZString::getList() {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZString::asInteger()
|
int ZString::asInteger() {
|
||||||
{
|
|
||||||
std::stringstream temp(std::string(data, length));
|
std::stringstream temp(std::string(data, length));
|
||||||
int tempInt = 0;
|
int tempInt = 0;
|
||||||
temp >> tempInt;
|
temp >> tempInt;
|
||||||
@ -96,13 +101,11 @@ namespace coreutils {
|
|||||||
stack.pop();
|
stack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ZString::str()
|
std::string ZString::str() {
|
||||||
{
|
|
||||||
return std::string(data, length);
|
return std::string(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ZString::str(int len)
|
std::string ZString::str(int len) {
|
||||||
{
|
|
||||||
return std::string(data, len);
|
return std::string(data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,8 +116,7 @@ namespace coreutils {
|
|||||||
return cdata;
|
return cdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -129,15 +131,13 @@ namespace coreutils {
|
|||||||
char *end = data + length;
|
char *end = data + length;
|
||||||
char *pos = cursor;
|
char *pos = cursor;
|
||||||
while ((pos + delimiter.getLength()) <= end) {
|
while ((pos + delimiter.getLength()) <= end) {
|
||||||
if ((strncmp(pos, delimiter.getData(), delimiter.getLength()) == 0) && (maxSize != 0))
|
if ((strncmp(pos, delimiter.getData(), delimiter.getLength()) == 0) && (maxSize != 0)) {
|
||||||
{
|
|
||||||
list.push_back(ZString(cursor, pos - cursor));
|
list.push_back(ZString(cursor, pos - cursor));
|
||||||
cursor = pos + delimiter.getLength();
|
cursor = pos + delimiter.getLength();
|
||||||
pos = cursor;
|
pos = cursor;
|
||||||
--maxSize;
|
--maxSize;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,45 +146,38 @@ namespace coreutils {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::isCharacter(char ch, const char *string)
|
bool ZString::isCharacter(char ch, const char *string) {
|
||||||
{
|
|
||||||
int len = strlen(string);
|
int len = strlen(string);
|
||||||
for (int ix = 0; ix < len; ++ix)
|
for (int ix = 0; ix < len; ++ix) {
|
||||||
{
|
|
||||||
if (ch == string[ix])
|
if (ch == string[ix])
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZString ZString::getTokenInclude(const char *include)
|
ZString ZString::getTokenInclude(const char *include) {
|
||||||
{
|
|
||||||
char *start = cursor;
|
char *start = cursor;
|
||||||
while ((cursor <= (data + length)) && isCharacter(*cursor, include))
|
while ((cursor <= (data + length)) && isCharacter(*cursor, include))
|
||||||
++cursor;
|
++cursor;
|
||||||
return ZString(start, cursor - start);
|
return ZString(start, cursor - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZString ZString::getTokenExclude(const char *exclude)
|
ZString ZString::getTokenExclude(const char *exclude) {
|
||||||
{
|
|
||||||
char *start = cursor;
|
char *start = cursor;
|
||||||
while ((cursor <= (data + length)) && !isCharacter(*cursor, exclude))
|
while ((cursor <= (data + length)) && !isCharacter(*cursor, exclude))
|
||||||
++cursor;
|
++cursor;
|
||||||
return ZString(start, cursor - start);
|
return ZString(start, cursor - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZString ZString::getTokenExclude(std::string exclude)
|
ZString ZString::getTokenExclude(std::string exclude) {
|
||||||
{
|
|
||||||
return getTokenExclude(exclude.c_str());
|
return getTokenExclude(exclude.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
ZString &ZString::operator[](int index)
|
ZString &ZString::operator[](int index) {
|
||||||
{
|
|
||||||
return list[index];
|
return list[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::eod()
|
bool ZString::eod() {
|
||||||
{
|
|
||||||
return cursor >= data + length;
|
return cursor >= data + length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,34 +185,29 @@ namespace coreutils {
|
|||||||
return strncmp(cursor, value, strlen(value)) == 0;
|
return strncmp(cursor, value, strlen(value)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::equals(const char *value)
|
bool ZString::equals(const char *value) {
|
||||||
{
|
|
||||||
if (strlen(value) != length)
|
if (strlen(value) != length)
|
||||||
return false;
|
return false;
|
||||||
return strncmp(data, value, length) == 0;
|
return strncmp(data, value, length) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::equals(char *value)
|
bool ZString::equals(char *value) {
|
||||||
{
|
|
||||||
if (strlen(value) != length)
|
if (strlen(value) != length)
|
||||||
return false;
|
return false;
|
||||||
return strncmp(data, value, length) == 0;
|
return strncmp(data, value, length) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::equals(ZString &zstring)
|
bool ZString::equals(ZString &zstring) {
|
||||||
{
|
|
||||||
if (zstring.getLength() != length)
|
if (zstring.getLength() != length)
|
||||||
return false;
|
return false;
|
||||||
return strncmp(data, zstring.getData(), length) == 0;
|
return strncmp(data, zstring.getData(), length) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::equals(std::string &string)
|
bool ZString::equals(std::string &string) {
|
||||||
{
|
|
||||||
return string == std::string(data, length);
|
return string == std::string(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::ifNext(const char *value)
|
bool ZString::ifNext(const char *value) {
|
||||||
{
|
|
||||||
if (((data + length) - cursor) < strlen(value))
|
if (((data + length) - cursor) < strlen(value))
|
||||||
return false;
|
return false;
|
||||||
bool test = (strncmp(cursor, value, strlen(value)) == 0);
|
bool test = (strncmp(cursor, value, strlen(value)) == 0);
|
||||||
@ -237,46 +225,37 @@ namespace coreutils {
|
|||||||
return test;
|
return test;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZString::ifEqualsCount(ZString &comparator)
|
int ZString::ifEqualsCount(ZString &comparator) {
|
||||||
{
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
while (cursor < (data + length))
|
while (cursor < (data + length)) {
|
||||||
{
|
if (*cursor == *comparator.cursor) {
|
||||||
if (*cursor == *comparator.cursor)
|
|
||||||
{
|
|
||||||
++count;
|
++count;
|
||||||
++cursor;
|
++cursor;
|
||||||
++comparator.cursor;
|
++comparator.cursor;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZString::skipWhitespace()
|
int ZString::skipWhitespace() {
|
||||||
{
|
|
||||||
int len = strspn(cursor, " \n\t");
|
int len = strspn(cursor, " \n\t");
|
||||||
cursor += len;
|
cursor += len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZString ZString::goeol()
|
ZString ZString::goeol() {
|
||||||
{
|
|
||||||
bool set = false;
|
bool set = false;
|
||||||
char *temp = cursor;
|
char *temp = cursor;
|
||||||
char *tempend = data + length;
|
char *tempend = data + length;
|
||||||
while (cursor <= (data + length))
|
while (cursor <= (data + length)) {
|
||||||
{
|
if (*cursor == '\r') {
|
||||||
if (*cursor == '\r')
|
|
||||||
{
|
|
||||||
tempend = cursor++;
|
tempend = cursor++;
|
||||||
set = true;
|
set = true;
|
||||||
}
|
}
|
||||||
if (*cursor == '\n')
|
if (*cursor == '\n') {
|
||||||
{
|
|
||||||
if (!set)
|
if (!set)
|
||||||
tempend = cursor;
|
tempend = cursor;
|
||||||
++cursor;
|
++cursor;
|
||||||
@ -287,15 +266,13 @@ namespace coreutils {
|
|||||||
return ZString(temp, tempend - temp);
|
return ZString(temp, tempend - temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZString ZString::readBlock(size_t size)
|
ZString ZString::readBlock(size_t size) {
|
||||||
{
|
|
||||||
char *temp = cursor;
|
char *temp = cursor;
|
||||||
cursor += size;
|
cursor += size;
|
||||||
return ZString(temp, size);
|
return ZString(temp, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ZString::getData()
|
char *ZString::getData() {
|
||||||
{
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,13 +286,11 @@ namespace coreutils {
|
|||||||
this->cursor = cursor;
|
this->cursor = cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZString::getLength()
|
size_t ZString::getLength() {
|
||||||
{
|
|
||||||
return length - (cursor - data);
|
return length - (cursor - data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZString::setZString(ZString zstring)
|
void ZString::setZString(ZString zstring) {
|
||||||
{
|
|
||||||
data = zstring.getData();
|
data = zstring.getData();
|
||||||
length = zstring.getLength();
|
length = zstring.getLength();
|
||||||
cursor = data;
|
cursor = data;
|
||||||
@ -329,18 +304,15 @@ namespace coreutils {
|
|||||||
return ZString(cursor, data + length - cursor);
|
return ZString(cursor, data + length - cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZString::reset()
|
void ZString::reset() {
|
||||||
{
|
|
||||||
cursor = data;
|
cursor = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
char ZString::charAt(int index)
|
char ZString::charAt(int index) {
|
||||||
{
|
|
||||||
return *(cursor + index);
|
return *(cursor + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZString::ifCRLF()
|
bool ZString::ifCRLF() {
|
||||||
{
|
|
||||||
int len = length;
|
int len = length;
|
||||||
if (*(data + length - 1) == '\n')
|
if (*(data + length - 1) == '\n')
|
||||||
--length;
|
--length;
|
||||||
|
@ -85,6 +85,8 @@ namespace coreutils {
|
|||||||
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 ZString &valuex) const;
|
||||||
|
bool operator!=(const char *valuex) const;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Return a vector of ZString objects which contain the parts established
|
/// Return a vector of ZString objects which contain the parts established
|
||||||
|
Loading…
x
Reference in New Issue
Block a user