merge
This commit is contained in:
commit
badfc4c709
@ -12,7 +12,7 @@ namespace coreutils {
|
|||||||
else
|
else
|
||||||
this->errorNumber = errorNumber;
|
this->errorNumber = errorNumber;
|
||||||
|
|
||||||
Log(LOG_EXCEPT) << text;
|
Log(LOG_EXCEPT) << text << "(" << file << ":" << line << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,19 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
namespace coreutils {
|
namespace coreutils {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use an Exception oject whenever you want to throw an error for an exception condition
|
||||||
|
/// to your calling stack to inform the program of the condition.
|
||||||
|
///
|
||||||
|
|
||||||
class Exception {
|
class Exception {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Exception(std::string text, std::string file = __FILE__, int line = __LINE__, int errorNumber = -1);
|
Exception(std::string text, std::string file = __FILE__, int line = __LINE__, int errorNumber = errno);
|
||||||
|
|
||||||
std::string className;
|
std::string className;
|
||||||
std::string file;
|
std::string file;
|
||||||
|
10
JString.cpp
10
JString.cpp
@ -36,6 +36,8 @@ namespace coreutils {
|
|||||||
if(locate(path)) {
|
if(locate(path)) {
|
||||||
if(ifNext("\""))
|
if(ifNext("\""))
|
||||||
return getTokenExclude("\"");
|
return getTokenExclude("\"");
|
||||||
|
// TODO: Handle numbers that are not in double quotes.
|
||||||
|
|
||||||
if(startsWith("[")) {
|
if(startsWith("[")) {
|
||||||
ZString temp = getContainer();
|
ZString temp = getContainer();
|
||||||
std::cout << temp << std::endl;
|
std::cout << temp << std::endl;
|
||||||
@ -45,6 +47,7 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void JString::operator=(ZString &value) {
|
void JString::operator=(ZString &value) {
|
||||||
|
std::cout << "operator=(ZString &)" << value << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
JString& JString::operator=(const char *value) {
|
JString& JString::operator=(const char *value) {
|
||||||
@ -84,11 +87,14 @@ namespace coreutils {
|
|||||||
if(ifNext(":")) {
|
if(ifNext(":")) {
|
||||||
if(label == path[0]) {
|
if(label == path[0]) {
|
||||||
if(path.getList().size() == 1)
|
if(path.getList().size() == 1)
|
||||||
return true;
|
{
|
||||||
|
std::cout << "cursor: " << unparsed() << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return locate(path[1]);
|
return locate(path[1]);
|
||||||
} if(startsWith("\"")) {
|
} if(startsWith("\"")) {
|
||||||
getContainer();;
|
getContainer();;
|
||||||
} else if(startsWith("[")) {
|
} else if(startsWith("[")) {
|
||||||
getContainer();
|
getContainer();
|
||||||
} else {
|
} else {
|
||||||
throw coreutils::Exception("Unrecognized data type.");
|
throw coreutils::Exception("Unrecognized data type.");
|
||||||
|
15
JString.h
15
JString.h
@ -13,6 +13,20 @@ namespace coreutils {
|
|||||||
/// The [] operator is overriden from the ZString and provides a method to
|
/// The [] operator is overriden from the ZString and provides a method to
|
||||||
/// access the objects elements using a named path as the index to the items.
|
/// access the objects elements using a named path as the index to the items.
|
||||||
///
|
///
|
||||||
|
/// JString default constructor will create an empty JString object pointing
|
||||||
|
/// to an empty string.
|
||||||
|
///
|
||||||
|
/// Use a constructor or assignment operator to initialize a JString to an
|
||||||
|
/// initial JSON string.
|
||||||
|
///
|
||||||
|
/// Several constructors are available including a handle to a std::FILE
|
||||||
|
/// object to initialize the JSON string. On destruction the file is saved back.
|
||||||
|
///
|
||||||
|
/// The [] operator can be used to access elements within the JSON string.
|
||||||
|
/// Use:
|
||||||
|
/// jstring["key"] = "value";
|
||||||
|
/// std::cout << jstring["key"];
|
||||||
|
///
|
||||||
|
|
||||||
class JString : public MString {
|
class JString : public MString {
|
||||||
|
|
||||||
@ -34,7 +48,6 @@ namespace coreutils {
|
|||||||
void operator=(ZString &value);
|
void operator=(ZString &value);
|
||||||
JString& operator=(const char *value);
|
JString& operator=(const char *value);
|
||||||
|
|
||||||
// ZString operator[](const char *path);
|
|
||||||
JString& operator[](const char *path);
|
JString& operator[](const char *path);
|
||||||
// operator const ZString () const {
|
// operator const ZString () const {
|
||||||
// return *this;
|
// return *this;
|
||||||
|
2
Log.cpp
2
Log.cpp
@ -81,7 +81,7 @@ namespace coreutils {
|
|||||||
if (logFile)
|
if (logFile)
|
||||||
logFile->write(out.str());
|
logFile->write(out.str());
|
||||||
|
|
||||||
std::cout << out.str();
|
// std::cout << out.str();
|
||||||
++seq;
|
++seq;
|
||||||
|
|
||||||
mtx.unlock();
|
mtx.unlock();
|
||||||
|
34
MString.cpp
34
MString.cpp
@ -29,6 +29,13 @@ namespace coreutils
|
|||||||
cursor = this->data;
|
cursor = this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MString::MString(unsigned char *data, size_t length)
|
||||||
|
{
|
||||||
|
setSize(length);
|
||||||
|
memcpy(this->data, data, length);
|
||||||
|
cursor = this->data;
|
||||||
|
}
|
||||||
|
|
||||||
MString::MString(const char *data, size_t length)
|
MString::MString(const char *data, size_t length)
|
||||||
{
|
{
|
||||||
setSize(length);
|
setSize(length);
|
||||||
@ -65,34 +72,21 @@ namespace coreutils
|
|||||||
cursor = this->data;
|
cursor = this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MString::MString(std::FILE *file)
|
||||||
|
{
|
||||||
|
setSize(1000000);
|
||||||
|
this->length = fread(this->data, 1000000, 1000000, file);
|
||||||
|
cursor = this->data;
|
||||||
|
}
|
||||||
|
|
||||||
MString::~MString()
|
MString::~MString()
|
||||||
{
|
{
|
||||||
if (data)
|
if (data)
|
||||||
free(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)
|
MString &MString::operator=(coreutils::ZString &value)
|
||||||
{
|
{
|
||||||
// if(*this == value)
|
|
||||||
// return *this;
|
|
||||||
setSize(value.getLength());
|
setSize(value.getLength());
|
||||||
memcpy(data, value.getData(), value.getLength());
|
memcpy(data, value.getData(), value.getLength());
|
||||||
length = value.getLength();
|
length = value.getLength();
|
||||||
|
22
MString.h
22
MString.h
@ -35,10 +35,16 @@ namespace coreutils
|
|||||||
/// Consructor providing the initial setup of the MString object.
|
/// Consructor providing the initial setup of the MString object.
|
||||||
///
|
///
|
||||||
|
|
||||||
MString(char *data, size_t length);
|
MString(unsigned char *data, size_t length);
|
||||||
|
|
||||||
MString(const char *data, size_t length);
|
MString(const char *data, size_t length);
|
||||||
|
|
||||||
|
MString(const unsigned char *data, size_t length);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Consructor providing a copy of a ZString.
|
||||||
|
///
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Consructor providing a copy of a ZString.
|
/// Consructor providing a copy of a ZString.
|
||||||
///
|
///
|
||||||
@ -56,8 +62,20 @@ namespace coreutils
|
|||||||
///
|
///
|
||||||
/// Consructor from a string.
|
/// Consructor from a string.
|
||||||
///
|
///
|
||||||
|
|
||||||
MString(std::string data);
|
MString(std::string data);
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
|
MString(char *data, size_t length);
|
||||||
|
|
||||||
|
MString(std::FILE *file);
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual ~MString();
|
||||||
|
|
||||||
~MString();
|
~MString();
|
||||||
|
|
||||||
|
41
ZString.cpp
41
ZString.cpp
@ -36,8 +36,12 @@ namespace coreutils {
|
|||||||
|
|
||||||
ZString::ZString(char *data, size_t length) : data(data), length(length), cursor(data) {}
|
ZString::ZString(char *data, size_t length) : data(data), length(length), cursor(data) {}
|
||||||
|
|
||||||
|
ZString::ZString(unsigned char *data, size_t length) : data((char *)data), length(length), cursor((char *)data) {}
|
||||||
|
|
||||||
ZString::ZString(const char *data, size_t length) : data((char *)data), length(length), cursor((char *)data) {}
|
ZString::ZString(const char *data, size_t length) : data((char *)data), length(length), cursor((char *)data) {}
|
||||||
|
|
||||||
|
ZString::ZString(const unsigned 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;
|
data = zstring.data;
|
||||||
length = zstring.length;
|
length = zstring.length;
|
||||||
@ -326,7 +330,25 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
return ZString(temp, tempend - temp);
|
return ZString(temp, tempend - temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ZString::find(ZString comparator) {
|
||||||
|
int count = 0;
|
||||||
|
char *temp = cursor;
|
||||||
|
char *temp2 = cursor;
|
||||||
|
while(!ifNext(comparator)) {
|
||||||
|
++count;
|
||||||
|
++cursor;
|
||||||
|
++temp2;
|
||||||
|
if(cursor > (data + length)) {
|
||||||
|
cursor = temp;
|
||||||
|
count = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cursor = temp2;
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
ZString ZString::readBlock(size_t size) {
|
ZString ZString::readBlock(size_t size) {
|
||||||
char *temp = cursor;
|
char *temp = cursor;
|
||||||
cursor += size;
|
cursor += size;
|
||||||
@ -356,7 +378,7 @@ namespace coreutils {
|
|||||||
length = zstring.getLength();
|
length = zstring.getLength();
|
||||||
cursor = data;
|
cursor = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZString ZString::parsed() {
|
ZString ZString::parsed() {
|
||||||
return ZString(data, cursor - data);
|
return ZString(data, cursor - data);
|
||||||
}
|
}
|
||||||
@ -380,10 +402,21 @@ namespace coreutils {
|
|||||||
if (*(data + length - 1) == '\r')
|
if (*(data + length - 1) == '\r')
|
||||||
--length;
|
--length;
|
||||||
if (cursor >= (data + length))
|
if (cursor >= (data + length))
|
||||||
cursor = data + length;
|
cursor = data + length;
|
||||||
return len != length;
|
return len != length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ZString::boolValue() {
|
||||||
|
if(this->equals("false"))
|
||||||
|
return false;
|
||||||
|
else if(this->equals("0"))
|
||||||
|
return false;
|
||||||
|
else if(this->equals(""))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ZString::nextChar() {
|
void ZString::nextChar() {
|
||||||
if(!eod())
|
if(!eod())
|
||||||
++cursor;
|
++cursor;
|
||||||
|
39
ZString.h
39
ZString.h
@ -60,14 +60,18 @@ namespace coreutils
|
|||||||
|
|
||||||
ZString(const char *data, size_t length);
|
ZString(const char *data, size_t length);
|
||||||
|
|
||||||
|
ZString(unsigned char *data, size_t length);
|
||||||
|
|
||||||
|
///
|
||||||
///
|
///
|
||||||
/// Consructor providing a copy of a ZString.
|
|
||||||
///
|
///
|
||||||
|
|
||||||
ZString(const ZString &zstring);
|
ZString(const ZString &zstring);
|
||||||
|
|
||||||
|
ZString(const unsigned char *data, size_t length);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Consructor from a string.
|
/// Consructor providing a copy of a ZString.
|
||||||
///
|
///
|
||||||
|
|
||||||
ZString(std::string &string);
|
ZString(std::string &string);
|
||||||
@ -95,7 +99,8 @@ namespace coreutils
|
|||||||
friend std::ostream &operator+(std::ostream &os, const char *value);
|
friend std::ostream &operator+(std::ostream &os, const char *value);
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
/// A friend method used to write the value of the ZString
|
||||||
|
/// to an ostream using the << syntax.
|
||||||
///
|
///
|
||||||
|
|
||||||
bool operator<(const ZString &valuex) const;
|
bool operator<(const ZString &valuex) const;
|
||||||
@ -298,7 +303,14 @@ namespace coreutils
|
|||||||
ZString readBlock(size_t size);
|
ZString readBlock(size_t size);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Return a pointer to the beginning of the ZString data.
|
///
|
||||||
|
///
|
||||||
|
|
||||||
|
int find(ZString comparator);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Return a block of data as a ZString from the cursor location for
|
||||||
|
/// the number of bytes specified by size.
|
||||||
///
|
///
|
||||||
|
|
||||||
char *getData();
|
char *getData();
|
||||||
@ -362,6 +374,25 @@ namespace coreutils
|
|||||||
|
|
||||||
void nextChar();
|
void nextChar();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
char *data;
|
||||||
|
char *cursor;
|
||||||
|
size_t length;
|
||||||
|
char *cdata = NULL;
|
||||||
|
std::vector<ZString> list;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
|
bool boolValue();
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
|
void nextChar();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
char *data;
|
char *data;
|
||||||
char *cursor;
|
char *cursor;
|
||||||
|
@ -17,16 +17,19 @@ int main(int argc, char **argv) {
|
|||||||
// std::cout << test1 << std::endl;
|
// std::cout << test1 << std::endl;
|
||||||
|
|
||||||
coreutils::JString test2("{\"key1\":[{\"id\":\"1\",\"name\":\"Brad\"},{\"id\":\"2\",\"name\":\"Jenn\"},{\"id\":\"3\",\"name\":\"Skye\"}],\"key2\":\"data5\",\"key3\":\"data3\",\"key4\":\"data4\"}");
|
coreutils::JString test2("{\"key1\":[{\"id\":\"1\",\"name\":\"Brad\"},{\"id\":\"2\",\"name\":\"Jenn\"},{\"id\":\"3\",\"name\":\"Skye\"}],\"key2\":\"data5\",\"key3\":\"data3\",\"key4\":\"data4\"}");
|
||||||
|
std::cout << test2 << std::endl;
|
||||||
|
std::cout << "--------" << std::endl;
|
||||||
// std::cout << test2["key2"] << std::endl;
|
// std::cout << test2["key2"] << std::endl;
|
||||||
// std::cout << test2["key1"] << std::endl;
|
// std::cout << test2["key1"] << std::endl;
|
||||||
// std::cout << "value: " << test2["key1.name[id=2]"] << std::endl;
|
// std::cout << "value: " << test2["key1.name[id=2]"] << std::endl;
|
||||||
// std::cout << "value: " << test2["key1.name[id=3]"] << std::endl;
|
// std::cout << "value: " << test2["key1.name[id=3]"] << std::endl;
|
||||||
|
|
||||||
test2["key2"] = "newvalue1";
|
test2["key2"] = "newvalue1";
|
||||||
std::cout << test2["key2"] << std::endl;
|
std::cout << "--------" << std::endl;
|
||||||
// test2 = "newvalue";
|
// test2 = "newvalue";
|
||||||
std::cout << test2 << std::endl;
|
std::cout << test2 << std::endl;
|
||||||
|
std::cout << "--------" << std::endl;
|
||||||
|
std::cout << "key2: " << test2["key2"] << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../MString.h"
|
#include "../MString.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
// Literal string assignment tests.
|
// Literal string assignment tests.
|
||||||
coreutils::MString test1 = "this is an assignment test.";
|
coreutils::MString test1 = "this is an assignment test.";
|
||||||
std::cout << "char * operator=: [" << test1 << "]." << std::endl;
|
std::cout << "char * operator=: [" << test1 << "]." << std::endl;
|
||||||
test1 = "new value.";
|
test1 = "new value.";
|
||||||
std::cout << "char * operator=: [" << test1 << "]." << std::endl;
|
std::cout << "char * operator=: [" << test1 << "]." << std::endl;
|
||||||
|
std::string test11 = "this is a test";
|
||||||
|
coreutils::MString test12 = test11;
|
||||||
|
std::cout << "assign from std::string: [" << test12 << "]." << std::endl;
|
||||||
|
|
||||||
coreutils::MString test2("this is another test.");
|
coreutils::MString test2("this is another test.");
|
||||||
std::cout << "assign on constructor: [" << test2 << "]." << std::endl;
|
std::cout << "assign on constructor: [" << test2 << "]." << std::endl;
|
||||||
@ -28,22 +31,31 @@ int main(int argc, char **argv) {
|
|||||||
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
||||||
test4 << "another test " << 75;
|
test4 << "another test " << 75;
|
||||||
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
||||||
|
|
||||||
// Stream assignment capabilities.
|
// Stream assignment capabilities.
|
||||||
coreutils::MString test6;
|
coreutils::MString test6;
|
||||||
int number = 75;
|
int number = 75;
|
||||||
test6 << "Will this work? " << number << test4 << " See how this works.";
|
test6 << "Will this work? " << number << test4 << " See how this works.";
|
||||||
std::cout << "streaming: [" << test6 << "]." << std::endl;
|
std::cout << "streaming: [" << test6 << "]." << std::endl;
|
||||||
|
std::string test13 = "stream from string test";
|
||||||
|
coreutils::MString test14;
|
||||||
|
test14 << test13;
|
||||||
|
std::cout << "streaming from std::string: [" << test14 << "]." << std::endl;
|
||||||
|
|
||||||
coreutils::MString test9("XXXXXXXXXYYYYYYYYYY");
|
coreutils::MString test9("XXXXXXXXXYYYYYYYYYY");
|
||||||
std::cout << "test insert: " << test9 << std::endl;
|
std::cout << "test insert: " << test9 << std::endl;
|
||||||
coreutils::MString test8("zzz");
|
coreutils::MString test8("zzz");
|
||||||
test9.insert(test8, 9);
|
test9.insert(test8, 9);
|
||||||
std::cout << "inserting: " << test9 << std::endl;
|
|
||||||
test9.insert("aaaaa", 9);
|
test9.insert("aaaaa", 9);
|
||||||
std::cout << "inserting: " << test9 << std::endl;
|
std::cout << "inserting: " << test9 << std::endl;
|
||||||
test9.remove(10, 7);
|
test9.remove(10, 7);
|
||||||
std::cout << "removing: " << test9 << std::endl;
|
std::cout << "removing: " << test9 << std::endl;
|
||||||
|
|
||||||
|
// Reassignments.
|
||||||
|
|
||||||
|
coreutils::MString test10;
|
||||||
|
test10 = "";
|
||||||
|
std::cout << test10 << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -38,5 +38,10 @@ int main(int argc, char **argv) {
|
|||||||
test4.getTokenExclude("(");
|
test4.getTokenExclude("(");
|
||||||
std::cout << "container: " << test4.getContainer() << std::endl;
|
std::cout << "container: " << test4.getContainer() << std::endl;
|
||||||
std::cout << "rest: " << test4.unparsed() << std::endl;
|
std::cout << "rest: " << test4.unparsed() << std::endl;
|
||||||
|
|
||||||
|
// Test find();
|
||||||
|
coreutils::ZString testA("this is a test string for MX 250xyzabc");
|
||||||
|
std::cout << "find MX: " << testA.find("MX") << std::endl;
|
||||||
|
std::cout << "unparsed: " << testA.unparsed() << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user