more serious work on JString.

This commit is contained in:
barant committed 2024-12-12 12:22:46 -08:00
1 parent c6e0486c14
commit 0d60cce8dc
8 files changed
+49 -45

No files matched your search

+33 -26
View File
@@ -33,7 +33,7 @@ namespace coreutils {
throw coreutils::Exception("Fix me to accept integer type.");
}
} else {
std::cout << "[" << unparsed() << "] >" << value << "<" << std::endl;
// std::cout << "[" << unparsed() << "] >" << value << "<" << std::endl;
MString key;
if(notfirst)
key << ",";
@@ -48,7 +48,7 @@ namespace coreutils {
}
}
ZString JString::find(ZString &path) {
ZString JString::find(ZString path) {
reset();
if(locate(path)) {
if(ifNext("\""))
@@ -64,23 +64,9 @@ namespace coreutils {
return ZString();
}
bool JString::locate(ZString &path) {
std::cout << "path locate: " << path << std::endl;
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();
bool JString::locate(ZString path) {
// std::cout << "path locate: " << path << std::endl;
path.getTokenExclude("[.");
notfirst = false;
if(ifNext("{")) {
while(startsWith("\"")) {
@@ -93,13 +79,34 @@ namespace coreutils {
} else
throw coreutils::Exception("Labels must be contained in double quotes.");
if(ifNext(":")) {
// std::cout << "path: (" << pathx << ") " << label << std::endl;
if(label == pathx) {
if(path.getList().size() == 1) {
std::cout << "found cursor: " << unparsed() << std::endl;
// std::cout << "path: (" << path.parsed() << ") (" << label << ") " << (label == path.parsed()) << std::endl;
if(label == path.parsed()) {
if(path.unparsed() == "") {
// std::cout << "found cursor: " << unparsed() << std::endl;
return true;
}
return locate(path[1]);
if(path.ifNext("."))
return locate(path.unparsed());
if(path.ifNext("[")) {
int index = path.asInteger();
if(!path.ifNext("]"))
throw coreutils::Exception("expecting ] after index value in array selector.");
if(ifNext("[")) {
while(index > 0) {
getContainer();
if(!ifNext(","))
throw coreutils::Exception("expecting comma to seperate array elements.");
--index;
}
return true;
} else
throw coreutils::Exception("Path is expecting an array for selector value.");
if(path.eod())
return false;
else if(path.ifNext("."))
return locate(path.unparsed());
throw coreutils::Exception("expecting '.' in path.");
}
}
// std::cout << "+++" << unparsed() << std::endl;
if(startsWith("\"")) {
@@ -117,9 +124,9 @@ namespace coreutils {
}
} else if(ifNext("[")) {
ZString label = path[0].getTokenExclude("[");
path[0].ifNext("[");
path.ifNext("[");
ZString key = path[0].getTokenExclude("=");
path[0].ifNext("=");
path.ifNext("=");
ZString value = path[0].getTokenExclude("]");
while(!ifNext("]")) {
push();