diff --git a/Exception.cpp b/Exception.cpp index 3220f2a..22eebb4 100644 --- a/Exception.cpp +++ b/Exception.cpp @@ -2,16 +2,16 @@ #include "Log.h" namespace coreutils { - + Exception::Exception(std::string text, std::string file, int line, int errorNumber) { this->text = text; this->file = file; this->line = line; if(errorNumber == -1) - this->errorNumber = errno; + this->errorNumber = errno; else - this->errorNumber = errorNumber; - + this->errorNumber = errorNumber; + Log(LOG_EXCEPT) << text; } diff --git a/IMFMessage.cpp b/IMFMessage.cpp index d204edc..1c2202b 100644 --- a/IMFMessage.cpp +++ b/IMFMessage.cpp @@ -48,7 +48,7 @@ namespace coreutils { if(header.getKey().equals(key)) { ZString value = header.getValue(); if(valueOnly) { - std::vector split = ZString(value).split(ZString((char *)";")); + std::vector split = ZString(value).split(";"); value = split[0]; } return value; @@ -60,10 +60,10 @@ namespace coreutils { ZString IMFMessage::getHeaderKeyPairValue(ZString headerKey, ZString key) { ZString value; ZString psource(getHeader(headerKey, false)); - std::vector sourcep = psource.split((char *)";"); - for(ZString work: sourcep) { + std::vector sourcep = psource.split(";"); + for(ZString work: sourcep) { work.skipWhitespace(); - ZString token = work.getTokenExclude((char *)"="); + ZString token = work.getTokenExclude("="); if(work.ifNext((char *)"=")) { if(token.equals(key)) { if(work.ifNext((char *)"\"")) { diff --git a/ZString.cpp b/ZString.cpp index 3286cae..cd508e2 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -4,7 +4,9 @@ namespace coreutils { std::ostream& operator<<(std::ostream& os, const ZString &zstring) { - os << zstring; + for(int ix = 0; ix < zstring.length; ++ix) { + os << zstring.data[ix]; + } return os; } @@ -24,28 +26,30 @@ namespace coreutils { cursor = data; } - ZString::ZString(const ZString&) {} + ZString::ZString(const char *data) : data((char *)data), length(strlen(data)), cursor((char *)data) {} - ZString::ZString(const char *data) : data((char *)data), length(strlen(data)), cursor((char *)data) {} - ZString::ZString(char *data, size_t length) : data(data), length(length), cursor(data) {} - ZString::ZString(ZString &zstring) { - data = zstring.getData(); - length = zstring.getLength(); - } - - std::vector & ZString::getList() { + ZString::ZString(const char *data, size_t length) : data((char *)data), length(length), cursor((char *)data) {} + + ZString::ZString(const ZString &zstring) { + data = zstring.data; + length = zstring.length; + cursor = zstring.cursor; + Log(LOG_DEBUG_2) << "ZSrting Copy Constructor: "; + } + + std::vector &ZString::getList() { return list; } - int ZString::asInteger() { + int ZString::asInteger() { std::stringstream temp(std::string(data, length)); int tempInt = 0; temp >> tempInt; return tempInt; } - + std::string ZString::str() { return std::string(data, length); } @@ -54,49 +58,55 @@ namespace coreutils { return std::string(data, len); } - std::vector ZString::split(std::string &delimiter, size_t maxSize) { - return split(ZString(delimiter.c_str()), maxSize); - } + std::vector &ZString::split(std::string delimiter, size_t maxSize) { + coreutils::ZString zDelimiter((char *)delimiter.c_str(), delimiter.size()); + return split(zDelimiter, maxSize); + } - std::vector ZString::split(ZString delimiter, size_t maxSize) { + std::vector &ZString::split(ZString &delimiter, size_t maxSize) { list.clear(); if(length == 0) { list.push_back(ZString((char *)"")); return list; } - + char *end = data + length; char *pos = cursor; - + while(pos < end) { - if(strncmp(pos, delimiter.getData(), delimiter.getLength()) == 0) { - list.push_back(ZString(cursor, pos - cursor)); - cursor = pos + delimiter.getLength(); - pos = cursor; - } - else { - ++pos; - } + if(strncmp(pos, delimiter.getData(), delimiter.getLength()) == 0) { + list.push_back(ZString(cursor, pos - cursor)); + cursor = pos + delimiter.getLength(); + pos = cursor; + } + else { + ++pos; + } } + list.push_back(ZString(cursor, pos - cursor)); cursor = pos; return list; } - - ZString ZString::getTokenInclude(char *include) { + + ZString ZString::getTokenInclude(const char *include) { char *start = cursor; int len = strcspn(cursor, include); cursor += len; return ZString(start, len); } - - ZString ZString::getTokenExclude(char *exclude) { + + ZString ZString::getTokenExclude(const char *exclude) { char *start = cursor; int len = strspn(cursor, exclude); cursor += len; return ZString(start, len); } - - ZString ZString::operator[](int index) { + + ZString ZString::getTokenExclude(std::string exclude) { + return getTokenExclude(exclude.c_str()); + } + + ZString &ZString::operator[](int index) { return list[index]; } @@ -108,14 +118,14 @@ namespace coreutils { return strncmp(data, value, length) == 0; } - bool ZString::equals(ZString zstring) { + bool ZString::equals(ZString &zstring) { if(zstring.getLength() != getLength()) return false; return strncmp(data, zstring.getData(), getLength()) == 0; } - bool ZString::equals(std::string string) { - return strncmp(string.c_str(), getData(), getLength()) == 0; + bool ZString::equals(std::string &string) { + return string == std::string(data, length); } bool ZString::ifNext(char *value) { diff --git a/ZString.h b/ZString.h index 84d373d..1173df2 100644 --- a/ZString.h +++ b/ZString.h @@ -28,15 +28,9 @@ namespace coreutils { /// /// Consructor providing an empty ZString.. /// - + ZString(); - /// - /// Copy constructor. - /// - - ZString(const ZString&); - /// /// /// @@ -49,11 +43,13 @@ namespace coreutils { ZString(char *data, size_t length); + ZString(const char *data, size_t length); + /// /// Consructor providing a copy of a ZString. /// - ZString(ZString &zstring); + ZString(const ZString &zstring); /// /// A friend method used to write the value of the ZString from the cursor @@ -96,13 +92,13 @@ namespace coreutils { /// /// - std::vector split(ZString delimiter, size_t maxSize = 0); + std::vector &split(ZString &delimiter, size_t maxSize = 0); /// /// /// - std::vector split(std::string &delimiter, size_t maxSize = 0); + std::vector &split(std::string delimiter, size_t maxSize = 0); /// /// Use getTokenInclude with a list of character to allow the forwarding @@ -110,19 +106,21 @@ namespace coreutils { /// include string is not encountered in the ZString data. /// - ZString getTokenInclude(char *include); + ZString getTokenInclude(const char *include); /// /// /// - ZString getTokenExclude(char *exclude); + ZString getTokenExclude(const char *exclude); + + ZString getTokenExclude(std::string exclude); /// /// Use the [] operator to retrieve values delimited by the split method. /// - ZString operator[](int index); + ZString &operator[](int index); /// /// Return true if the ZString cursor is at the end of the data. @@ -140,13 +138,13 @@ namespace coreutils { /// /// - bool equals(ZString zstring); + bool equals(ZString &zstring); /// /// /// - bool equals(std::string string); + bool equals(std::string &string); /// /// Advance the cursor the length of the provided value if the value at diff --git a/compile b/compile index 6abd269..5d5037e 100755 --- a/compile +++ b/compile @@ -5,7 +5,7 @@ do filename="${file%.*}" list="$list $filename.o" echo -n "Compiling $filename..." - g++ -g -c $file -std=c++17 + g++ -g -c $file -std=c++17 & if [ $? = '0' ] then echo "OK"