MString edebugged.
This commit is contained in:
parent
b25650c5a7
commit
e411d31cb6
31
MString.cpp
31
MString.cpp
@ -2,6 +2,7 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
namespace coreutils {
|
namespace coreutils {
|
||||||
|
|
||||||
@ -12,32 +13,26 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MString::MString(const char *data) {
|
MString::MString(const char *data) {
|
||||||
this->length = strlen(data);
|
setSize(strlen(data));
|
||||||
setSize(this->length);
|
|
||||||
this->data = (char *)malloc(bufferSize);
|
|
||||||
memcpy(this->data, data, length);
|
memcpy(this->data, data, length);
|
||||||
cursor = this->data;
|
cursor = this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
MString::MString(char *data, size_t length) {
|
MString::MString(char *data, size_t length) {
|
||||||
this->length = length;
|
|
||||||
setSize(length);
|
setSize(length);
|
||||||
memcpy(this->data, data, length);
|
memcpy(this->data, data, length);
|
||||||
cursor = this->data;
|
cursor = this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
MString::MString(const char *data, size_t length) {
|
MString::MString(const char *data, size_t length) {
|
||||||
this->length = length;
|
|
||||||
setSize(length);
|
setSize(length);
|
||||||
memcpy(this->data, data, length);
|
memcpy(this->data, data, length);
|
||||||
cursor = this->data;
|
cursor = this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
MString::MString(const MString &mstring) {
|
MString::MString(const MString &mstring) {
|
||||||
bufferSize = (mstring.length % 256) + 256;
|
setSize(mstring.length);
|
||||||
data = (char *)malloc(bufferSize);
|
|
||||||
memcpy(data, mstring.data, mstring.length);
|
memcpy(data, mstring.data, mstring.length);
|
||||||
length = mstring.length;
|
|
||||||
cursor = data;
|
cursor = data;
|
||||||
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
|
// Log(LOG_DEBUG_2) << "MString Copy Constructor: ";
|
||||||
}
|
}
|
||||||
@ -45,7 +40,6 @@ namespace coreutils {
|
|||||||
MString::MString(std::string data) {
|
MString::MString(std::string data) {
|
||||||
setSize(data.length());
|
setSize(data.length());
|
||||||
memcpy(this->data, (char *)data.c_str(), data.length());
|
memcpy(this->data, (char *)data.c_str(), data.length());
|
||||||
length = data.length();
|
|
||||||
cursor = this->data;
|
cursor = this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,21 +49,26 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int MString::write(char ch) {
|
int MString::write(char ch) {
|
||||||
setSize(bufferSize + 1);
|
setSize(length + 1);
|
||||||
data[length++] = ch;
|
*(data + length - 1) = ch;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MString::write(ZString &value) {
|
int MString::write(ZString &value) {
|
||||||
setSize(bufferSize + value.getLength());
|
int len = length;
|
||||||
memcpy(data, value.getData(), value.getLength());
|
setSize(length + value.getLength());
|
||||||
length += value.getLength();
|
memcpy(data + len, value.getData(), value.getLength());
|
||||||
return value.getLength();
|
return value.getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MString::setSize(int size) {
|
void MString::setSize(int size) {
|
||||||
bufferSize = (size % 256) + 256;
|
int cursorOffset = cursor - data;
|
||||||
data = (char *)realloc(data, bufferSize);
|
int newBufferSize = ((size / 256) + 1) * 256;
|
||||||
|
if(bufferSize != newBufferSize) {
|
||||||
|
bufferSize = newBufferSize;
|
||||||
|
data = (char *)realloc(data, bufferSize);
|
||||||
|
cursor = data + cursorOffset;
|
||||||
|
}
|
||||||
length = size;
|
length = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +82,15 @@ namespace coreutils {
|
|||||||
return cursor - temp;
|
return cursor - temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ZString::push() {
|
||||||
|
stack.push(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZString::pop() {
|
||||||
|
cursor = stack.top();
|
||||||
|
stack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
std::string ZString::str()
|
std::string ZString::str()
|
||||||
{
|
{
|
||||||
return std::string(data, length);
|
return std::string(data, length);
|
||||||
|
18
ZString.h
18
ZString.h
@ -6,6 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
namespace coreutils {
|
namespace coreutils {
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ namespace coreutils {
|
|||||||
/// During the parsing process you can retrieve the parsed and unparsed sections of
|
/// During the parsing process you can retrieve the parsed and unparsed sections of
|
||||||
/// the ZString as ZStrings.
|
/// the ZString as ZStrings.
|
||||||
///
|
///
|
||||||
/// You can stream the ZString to an output stream usinf the << operator and the entire
|
/// 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.
|
/// contents of the ZString will be output regardless of parsing activity.
|
||||||
///
|
///
|
||||||
|
|
||||||
@ -100,6 +101,20 @@ namespace coreutils {
|
|||||||
|
|
||||||
int incrementCursor(int length);
|
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.
|
/// Return the value of the ZString from the cursor to the end.
|
||||||
///
|
///
|
||||||
@ -282,6 +297,7 @@ namespace coreutils {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<ZString> list;
|
std::vector<ZString> list;
|
||||||
|
std::stack<char *> stack;
|
||||||
bool isCharacter(char ch, const char *string);
|
bool isCharacter(char ch, const char *string);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user