<< operator now outputs fulll ZString.

This commit is contained in:
Brad Arant committed 2022-04-04 13:35:15 -07:00
1 parent 59228ad356
commit b25650c5a7
4 files changed
+83 -43

No files matched your search

+32 -20
View File
@@ -1,32 +1,27 @@
#include "ZString.h"
#include "Log.h"
#include "Exception.h"
#include <iostream>
namespace coreutils
{
namespace coreutils {
std::ostream &operator<<(std::ostream &os, const ZString &zstring)
{
for (char *ix = zstring.cursor; ix < (zstring.data + zstring.length); ++ix)
{
os << *ix;
}
std::ostream &operator<<(std::ostream &os, const ZString &zstring) {
for (char *ix = zstring.data; ix < (zstring.data + zstring.length); ++ix)
os << *ix;
return os;
}
std::ostream &operator<<(std::ostream &os, const std::string &string)
{
std::ostream &operator<<(std::ostream &os, const std::string &string) {
os << string;
return os;
}
std::ostream &operator+(std::ostream &os, const ZString &zstring)
{
std::ostream &operator+(std::ostream &os, const ZString &zstring) {
os << zstring;
return os;
}
ZString::ZString()
{
ZString::ZString() {
data = NULL;
length = 0;
cursor = data;
@@ -38,16 +33,14 @@ namespace coreutils
ZString::ZString(const char *data, size_t length) : data((char *)data), length(length), cursor((char *)data) {}
ZString::ZString(const ZString &zstring)
{
ZString::ZString(const ZString &zstring) {
data = zstring.data;
length = zstring.length;
cursor = zstring.cursor;
// Log(LOG_DEBUG_2) << "ZString Copy Constructor: ";
}
ZString::ZString(std::string data)
{
ZString::ZString(std::string data) {
this->data = (char *)data.c_str();
length = data.length();
cursor = (char *)data.c_str();
@@ -80,6 +73,15 @@ namespace coreutils
return tempInt;
}
int ZString::incrementCursor(int length) {
char *temp = cursor;
if((cursor + length) > (data + this->length))
cursor = data + this->length;
else
cursor += length;
return cursor - temp;
}
std::string ZString::str()
{
return std::string(data, length);
@@ -279,6 +281,12 @@ namespace coreutils
char *ZString::getCursor() {
return cursor;
}
void ZString::setCursor(char *cursor) {
if((cursor < data) || (cursor > (data + length)))
throw Exception("Cursor out of range on setCursor.");
this->cursor = cursor;
}
size_t ZString::getLength()
{
@@ -292,10 +300,14 @@ namespace coreutils
cursor = data;
}
ZString ZString::getParsed() {
ZString ZString::parsed() {
return ZString(data, cursor - data);
}
ZString ZString::unparsed() {
return ZString(cursor, data + length - cursor);
}
void ZString::reset()
{
cursor = data;