Core Changes

This commit is contained in:
Matt Arant committed 2023-10-06 18:32:17 +00:00
1 parent 2a8cfcee2a
commit ac142b6a66
35 files changed
+6395 -423

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
#ifndef __Directory_h__
# define __Directory_h__
# include "includes"
# include "DirectoryEntry.h"
# include "Log.h"
namespace coreutils {
class Directory {
public:
Directory(std::string path) {
dir = opendir(path.c_str());
if(dir) {
struct dirent *entry = readdir(dir);
while(entry) {
directory.emplace(std::string(entry->d_name), entry);
entry = readdir(dir);
}
}
if(directory.size() > 0)
cursor = directory.begin();
}
~Directory() {}
bool eod() {
return cursor == directory.end();
}
DirectoryEntry get() {
if(eod())
return NULL;
return cursor->second;
}
void next() {
++cursor;
}
private:
DIR *dir;
std::map<std::string, DirectoryEntry> directory;
std::map<std::string, DirectoryEntry>::iterator cursor;
};
}
#endif
+58
View File
@@ -0,0 +1,58 @@
#ifndef __Directory_h__
#define __Directory_h__
#include "DirectoryEntry.h"
#include "Log.h"
#include "includes"
namespace coreutils
{
class Directory
{
public:
Directory(std::string path)
{
dir = opendir(path.c_str());
if (dir)
{
struct dirent *entry = readdir(dir);
while (entry)
{
directory.emplace(std::string(entry->d_name), entry);
entry = readdir(dir);
}
}
if (directory.size() > 0)
cursor = directory.begin();
}
~Directory() {}
bool eod()
{
return cursor == directory.end();
}
DirectoryEntry get()
{
if (eod())
return NULL;
return cursor->second;
}
void next()
{
++cursor;
}
private:
DIR *dir;
std::map<std::string, DirectoryEntry> directory;
std::map<std::string, DirectoryEntry>::iterator cursor;
};
}
#endif
+58
View File
@@ -0,0 +1,58 @@
#ifndef __Directory_h__
#define __Directory_h__
#include "DirectoryEntry.h"
#include "Log.h"
#include "includes"
namespace coreutils
{
class Directory
{
public:
Directory(std::string path)
{
dir = opendir(path.c_str());
if (dir)
{
struct dirent *entry = readdir(dir);
while (entry)
{
directory.emplace(std::string(entry->d_name), entry);
entry = readdir(dir);
}
}
if (directory.size() > 0)
cursor = directory.begin();
}
~Directory() {}
bool eod()
{
return cursor == directory.end();
}
DirectoryEntry get()
{
if (eod())
return NULL;
return cursor->second;
}
void next()
{
++cursor;
}
private:
DIR *dir;
std::map<std::string, DirectoryEntry> directory;
std::map<std::string, DirectoryEntry>::iterator cursor;
};
}
#endif
+211
View File
@@ -0,0 +1,211 @@
#include "MString.h"
#include "Log.h"
#include <stdlib.h>
#include <iomanip>
#include <cstring>
namespace coreutils {
MString::MString() {
data = NULL;
length = 0;
cursor = NULL;
}
MString::MString(const char *data) {
setSize(strlen(data));
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(char *data, size_t length) {
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const char *data, size_t length) {
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const MString &mstring) {
setSize(mstring.length);
memcpy(data, mstring.data, mstring.length);
cursor = data;
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
}
MString::MString(ZString &zstring) {
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(ZString zstring) {
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(std::string data) {
setSize(data.length());
memcpy(this->data, (char *)data.c_str(), data.length());
cursor = this->data;
}
MString::~MString() {
if(data)
free(data);
}
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
MString& MString::operator=(coreutils::ZString &value) {
// if(*this == value)
// return *this;
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
return *this;
}
MString& MString::operator=(const char *value) {
int len = strlen(value);
setSize(len);
memcpy(data, value, len);
return *this;
}
MString& MString::operator=(char value) {
int len = 1;
setSize(1);
*data = value;
return *this;
}
MString& MString::operator<<(const char *value) {
int temp = length;
int len = strlen(value);
setSize(len + length);
memcpy(data + temp, value, len);
return *this;
}
MString& MString::operator<<(const int value) {
std::stringstream temp;
temp << value;
*this << temp.str();
return *this;
}
// MString& MString::operator<<(coreutils::ZString &zstring) {
// int temp = length;
// int len = length + zstring.getLength();
// setSize(len);
// memcpy(data + temp, zstring.getData(), zstring.getLength());
// return *this;
// }
MString& MString::operator<<(coreutils::ZString zstring) {
int temp = length;
int len = length + zstring.getLength();
setSize(len);
memcpy(data + temp, zstring.getData(), zstring.getLength());
return *this;
}
MString& MString::operator<<(std::string value) {
int temp = length;
int len = length + value.length();
setSize(len);
memcpy(data + temp, value.c_str(), value.length());
return *this;
}
void MString::insert(char ch, int offset) {
setSize(length + 1);
for(int ix = length; ix >= offset; ix--)
getData()[ix + 1] = getData()[ix];
data[offset] = ch;
}
void MString::insert(ZString &value, int offset) {
setSize(length + value.getLength());
for(int ix = length; ix >= offset; ix--)
getData()[ix + value.getLength()] = getData()[ix];
std::memcpy(data + offset, value.getData(), value.getLength());
}
void MString::insert(std::string value, int offset) {
setSize(length + value.size());
for(int ix = length; ix >= offset; ix--)
getData()[ix + value.size()] = getData()[ix];
std::memcpy(data + offset, value.c_str(), value.size());
}
void MString::replace(char ch, int offset) {
}
void MString::replace(ZString &value, int offset) {
}
void MString::replace(std::string value, int offset) {
}
void MString::remove(int offset, int length) {
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
for(int ix = offset; ix < this->length; ix++)
getData()[ix] = getData()[ix + length];
setSize(this->length - length);
}
MString& MString::write(char ch) {
setSize(length + 1);
*(data + length - 1) = ch;
return *this;
}
MString& MString::write(ZString &value) {
int len = length;
setSize(length + value.getLength());
memcpy(data + len, value.getData(), value.getLength());
return *this;
}
void MString::setSize(int size) {
int cursorOffset = cursor - data;
int newBufferSize = ((size / 256) + 1) * 256;
if(bufferSize != newBufferSize) {
bufferSize = newBufferSize;
data = (char *)realloc(data, bufferSize);
cursor = data + cursorOffset;
}
length = size;
}
int MString::offset() {
return cursor - data;
}
}
+147
View File
@@ -0,0 +1,147 @@
#ifndef __MString_h__
#define __MString_h__
#include "ZString.h"
#include <iostream>
#include <sstream>
namespace coreutils {
///
/// Use the MString object when you need a permanent backing store on the heap
/// for a ZString style functionality. Because MString has a backing store we
/// added functionalities to build strings as well as the parsing power of the
/// ZString.
///
class MString : public ZString {
public:
///
///
///
MString();
///
///
///
MString(const char *data);
///
/// Consructor providing the initial setup of the MString object.
///
MString(char *data, size_t length);
MString(const char *data, size_t length);
///
/// Consructor providing a copy of a ZString.
///
MString(ZString &zstring);
MString(ZString zstring);
///
/// Consructor providing a copy of a ZString.
///
MString(const MString &mstring);
///
/// Consructor from a string.
///
MString(std::string data);
~MString();
///
/// Assignment operator will copy data to backing store.
///
// MString& operator=(coreutils::ZString& data);
///
/// Assignment operator will copy data to backing store.
///
// MString& operator=(coreutils::ZString& data);
MString& operator=(coreutils::ZString &data);
///
/// Assignment operator will copy data to backing store.
///
MString& operator=(const char *data);
///
/// Assignment operator will copy data to backing store.
///
MString& operator=(char data);
///
///
///
MString& operator<<(const char *value);
MString& operator<<(const int value);
// MString& operator<<(coreutils::ZString &zstring);
MString& operator<<(coreutils::ZString zstring);
MString& operator<<(std::string value);
///
///
///
void insert(char ch, int offset);
void insert(ZString &value, int offset);
void insert(std::string value, int offset);
///
///
///
void replace(char ch, int offset);
void replace(ZString &value, int offset);
void replace(std::string value, int offset);
///
///
///
void remove(int offset, int length);
///
///
///
MString& write(char ch);
///
///
///
MString& write(ZString &value);
int offset();
private:
int bufferSize = 0;
void setSize(int size);
};
}
#endif
+147
View File
@@ -0,0 +1,147 @@
#ifndef __MString_h__
#define __MString_h__
#include "ZString.h"
#include <iostream>
#include <sstream>
namespace coreutils
{
///
/// Use the MString object when you need a permanent backing store on the heap
/// for a ZString style functionality. Because MString has a backing store we
/// added functionalities to build strings as well as the parsing power of the
/// ZString.
///
class MString : public ZString
{
public:
///
///
///
MString();
///
///
///
MString(const char *data);
MString(void *alias);
///
/// Consructor providing the initial setup of the MString object.
///
MString(char *data, size_t length);
MString(const char *data, size_t length);
///
/// Consructor providing a copy of a ZString.
///
MString(ZString &zstring);
MString(ZString zstring);
///
/// Consructor providing a copy of a ZString.
///
MString(const MString &mstring);
///
/// Consructor from a string.
///
MString(std::string data);
~MString();
///
/// Assignment operator will copy data to backing store.
///
// MString& operator=(coreutils::ZString& data);
///
/// Assignment operator will copy data to backing store.
///
// MString& operator=(coreutils::ZString& data);
MString &operator=(coreutils::ZString &data);
///
/// Assignment operator will copy data to backing store.
///
MString &operator=(const char *data);
///
/// Assignment operator will copy data to backing store.
///
MString &operator=(char data);
///
///
///
MString &operator<<(const char *value);
MString &operator<<(const int value);
// MString& operator<<(coreutils::ZString &zstring);
MString &operator<<(coreutils::ZString zstring);
MString &operator<<(std::string value);
///
///
///
void insert(char ch, int offset);
void insert(ZString &value, int offset);
void insert(std::string value, int offset);
///
///
///
void replace(char ch, int offset);
void replace(ZString &value, int offset);
void replace(std::string value, int offset);
///
///
///
void remove(int offset, int length);
///
///
///
MString &write(char ch);
///
///
///
MString &write(ZString &value);
int offset();
private:
int bufferSize = 0;
void setSize(int size);
};
}
#endif
+241
View File
@@ -0,0 +1,241 @@
#include "MString.h"
#include "Log.h"
#include <cstring>
#include <iomanip>
#include <stdlib.h>
namespace coreutils
{
MString::MString()
{
data = NULL;
length = 0;
cursor = NULL;
}
MString::MString(void *alias)
{
}
MString::MString(const char *data)
{
setSize(strlen(data));
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const MString &mstring)
{
setSize(mstring.length);
memcpy(data, mstring.data, mstring.length);
cursor = data;
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
}
MString::MString(ZString &zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(ZString zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(std::string data)
{
setSize(data.length());
memcpy(this->data, (char *)data.c_str(), data.length());
cursor = this->data;
}
MString::~MString()
{
if (data)
free(data);
}
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
MString &MString::operator=(coreutils::ZString &value)
{
// if(*this == value)
// return *this;
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
return *this;
}
MString &MString::operator=(const char *value)
{
int len = strlen(value);
setSize(len);
memcpy(data, value, len);
return *this;
}
MString &MString::operator=(char value)
{
int len = 1;
setSize(1);
*data = value;
return *this;
}
MString &MString::operator<<(const char *value)
{
int temp = length;
int len = strlen(value);
setSize(len + length);
memcpy(data + temp, value, len);
return *this;
}
MString &MString::operator<<(const int value)
{
std::stringstream temp;
temp << value;
*this << temp.str();
return *this;
}
// MString& MString::operator<<(coreutils::ZString &zstring) {
// int temp = length;
// int len = length + zstring.getLength();
// setSize(len);
// memcpy(data + temp, zstring.getData(), zstring.getLength());
// return *this;
// }
MString &MString::operator<<(coreutils::ZString zstring)
{
int temp = length;
int len = length + zstring.getLength();
setSize(len);
memcpy(data + temp, zstring.getData(), zstring.getLength());
return *this;
}
MString &MString::operator<<(std::string value)
{
int temp = length;
int len = length + value.length();
setSize(len);
memcpy(data + temp, value.c_str(), value.length());
return *this;
}
void MString::insert(char ch, int offset)
{
setSize(length + 1);
for (int ix = length; ix >= offset; ix--)
getData()[ix + 1] = getData()[ix];
data[offset] = ch;
}
void MString::insert(ZString &value, int offset)
{
setSize(length + value.getLength());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.getLength()] = getData()[ix];
std::memcpy(data + offset, value.getData(), value.getLength());
}
void MString::insert(std::string value, int offset)
{
setSize(length + value.size());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.size()] = getData()[ix];
std::memcpy(data + offset, value.c_str(), value.size());
}
void MString::replace(char ch, int offset)
{
}
void MString::replace(ZString &value, int offset)
{
}
void MString::replace(std::string value, int offset)
{
}
void MString::remove(int offset, int length)
{
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
for (int ix = offset; ix < this->length; ix++)
getData()[ix] = getData()[ix + length];
setSize(this->length - length);
}
MString &MString::write(char ch)
{
setSize(length + 1);
*(data + length - 1) = ch;
return *this;
}
MString &MString::write(ZString &value)
{
int len = length;
setSize(length + value.getLength());
memcpy(data + len, value.getData(), value.getLength());
return *this;
}
void MString::setSize(int size)
{
int cursorOffset = cursor - data;
int newBufferSize = ((size / 256) + 1) * 256;
if (bufferSize != newBufferSize)
{
bufferSize = newBufferSize;
data = (char *)realloc(data, bufferSize);
cursor = data + cursorOffset;
}
length = size;
}
int MString::offset()
{
return cursor - data;
}
}
+241
View File
@@ -0,0 +1,241 @@
#include "MString.h"
#include "Log.h"
#include <cstring>
#include <iomanip>
#include <stdlib.h>
namespace coreutils
{
MString::MString()
{
data = NULL;
length = 0;
cursor = NULL;
}
MString::MString(void *alias)
{
}
MString::MString(const char *data)
{
setSize(strlen(data));
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const MString &mstring)
{
setSize(mstring.length);
memcpy(data, mstring.data, mstring.length);
cursor = data;
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
}
MString::MString(ZString &zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(ZString zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(std::string data)
{
setSize(data.length());
memcpy(this->data, (char *)data.c_str(), data.length());
cursor = this->data;
}
MString::~MString()
{
if (data)
free(data);
}
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
MString &MString::operator=(coreutils::ZString &value)
{
// if(*this == value)
// return *this;
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
return *this;
}
MString &MString::operator=(const char *value)
{
int len = strlen(value);
setSize(len);
memcpy(data, value, len);
return *this;
}
MString &MString::operator=(char value)
{
int len = 1;
setSize(1);
*data = value;
return *this;
}
MString &MString::operator<<(const char *value)
{
int temp = length;
int len = strlen(value);
setSize(len + length);
memcpy(data + temp, value, len);
return *this;
}
MString &MString::operator<<(const int value)
{
std::stringstream temp;
temp << value;
*this << temp.str();
return *this;
}
// MString& MString::operator<<(coreutils::ZString &zstring) {
// int temp = length;
// int len = length + zstring.getLength();
// setSize(len);
// memcpy(data + temp, zstring.getData(), zstring.getLength());
// return *this;
// }
MString &MString::operator<<(coreutils::ZString zstring)
{
int temp = length;
int len = length + zstring.getLength();
setSize(len);
memcpy(data + temp, zstring.getData(), zstring.getLength());
return *this;
}
MString &MString::operator<<(std::string value)
{
int temp = length;
int len = length + value.length();
setSize(len);
memcpy(data + temp, value.c_str(), value.length());
return *this;
}
void MString::insert(char ch, int offset)
{
setSize(length + 1);
for (int ix = length; ix >= offset; ix--)
getData()[ix + 1] = getData()[ix];
data[offset] = ch;
}
void MString::insert(ZString &value, int offset)
{
setSize(length + value.getLength());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.getLength()] = getData()[ix];
std::memcpy(data + offset, value.getData(), value.getLength());
}
void MString::insert(std::string value, int offset)
{
setSize(length + value.size());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.size()] = getData()[ix];
std::memcpy(data + offset, value.c_str(), value.size());
}
void MString::replace(char ch, int offset)
{
}
void MString::replace(ZString &value, int offset)
{
}
void MString::replace(std::string value, int offset)
{
}
void MString::remove(int offset, int length)
{
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
for (int ix = offset; ix < this->length; ix++)
getData()[ix] = getData()[ix + length];
setSize(this->length - length);
}
MString &MString::write(char ch)
{
setSize(length + 1);
*(data + length - 1) = ch;
return *this;
}
MString &MString::write(ZString &value)
{
int len = length;
setSize(length + value.getLength());
memcpy(data + len, value.getData(), value.getLength());
return *this;
}
void MString::setSize(int size)
{
int cursorOffset = cursor - data;
int newBufferSize = ((size / 256) + 1) * 256;
if (bufferSize != newBufferSize)
{
bufferSize = newBufferSize;
data = (char *)realloc(data, bufferSize);
cursor = data + cursorOffset;
}
length = size;
}
int MString::offset()
{
return cursor - data;
}
}
+241
View File
@@ -0,0 +1,241 @@
#include "MString.h"
#include "Log.h"
#include <cstring>
#include <iomanip>
#include <stdlib.h>
namespace coreutils
{
MString::MString()
{
data = NULL;
length = 0;
cursor = NULL;
}
MString::MString(void *alias)
{
}
MString::MString(const char *data)
{
setSize(strlen(data));
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const MString &mstring)
{
setSize(mstring.length);
memcpy(data, mstring.data, mstring.length);
cursor = data;
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
}
MString::MString(ZString &zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(ZString zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(std::string data)
{
setSize(data.length());
memcpy(this->data, (char *)data.c_str(), data.length());
cursor = this->data;
}
MString::~MString()
{
if (data)
free(data);
}
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
MString &MString::operator=(coreutils::ZString &value)
{
// if(*this == value)
// return *this;
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
return *this;
}
MString &MString::operator=(const char *value)
{
int len = strlen(value);
setSize(len);
memcpy(data, value, len);
return *this;
}
MString &MString::operator=(char value)
{
int len = 1;
setSize(1);
*data = value;
return *this;
}
MString &MString::operator<<(const char *value)
{
int temp = length;
int len = strlen(value);
setSize(len + length);
memcpy(data + temp, value, len);
return *this;
}
MString &MString::operator<<(const int value)
{
std::stringstream temp;
temp << value;
*this << temp.str();
return *this;
}
// MString& MString::operator<<(coreutils::ZString &zstring) {
// int temp = length;
// int len = length + zstring.getLength();
// setSize(len);
// memcpy(data + temp, zstring.getData(), zstring.getLength());
// return *this;
// }
MString &MString::operator<<(coreutils::ZString zstring)
{
int temp = length;
int len = length + zstring.getLength();
setSize(len);
memcpy(data + temp, zstring.getData(), zstring.getLength());
return *this;
}
MString &MString::operator<<(std::string value)
{
int temp = length;
int len = length + value.length();
setSize(len);
memcpy(data + temp, value.c_str(), value.length());
return *this;
}
void MString::insert(char ch, int offset)
{
setSize(length + 1);
for (int ix = length; ix >= offset; ix--)
getData()[ix + 1] = getData()[ix];
data[offset] = ch;
}
void MString::insert(ZString &value, int offset)
{
setSize(length + value.getLength());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.getLength()] = getData()[ix];
std::memcpy(data + offset, value.getData(), value.getLength());
}
void MString::insert(std::string value, int offset)
{
setSize(length + value.size());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.size()] = getData()[ix];
std::memcpy(data + offset, value.c_str(), value.size());
}
void MString::replace(char ch, int offset)
{
}
void MString::replace(ZString &value, int offset)
{
}
void MString::replace(std::string value, int offset)
{
}
void MString::remove(int offset, int length)
{
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
for (int ix = offset; ix < this->length; ix++)
getData()[ix] = getData()[ix + length];
setSize(this->length - length);
}
MString &MString::write(char ch)
{
setSize(length + 1);
*(data + length - 1) = ch;
return *this;
}
MString &MString::write(ZString &value)
{
int len = length;
setSize(length + value.getLength());
memcpy(data + len, value.getData(), value.getLength());
return *this;
}
void MString::setSize(int size)
{
int cursorOffset = cursor - data;
int newBufferSize = ((size / 256) + 1) * 256;
if (bufferSize != newBufferSize)
{
bufferSize = newBufferSize;
data = (char *)realloc(data, bufferSize);
cursor = data + cursorOffset;
}
length = size;
}
int MString::offset()
{
return cursor - data;
}
}
+242
View File
@@ -0,0 +1,242 @@
#include "MString.h"
#include "Log.h"
#include "uuid/uuid.h"
#include <cstring>
#include <iomanip>
#include <stdlib.h>
namespace coreutils
{
MString::MString()
{
data = NULL;
length = 0;
cursor = NULL;
}
MString::MString(void *alias)
{
}
MString::MString(const char *data)
{
setSize(strlen(data));
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const MString &mstring)
{
setSize(mstring.length);
memcpy(data, mstring.data, mstring.length);
cursor = data;
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
}
MString::MString(ZString &zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(ZString zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(std::string data)
{
setSize(data.length());
memcpy(this->data, (char *)data.c_str(), data.length());
cursor = this->data;
}
MString::~MString()
{
if (data)
free(data);
}
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
MString &MString::operator=(coreutils::ZString &value)
{
// if(*this == value)
// return *this;
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
return *this;
}
MString &MString::operator=(const char *value)
{
int len = strlen(value);
setSize(len);
memcpy(data, value, len);
return *this;
}
MString &MString::operator=(char value)
{
int len = 1;
setSize(1);
*data = value;
return *this;
}
MString &MString::operator<<(const char *value)
{
int temp = length;
int len = strlen(value);
setSize(len + length);
memcpy(data + temp, value, len);
return *this;
}
MString &MString::operator<<(const int value)
{
std::stringstream temp;
temp << value;
*this << temp.str();
return *this;
}
// MString& MString::operator<<(coreutils::ZString &zstring) {
// int temp = length;
// int len = length + zstring.getLength();
// setSize(len);
// memcpy(data + temp, zstring.getData(), zstring.getLength());
// return *this;
// }
MString &MString::operator<<(coreutils::ZString zstring)
{
int temp = length;
int len = length + zstring.getLength();
setSize(len);
memcpy(data + temp, zstring.getData(), zstring.getLength());
return *this;
}
MString &MString::operator<<(std::string value)
{
int temp = length;
int len = length + value.length();
setSize(len);
memcpy(data + temp, value.c_str(), value.length());
return *this;
}
void MString::insert(char ch, int offset)
{
setSize(length + 1);
for (int ix = length; ix >= offset; ix--)
getData()[ix + 1] = getData()[ix];
data[offset] = ch;
}
void MString::insert(ZString &value, int offset)
{
setSize(length + value.getLength());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.getLength()] = getData()[ix];
std::memcpy(data + offset, value.getData(), value.getLength());
}
void MString::insert(std::string value, int offset)
{
setSize(length + value.size());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.size()] = getData()[ix];
std::memcpy(data + offset, value.c_str(), value.size());
}
void MString::replace(char ch, int offset)
{
}
void MString::replace(ZString &value, int offset)
{
}
void MString::replace(std::string value, int offset)
{
}
void MString::remove(int offset, int length)
{
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
for (int ix = offset; ix < this->length; ix++)
getData()[ix] = getData()[ix + length];
setSize(this->length - length);
}
MString &MString::write(char ch)
{
setSize(length + 1);
*(data + length - 1) = ch;
return *this;
}
MString &MString::write(ZString &value)
{
int len = length;
setSize(length + value.getLength());
memcpy(data + len, value.getData(), value.getLength());
return *this;
}
void MString::setSize(int size)
{
int cursorOffset = cursor - data;
int newBufferSize = ((size / 256) + 1) * 256;
if (bufferSize != newBufferSize)
{
bufferSize = newBufferSize;
data = (char *)realloc(data, bufferSize);
cursor = data + cursorOffset;
}
length = size;
}
int MString::offset()
{
return cursor - data;
}
}
+242
View File
@@ -0,0 +1,242 @@
#include "MString.h"
#include "Log.h"
#include "uuid/uuid.h"
#include <cstring>
#include <iomanip>
#include <stdlib.h>
namespace coreutils
{
MString::MString()
{
data = NULL;
length = 0;
cursor = NULL;
}
MString::MString(void *alias)
{
}
MString::MString(const char *data)
{
setSize(strlen(data));
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const MString &mstring)
{
setSize(mstring.length);
memcpy(data, mstring.data, mstring.length);
cursor = data;
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
}
MString::MString(ZString &zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(ZString zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(std::string data)
{
setSize(data.length());
memcpy(this->data, (char *)data.c_str(), data.length());
cursor = this->data;
}
MString::~MString()
{
if (data)
free(data);
}
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
MString &MString::operator=(coreutils::ZString &value)
{
// if(*this == value)
// return *this;
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
return *this;
}
MString &MString::operator=(const char *value)
{
int len = strlen(value);
setSize(len);
memcpy(data, value, len);
return *this;
}
MString &MString::operator=(char value)
{
int len = 1;
setSize(1);
*data = value;
return *this;
}
MString &MString::operator<<(const char *value)
{
int temp = length;
int len = strlen(value);
setSize(len + length);
memcpy(data + temp, value, len);
return *this;
}
MString &MString::operator<<(const int value)
{
std::stringstream temp;
temp << value;
*this << temp.str();
return *this;
}
// MString& MString::operator<<(coreutils::ZString &zstring) {
// int temp = length;
// int len = length + zstring.getLength();
// setSize(len);
// memcpy(data + temp, zstring.getData(), zstring.getLength());
// return *this;
// }
MString &MString::operator<<(coreutils::ZString zstring)
{
int temp = length;
int len = length + zstring.getLength();
setSize(len);
memcpy(data + temp, zstring.getData(), zstring.getLength());
return *this;
}
MString &MString::operator<<(std::string value)
{
int temp = length;
int len = length + value.length();
setSize(len);
memcpy(data + temp, value.c_str(), value.length());
return *this;
}
void MString::insert(char ch, int offset)
{
setSize(length + 1);
for (int ix = length; ix >= offset; ix--)
getData()[ix + 1] = getData()[ix];
data[offset] = ch;
}
void MString::insert(ZString &value, int offset)
{
setSize(length + value.getLength());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.getLength()] = getData()[ix];
std::memcpy(data + offset, value.getData(), value.getLength());
}
void MString::insert(std::string value, int offset)
{
setSize(length + value.size());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.size()] = getData()[ix];
std::memcpy(data + offset, value.c_str(), value.size());
}
void MString::replace(char ch, int offset)
{
}
void MString::replace(ZString &value, int offset)
{
}
void MString::replace(std::string value, int offset)
{
}
void MString::remove(int offset, int length)
{
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
for (int ix = offset; ix < this->length; ix++)
getData()[ix] = getData()[ix + length];
setSize(this->length - length);
}
MString &MString::write(char ch)
{
setSize(length + 1);
*(data + length - 1) = ch;
return *this;
}
MString &MString::write(ZString &value)
{
int len = length;
setSize(length + value.getLength());
memcpy(data + len, value.getData(), value.getLength());
return *this;
}
void MString::setSize(int size)
{
int cursorOffset = cursor - data;
int newBufferSize = ((size / 256) + 1) * 256;
if (bufferSize != newBufferSize)
{
bufferSize = newBufferSize;
data = (char *)realloc(data, bufferSize);
cursor = data + cursorOffset;
}
length = size;
}
int MString::offset()
{
return cursor - data;
}
}
+242
View File
@@ -0,0 +1,242 @@
#include "MString.h"
#include "Log.h"
#include "uuid/uuid.h"
#include <cstring>
#include <iomanip>
#include <stdlib.h>
namespace coreutils
{
MString::MString()
{
data = NULL;
length = 0;
cursor = NULL;
}
MString::MString(void *alias)
{
}
MString::MString(const char *data)
{
setSize(strlen(data));
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const MString &mstring)
{
setSize(mstring.length);
memcpy(data, mstring.data, mstring.length);
cursor = data;
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
}
MString::MString(ZString &zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(ZString zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(std::string data)
{
setSize(data.length());
memcpy(this->data, (char *)data.c_str(), data.length());
cursor = this->data;
}
MString::~MString()
{
if (data)
free(data);
}
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
MString &MString::operator=(coreutils::ZString &value)
{
// if(*this == value)
// return *this;
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
return *this;
}
MString &MString::operator=(const char *value)
{
int len = strlen(value);
setSize(len);
memcpy(data, value, len);
return *this;
}
MString &MString::operator=(char value)
{
int len = 1;
setSize(1);
*data = value;
return *this;
}
MString &MString::operator<<(const char *value)
{
int temp = length;
int len = strlen(value);
setSize(len + length);
memcpy(data + temp, value, len);
return *this;
}
MString &MString::operator<<(const int value)
{
std::stringstream temp;
temp << value;
*this << temp.str();
return *this;
}
// MString& MString::operator<<(coreutils::ZString &zstring) {
// int temp = length;
// int len = length + zstring.getLength();
// setSize(len);
// memcpy(data + temp, zstring.getData(), zstring.getLength());
// return *this;
// }
MString &MString::operator<<(coreutils::ZString zstring)
{
int temp = length;
int len = length + zstring.getLength();
setSize(len);
memcpy(data + temp, zstring.getData(), zstring.getLength());
return *this;
}
MString &MString::operator<<(std::string value)
{
int temp = length;
int len = length + value.length();
setSize(len);
memcpy(data + temp, value.c_str(), value.length());
return *this;
}
void MString::insert(char ch, int offset)
{
setSize(length + 1);
for (int ix = length; ix >= offset; ix--)
getData()[ix + 1] = getData()[ix];
data[offset] = ch;
}
void MString::insert(ZString &value, int offset)
{
setSize(length + value.getLength());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.getLength()] = getData()[ix];
std::memcpy(data + offset, value.getData(), value.getLength());
}
void MString::insert(std::string value, int offset)
{
setSize(length + value.size());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.size()] = getData()[ix];
std::memcpy(data + offset, value.c_str(), value.size());
}
void MString::replace(char ch, int offset)
{
}
void MString::replace(ZString &value, int offset)
{
}
void MString::replace(std::string value, int offset)
{
}
void MString::remove(int offset, int length)
{
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
for (int ix = offset; ix < this->length; ix++)
getData()[ix] = getData()[ix + length];
setSize(this->length - length);
}
MString &MString::write(char ch)
{
setSize(length + 1);
*(data + length - 1) = ch;
return *this;
}
MString &MString::write(ZString &value)
{
int len = length;
setSize(length + value.getLength());
memcpy(data + len, value.getData(), value.getLength());
return *this;
}
void MString::setSize(int size)
{
int cursorOffset = cursor - data;
int newBufferSize = ((size / 256) + 1) * 256;
if (bufferSize != newBufferSize)
{
bufferSize = newBufferSize;
data = (char *)realloc(data, bufferSize);
cursor = data + cursorOffset;
}
length = size;
}
int MString::offset()
{
return cursor - data;
}
}
+242
View File
@@ -0,0 +1,242 @@
#include "MString.h"
#include "Log.h"
#include "uuid/uuid.h"
#include <cstring>
#include <iomanip>
#include <stdlib.h>
namespace coreutils
{
MString::MString()
{
data = NULL;
length = 0;
cursor = NULL;
}
MString::MString(void *alias)
{
}
MString::MString(const char *data)
{
setSize(strlen(data));
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const MString &mstring)
{
setSize(mstring.length);
memcpy(data, mstring.data, mstring.length);
cursor = data;
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
}
MString::MString(ZString &zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(ZString zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(std::string data)
{
setSize(data.length());
memcpy(this->data, (char *)data.c_str(), data.length());
cursor = this->data;
}
MString::~MString()
{
if (data)
free(data);
}
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
MString &MString::operator=(coreutils::ZString &value)
{
// if(*this == value)
// return *this;
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
return *this;
}
MString &MString::operator=(const char *value)
{
int len = strlen(value);
setSize(len);
memcpy(data, value, len);
return *this;
}
MString &MString::operator=(char value)
{
int len = 1;
setSize(1);
*data = value;
return *this;
}
MString &MString::operator<<(const char *value)
{
int temp = length;
int len = strlen(value);
setSize(len + length);
memcpy(data + temp, value, len);
return *this;
}
MString &MString::operator<<(const int value)
{
std::stringstream temp;
temp << value;
*this << temp.str();
return *this;
}
// MString& MString::operator<<(coreutils::ZString &zstring) {
// int temp = length;
// int len = length + zstring.getLength();
// setSize(len);
// memcpy(data + temp, zstring.getData(), zstring.getLength());
// return *this;
// }
MString &MString::operator<<(coreutils::ZString zstring)
{
int temp = length;
int len = length + zstring.getLength();
setSize(len);
memcpy(data + temp, zstring.getData(), zstring.getLength());
return *this;
}
MString &MString::operator<<(std::string value)
{
int temp = length;
int len = length + value.length();
setSize(len);
memcpy(data + temp, value.c_str(), value.length());
return *this;
}
void MString::insert(char ch, int offset)
{
setSize(length + 1);
for (int ix = length; ix >= offset; ix--)
getData()[ix + 1] = getData()[ix];
data[offset] = ch;
}
void MString::insert(ZString &value, int offset)
{
setSize(length + value.getLength());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.getLength()] = getData()[ix];
std::memcpy(data + offset, value.getData(), value.getLength());
}
void MString::insert(std::string value, int offset)
{
setSize(length + value.size());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.size()] = getData()[ix];
std::memcpy(data + offset, value.c_str(), value.size());
}
void MString::replace(char ch, int offset)
{
}
void MString::replace(ZString &value, int offset)
{
}
void MString::replace(std::string value, int offset)
{
}
void MString::remove(int offset, int length)
{
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
for (int ix = offset; ix < this->length; ix++)
getData()[ix] = getData()[ix + length];
setSize(this->length - length);
}
MString &MString::write(char ch)
{
setSize(length + 1);
*(data + length - 1) = ch;
return *this;
}
MString &MString::write(ZString &value)
{
int len = length;
setSize(length + value.getLength());
memcpy(data + len, value.getData(), value.getLength());
return *this;
}
void MString::setSize(int size)
{
int cursorOffset = cursor - data;
int newBufferSize = ((size / 256) + 1) * 256;
if (bufferSize != newBufferSize)
{
bufferSize = newBufferSize;
data = (char *)realloc(data, bufferSize);
cursor = data + cursorOffset;
}
length = size;
}
int MString::offset()
{
return cursor - data;
}
}
+238
View File
@@ -0,0 +1,238 @@
#include "MString.h"
#include "Log.h"
#include "uuid/uuid.h"
#include <cstring>
#include <iomanip>
#include <stdlib.h>
namespace coreutils
{
MString::MString()
{
data = NULL;
length = 0;
cursor = NULL;
}
MString::MString(const char *data)
{
setSize(strlen(data));
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const char *data, size_t length)
{
setSize(length);
memcpy(this->data, data, length);
cursor = this->data;
}
MString::MString(const MString &mstring)
{
setSize(mstring.length);
memcpy(data, mstring.data, mstring.length);
cursor = data;
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
}
MString::MString(ZString &zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(ZString zstring)
{
setSize(zstring.getLength());
memcpy(data, zstring.getData(), zstring.getLength());
cursor = data;
}
MString::MString(std::string data)
{
setSize(data.length());
memcpy(this->data, (char *)data.c_str(), data.length());
cursor = this->data;
}
MString::~MString()
{
if (data)
free(data);
}
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
// MString& MString::operator=(coreutils::ZString& value) {
// if(*this == value)
// return *this;
// int len = length;
// setSize(length + value.getLength());
// memcpy(data + len, value.getData(), value.getLength());
// return *this;
// }
MString &MString::operator=(coreutils::ZString &value)
{
// if(*this == value)
// return *this;
setSize(value.getLength());
memcpy(data, value.getData(), value.getLength());
length = value.getLength();
return *this;
}
MString &MString::operator=(const char *value)
{
int len = strlen(value);
setSize(len);
memcpy(data, value, len);
return *this;
}
MString &MString::operator=(char value)
{
int len = 1;
setSize(1);
*data = value;
return *this;
}
MString &MString::operator<<(const char *value)
{
int temp = length;
int len = strlen(value);
setSize(len + length);
memcpy(data + temp, value, len);
return *this;
}
MString &MString::operator<<(const int value)
{
std::stringstream temp;
temp << value;
*this << temp.str();
return *this;
}
// MString& MString::operator<<(coreutils::ZString &zstring) {
// int temp = length;
// int len = length + zstring.getLength();
// setSize(len);
// memcpy(data + temp, zstring.getData(), zstring.getLength());
// return *this;
// }
MString &MString::operator<<(coreutils::ZString zstring)
{
int temp = length;
int len = length + zstring.getLength();
setSize(len);
memcpy(data + temp, zstring.getData(), zstring.getLength());
return *this;
}
MString &MString::operator<<(std::string value)
{
int temp = length;
int len = length + value.length();
setSize(len);
memcpy(data + temp, value.c_str(), value.length());
return *this;
}
void MString::insert(char ch, int offset)
{
setSize(length + 1);
for (int ix = length; ix >= offset; ix--)
getData()[ix + 1] = getData()[ix];
data[offset] = ch;
}
void MString::insert(ZString &value, int offset)
{
setSize(length + value.getLength());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.getLength()] = getData()[ix];
std::memcpy(data + offset, value.getData(), value.getLength());
}
void MString::insert(std::string value, int offset)
{
setSize(length + value.size());
for (int ix = length; ix >= offset; ix--)
getData()[ix + value.size()] = getData()[ix];
std::memcpy(data + offset, value.c_str(), value.size());
}
void MString::replace(char ch, int offset)
{
}
void MString::replace(ZString &value, int offset)
{
}
void MString::replace(std::string value, int offset)
{
}
void MString::remove(int offset, int length)
{
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
for (int ix = offset; ix < this->length; ix++)
getData()[ix] = getData()[ix + length];
setSize(this->length - length);
}
MString &MString::write(char ch)
{
setSize(length + 1);
*(data + length - 1) = ch;
return *this;
}
MString &MString::write(ZString &value)
{
int len = length;
setSize(length + value.getLength());
memcpy(data + len, value.getData(), value.getLength());
return *this;
}
void MString::setSize(int size)
{
int cursorOffset = cursor - data;
int newBufferSize = ((size / 256) + 1) * 256;
if (bufferSize != newBufferSize)
{
bufferSize = newBufferSize;
data = (char *)realloc(data, bufferSize);
cursor = data + cursorOffset;
}
length = size;
}
int MString::offset()
{
return cursor - data;
}
}
+379
View File
@@ -0,0 +1,379 @@
#ifndef __ZString_h__
#define __ZString_h__
#include <string.h>
#include <string>
#include <ostream>
#include <vector>
#include <stack>
namespace coreutils {
///
/// Use the ZString object when advanced parsing algorithms are required to simplify
/// parsing. ZString is not a backing store and requires that any referenced buffer
/// or objects are retained throughout the life of the object. Additionally, ZString
/// is non-destructive to its underlying references.
///
/// ZString provides several methods to reference and parse the content. First method
/// is split(ZString delimiter) which will return a vector of ZString which contains
/// references to the parts of the string split by the provided delimiter. The delimiter
/// portion is omitted from the results.
///
/// Second method involves a cursor which is a pointer to data contained within the
/// ZString and is used to point to the current parsing point. Several methods are
/// provided to advance through the parsing based upon content and rule checks.
///
/// During the parsing process you can retrieve the parsed and unparsed sections of
/// the ZString as ZStrings.
///
/// You can stream the ZString to an output stream using the << operator and the entire
/// contents of the ZString will be output regardless of parsing activity.
///
class ZString {
public:
///
/// Consructor providing an empty ZString.
///
ZString();
///
/// Constructor wrapping a null terminated buffer to a ZString.
///
ZString(const char *data);
///
/// Consructor providing the initial setup of the ZString object.
///
ZString(char *data, size_t length);
///
///
///
ZString(const char *data, size_t length);
///
/// Consructor providing a copy of a ZString.
///
ZString(const ZString &zstring);
///
/// Consructor from a string.
///
ZString(std::string &string);
///
/// Consructor from a string.
///
// ZString(std::string string);
///
/// Destructor for the ZString.
///
~ZString();
///
/// A friend method used to write the value of the ZString
/// to an ostream using the << syntax.
///
friend std::ostream& operator<<(std::ostream& os, const ZString& zstring);
friend std::ostream& operator<<(std::ostream& os, const std::string& string);
friend std::ostream& operator+(std::ostream& os, const ZString& zstring);
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);
// bool operator==(std::string value);
// bool operator==(const char *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
/// by using the split method and passing a delimiter value.
///
std::vector<ZString> & getList();
///
/// Return the integer value of the ZString from the cursor to the first
/// non-numeric character.
///
int asInteger();
///
///
///
int incrementCursor(int length);
///
/// Use the push method to push the current cursor pointer to a stack.
///
void push();
///
/// Use the pop method to pop a previously pushed cursor pointer from the
/// cursor stack. The cursor will point to the same location in the
/// ZString where the cursor was pushed.
///
void pop();
///
/// Return the value of the ZString from the cursor to the end.
///
std::string str();
///
/// Return the current value of the ZString as a string of
/// specified length.
///
std::string str(int len);
///
///
///
char* c_str();
///
///
///
ZString substring(int start);
///
///
///
ZString substring(int start, int len);
///
///
///
std::vector<ZString> &split(ZString &delimiter, size_t maxSize = 0);
///
///
///
std::vector<ZString> &split(std::string delimiter, size_t maxSize = 0);
///
/// Use getTokenInclude with a list of character to allow the forwarding
/// of the cursor through the data until a character that is not in the
/// include string is not encountered in the ZString data.
///
ZString getTokenInclude(const char *include);
///
///
///
ZString getTokenExclude(const char *exclude);
///
///
///
ZString getTokenExclude(std::string exclude);
///
/// If the cursor is over a container character then a call to this method
/// will return the contents of the container. The cursor will remain at
/// the position following the container.
///
ZString getContainer();
///
/// Use the [] operator to retrieve values delimited by the split method.
///
ZString &operator[](int index);
///
/// Return true if the ZString cursor is at the end of the data.
///
bool eod();
///
///
///
bool startsWith(const char *value);
///
///
///
bool equals(const char *value);
///
///
///
bool equals(char *value);
///
///
///
bool equals(ZString &zstring);
///
///
///
bool equals(std::string &string);
///
/// Advance the cursor the length of the provided value if the value at
/// the cursor position is equal to the value provided.
///
bool ifNext(const char *value);
///
///
///
bool ifNext(ZString &value);
///
///
///
int ifEqualsCount(ZString &comparator);
///
/// Advance the cursor through the ZString for each whitespace character
/// encountered.
///
int skipWhitespace();
///
///
///
ZString goeol();
///
/// Return a block of data as a ZString from the cursor location for
/// the number of bytes specified by size.
///
ZString readBlock(size_t size);
///
/// Return a pointer to the beginning of the ZString data.
///
char* getData();
///
///
///
char* getCursor();
///
///
///
void setCursor(char *cursor);
///
/// Return the length of the ZString.
///
size_t getLength();
///
/// Set this ZString to have the same data space as the ZString pointer
/// passed into the method.
///
void setZString(ZString zstring);
///
/// Use the parsed method to return a ZString that represents the portion
/// ZString that has been parsed. The returned ZString represents the
/// portion of the ZString from the data pointer to the cursor.
///
ZString parsed();
///
///
///
ZString unparsed();
///
///
///
void reset();
///
///
///
char charAt(int index);
///
///
///
bool ifCRLF();
void nextChar();
protected:
char *data;
char *cursor;
size_t length;
char *cdata = NULL;
std::vector<ZString> list;
private:
std::stack<char *> stack;
bool isCharacter(char ch, const char *string);
};
}
#endif
+379
View File
@@ -0,0 +1,379 @@
#ifndef __ZString_h__
#define __ZString_h__
#include <ostream>
#include <stack>
#include <string.h>
#include <string>
#include <vector>
namespace coreutils
{
///
/// Use the ZString object when advanced parsing algorithms are required to simplify
/// parsing. ZString is not a backing store and requires that any referenced buffer
/// or objects are retained throughout the life of the object. Additionally, ZString
/// is non-destructive to its underlying references.
///
/// ZString provides several methods to reference and parse the content. First method
/// is split(ZString delimiter) which will return a vector of ZString which contains
/// references to the parts of the string split by the provided delimiter. The delimiter
/// portion is omitted from the results.
///
/// Second method involves a cursor which is a pointer to data contained within the
/// ZString and is used to point to the current parsing point. Several methods are
/// provided to advance through the parsing based upon content and rule checks.
///
/// During the parsing process you can retrieve the parsed and unparsed sections of
/// the ZString as ZStrings.
///
/// You can stream the ZString to an output stream using the << operator and the entire
/// contents of the ZString will be output regardless of parsing activity.
///
class ZString
{
public:
///
/// Consructor providing an empty ZString.
///
ZString();
///
/// Constructor wrapping a null terminated buffer to a ZString.
///
ZString(const char *data);
///
/// Consructor providing the initial setup of the ZString object.
///
ZString(char *data, size_t length);
///
///
///
ZString(const char *data, size_t length);
///
/// Consructor providing a copy of a ZString.
///
ZString(const ZString &zstring);
///
/// Consructor from a string.
///
ZString(std::string &string);
///
/// Consructor from a string.
///
// ZString(std::string string);
///
/// Destructor for the ZString.
///
~ZString();
///
/// A friend method used to write the value of the ZString
/// to an ostream using the << syntax.
///
friend std::ostream &operator<<(std::ostream &os, const ZString &zstring);
friend std::ostream &operator<<(std::ostream &os, const std::string &string);
friend std::ostream &operator+(std::ostream &os, const ZString &zstring);
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);
// bool operator==(std::string value);
// bool operator==(const char *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
/// by using the split method and passing a delimiter value.
///
std::vector<ZString> &getList();
///
/// Return the integer value of the ZString from the cursor to the first
/// non-numeric character.
///
int asInteger();
///
///
///
int incrementCursor(int length);
///
/// Use the push method to push the current cursor pointer to a stack.
///
void push();
///
/// Use the pop method to pop a previously pushed cursor pointer from the
/// cursor stack. The cursor will point to the same location in the
/// ZString where the cursor was pushed.
///
void pop();
///
/// Return the value of the ZString from the cursor to the end.
///
std::string str();
///
/// Return the current value of the ZString as a string of
/// specified length.
///
std::string str(int len);
///
///
///
char *c_str();
///
///
///
ZString substring(int start);
///
///
///
ZString substring(int start, int len);
///
///
///
std::vector<ZString> &split(ZString &delimiter, size_t maxSize = 0);
///
///
///
std::vector<ZString> &split(std::string delimiter, size_t maxSize = 0);
///
/// Use getTokenInclude with a list of character to allow the forwarding
/// of the cursor through the data until a character that is not in the
/// include string is not encountered in the ZString data.
///
ZString getTokenInclude(const char *include);
///
///
///
ZString getTokenExclude(const char *exclude);
///
///
///
ZString getTokenExclude(std::string exclude);
///
/// If the cursor is over a container character then a call to this method
/// will return the contents of the container. The cursor will remain at
/// the position following the container.
///
ZString getContainer();
///
/// Use the [] operator to retrieve values delimited by the split method.
///
ZString &operator[](int index);
///
/// Return true if the ZString cursor is at the end of the data.
///
bool eod();
///
///
///
bool startsWith(const char *value);
///
///
///
bool equals(const char *value);
///
///
///
bool equals(char *value);
///
///
///
bool equals(ZString &zstring);
///
///
///
bool equals(std::string &string);
///
/// Advance the cursor the length of the provided value if the value at
/// the cursor position is equal to the value provided.
///
bool ifNext(const char *value);
///
///
///
bool ifNext(ZString &value);
///
///
///
int ifEqualsCount(ZString &comparator);
///
/// Advance the cursor through the ZString for each whitespace character
/// encountered.
///
int skipWhitespace();
///
///
///
ZString goeol();
///
/// Return a block of data as a ZString from the cursor location for
/// the number of bytes specified by size.
///
ZString readBlock(size_t size);
///
/// Return a pointer to the beginning of the ZString data.
///
char *getData();
///
///
///
char *getCursor();
///
///
///
void setCursor(char *cursor);
///
/// Return the length of the ZString.
///
size_t getLength();
///
/// Set this ZString to have the same data space as the ZString pointer
/// passed into the method.
///
void setZString(ZString zstring);
///
/// Use the parsed method to return a ZString that represents the portion
/// ZString that has been parsed. The returned ZString represents the
/// portion of the ZString from the data pointer to the cursor.
///
ZString parsed();
///
///
///
ZString unparsed();
///
///
///
void reset();
///
///
///
char charAt(int index);
///
///
///
bool ifCRLF();
void nextChar();
protected:
char *data;
char *cursor;
size_t length;
char *cdata = NULL;
std::vector<ZString> list;
private:
std::stack<char *> stack;
bool isCharacter(char ch, const char *string);
};
}
#endif