Serious work on JString and some minor MString ajustments.
This commit is contained in:
parent
7531c885a7
commit
c6e0486c14
33
JString.cpp
33
JString.cpp
@ -21,7 +21,12 @@ namespace coreutils {
|
|||||||
pop();
|
pop();
|
||||||
remove(offset(), old.getLength() + 2);
|
remove(offset(), old.getLength() + 2);
|
||||||
MString key;
|
MString key;
|
||||||
key << "\"" << value << "\"";
|
if(value.startsWith("["))
|
||||||
|
key << value;
|
||||||
|
else if(value.startsWith("{"))
|
||||||
|
key << value;
|
||||||
|
else
|
||||||
|
key << "\"" << value << "\"";
|
||||||
insert(key, offset());
|
insert(key, offset());
|
||||||
} else {
|
} else {
|
||||||
pop();
|
pop();
|
||||||
@ -32,17 +37,13 @@ namespace coreutils {
|
|||||||
MString key;
|
MString key;
|
||||||
if(notfirst)
|
if(notfirst)
|
||||||
key << ",";
|
key << ",";
|
||||||
|
|
||||||
// TODO: The value added must be parsed down to remove all whitespace.
|
// TODO: The value added must be parsed down to remove all whitespace.
|
||||||
value.push();
|
|
||||||
value.skipWhitespace();
|
|
||||||
if(value.startsWith("["))
|
if(value.startsWith("["))
|
||||||
key << "\"" << path << "\":" << value;
|
key << "\"" << path << "\":" << value;
|
||||||
else if(value.startsWith("{"))
|
else if(value.startsWith("{"))
|
||||||
key << "\"" << path << "\":" << value;
|
key << "\"" << path << "\":" << value;
|
||||||
else
|
else
|
||||||
key << "\"" << path << "\":" << "\"" << value << "\"";
|
key << "\"" << path << "\":" << "\"" << value << "\"";
|
||||||
value.pop();
|
|
||||||
insert(key, offset());
|
insert(key, offset());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,9 +65,24 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool JString::locate(ZString &path) {
|
bool JString::locate(ZString &path) {
|
||||||
|
std::cout << "path locate: " << path << std::endl;
|
||||||
path.split(".", 1);
|
path.split(".", 1);
|
||||||
|
ZString pathx = path[0].getTokenExclude("[");
|
||||||
|
ZString index;
|
||||||
|
if(path[0].ifNext("[")) {
|
||||||
|
index = path[0].getTokenExclude("]");
|
||||||
|
if(path[0].ifNext("]")) {
|
||||||
|
// TODO: index value here
|
||||||
|
std::cout << ":::" << pathx << ":" << index << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
pathx = path[0];
|
||||||
|
pathx.reset();
|
||||||
|
index.reset();
|
||||||
|
path[0].reset();
|
||||||
notfirst = false;
|
notfirst = false;
|
||||||
if(ifNext("{")) {
|
if(ifNext("{")) {
|
||||||
while(startsWith("\"")) {
|
while(startsWith("\"")) {
|
||||||
notfirst = true;
|
notfirst = true;
|
||||||
ZString label;
|
ZString label;
|
||||||
@ -77,9 +93,10 @@ namespace coreutils {
|
|||||||
} else
|
} else
|
||||||
throw coreutils::Exception("Labels must be contained in double quotes.");
|
throw coreutils::Exception("Labels must be contained in double quotes.");
|
||||||
if(ifNext(":")) {
|
if(ifNext(":")) {
|
||||||
if(label == path[0]) {
|
// std::cout << "path: (" << pathx << ") " << label << std::endl;
|
||||||
|
if(label == pathx) {
|
||||||
if(path.getList().size() == 1) {
|
if(path.getList().size() == 1) {
|
||||||
// std::cout << "found cursor: " << unparsed() << std::endl;
|
std::cout << "found cursor: " << unparsed() << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return locate(path[1]);
|
return locate(path[1]);
|
||||||
|
@ -83,7 +83,9 @@ namespace coreutils {
|
|||||||
|
|
||||||
JString & operator=(coreutils:: ZString value) {
|
JString & operator=(coreutils:: ZString value) {
|
||||||
std::cout << "operator=" << value << std::endl;
|
std::cout << "operator=" << value << std::endl;
|
||||||
|
setSize(value.getLength());
|
||||||
|
memcpy(data, value.getData(), value.getLength());
|
||||||
|
length = value.getLength();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,6 +258,7 @@ namespace coreutils {
|
|||||||
int newBufferSize = ((size / 256) + 1) * 256;
|
int newBufferSize = ((size / 256) + 1) * 256;
|
||||||
if (bufferSize != newBufferSize) {
|
if (bufferSize != newBufferSize) {
|
||||||
bufferSize = newBufferSize;
|
bufferSize = newBufferSize;
|
||||||
|
std::cout << "Adjusting storage size to " << bufferSize << " to accomodate " << size << "bytes." << std::endl;
|
||||||
data = (char *)realloc(data, bufferSize);
|
data = (char *)realloc(data, bufferSize);
|
||||||
cursor = data + cursorOffset;
|
cursor = data + cursorOffset;
|
||||||
}
|
}
|
||||||
|
@ -227,10 +227,12 @@ namespace coreutils {
|
|||||||
MString &read(int fd);
|
MString &read(int fd);
|
||||||
|
|
||||||
int offset();
|
int offset();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setSize(int size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int bufferSize = 0;
|
int bufferSize = 0;
|
||||||
void setSize(int size);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#g++ -g -std=c++20 -o zstring_test zstring_test.cpp -I.. -L.. -lCoreUtils
|
#g++ -g -std=c++20 -o zstring_test zstring_test.cpp -I.. -L.. -lCoreUtils
|
||||||
#g++ -g -std=c++20 -o mstring_test mstring_test.cpp -I.. -L.. -lCoreUtils
|
g++ -g -std=c++20 -o mstring_test mstring_test.cpp -I.. -L.. -lCoreUtils
|
||||||
g++ -o jstring_test jstring_test.cpp -I.. -L.. -lCoreUtils
|
g++ -o jstring_test jstring_test.cpp -I.. -L.. -lCoreUtils
|
||||||
|
Binary file not shown.
@ -3,22 +3,30 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
coreutils::MString test0("{\"Number:\"0\",\"id\":\"XXXXX\"}");
|
coreutils::MString test0("{\"Number\":\"0\",\"id\":\"XXXXX\"}");
|
||||||
coreutils::JString test1;
|
coreutils::JString test1;
|
||||||
|
|
||||||
test1 = test0;
|
test1 = test0;
|
||||||
|
std::cout << test1 << std::endl;
|
||||||
|
|
||||||
|
std::cout << test1["id"] << std::endl;
|
||||||
|
|
||||||
test1["name"] = "Cohen";
|
test1["name"] = "Cohen";
|
||||||
|
|
||||||
|
std::cout << test1 << std::endl;
|
||||||
|
|
||||||
test1["health"] = "100";
|
test1["health"] = "100";
|
||||||
test1["comment"] = "this is a comment";
|
test1["comment"] = "this is a comment";
|
||||||
test1["race"] = "human";
|
test1["race"] = "human";
|
||||||
test1["array"] = "[\"test1\",\"test2\",\"test3\"]";
|
test1["array"] = "[\"test1\",\"test2\",\"test3\"]";
|
||||||
test1["tester"] = "test field";
|
test1["tester"] = "test field";
|
||||||
test1["object1"] = "{\"attr1\":\"value1\",\"attr2\":\"value2\",\"attr3\":\"value3\"}";
|
test1["object1"] = "{\"attr1\":\"value1\",\"attr2\":\"value2\",\"attr3\":\"value3\"}";
|
||||||
|
test1["object1.attr2"] = "{\"xattr1\":\"xvalue1\",\"xattr2\":\"xvalue2\",\"xattr3\":\"xvalue3\"}";
|
||||||
|
test1["object1.attr3"] = "Im not an object";
|
||||||
|
|
||||||
std::cout << test1 << std::endl;
|
std::cout << test1 << std::endl;
|
||||||
|
|
||||||
coreutils::MString test2 = test1["name"];
|
coreutils::ZString test2 = test1["name"];
|
||||||
std::cout << test2 << std::endl;
|
std::cout << test2 << std::endl;
|
||||||
|
|
||||||
std::cout << test1["name"] << std::endl;
|
std::cout << test1["name"] << std::endl;
|
||||||
@ -29,6 +37,11 @@ int main(int argc, char **argv) {
|
|||||||
std::cout << test1["tester"] << std::endl;
|
std::cout << test1["tester"] << std::endl;
|
||||||
std::cout << test1["object1"] << std::endl;
|
std::cout << test1["object1"] << std::endl;
|
||||||
std::cout << test1["object1.attr2"] << std::endl;
|
std::cout << test1["object1.attr2"] << std::endl;
|
||||||
|
std::cout << test1["object1.attr2.xattr3"] << std::endl;
|
||||||
|
std::cout << test1["object1.attr3"] << std::endl;
|
||||||
|
std::cout << test1["array[0]"] << std::endl;
|
||||||
|
std::cout << test1["array[1]"] << std::endl;
|
||||||
|
std::cout << test1["array[2]"] << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,11 @@ int main(int argc, char **argv) {
|
|||||||
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::cout << "001" << std::endl;
|
||||||
std::string test11 = "this is a test";
|
std::string test11 = "this is a test";
|
||||||
|
std::cout << "002" << std::endl;
|
||||||
coreutils::MString test12 = test11;
|
coreutils::MString test12 = test11;
|
||||||
|
std::cout << "003" << std::endl;
|
||||||
std::cout << "assign from std::string: [" << test12 << "]." << std::endl;
|
std::cout << "assign from std::string: [" << test12 << "]." << std::endl;
|
||||||
|
|
||||||
coreutils::MString test2("this is another test.");
|
coreutils::MString test2("this is another test.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user