Working flat JString sorta
This commit is contained in:
parent
7b333a3984
commit
74ab316e64
37
JString.cpp
37
JString.cpp
@ -7,7 +7,7 @@ namespace coreutils {
|
||||
|
||||
JString::JString(const char *data) : MString(data) {}
|
||||
|
||||
void JString::set(ZString path, const char *value) {
|
||||
void JString::set(ZString &path, ZString &value) {
|
||||
reset();
|
||||
if(locate(path)) {
|
||||
push();
|
||||
@ -32,46 +32,21 @@ namespace coreutils {
|
||||
}
|
||||
}
|
||||
|
||||
ZString JString::find(ZString path) {
|
||||
ZString JString::find(ZString &path) {
|
||||
reset();
|
||||
if(locate(path)) {
|
||||
if(ifNext("\""))
|
||||
return getTokenExclude("\"");
|
||||
// TODO: Handle numbers that are not in double quotes.
|
||||
|
||||
if(startsWith("[")) {
|
||||
ZString temp = getContainer();
|
||||
std::cout << temp << std::endl;
|
||||
std::cout << getContainer() << std::endl;
|
||||
}
|
||||
}
|
||||
return ZString();
|
||||
}
|
||||
|
||||
void JString::operator=(ZString &value) {
|
||||
std::cout << "operator=(ZString &)" << value << "\n";
|
||||
}
|
||||
|
||||
JString& JString::operator=(const char *value) {
|
||||
std::cout << "operator=" << value << "\n";
|
||||
set(path, value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ZString JString::operator[](const char *path) {
|
||||
// std::cout << "operator[" << path << "]\n";
|
||||
// this->path = path;
|
||||
// reset();
|
||||
// return find(path);
|
||||
// }
|
||||
|
||||
JString& JString::operator[](const char *path) {
|
||||
std::cout << "operator[" << path << "]\n";
|
||||
reset();
|
||||
this->path = path;
|
||||
find(path);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool JString::locate(ZString path) {
|
||||
bool JString::locate(ZString &path) {
|
||||
path.split(".", 1);
|
||||
notfirst = false;
|
||||
if(ifNext("{")) {
|
||||
@ -122,5 +97,5 @@ namespace coreutils {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
49
JString.h
49
JString.h
@ -35,32 +35,47 @@ namespace coreutils {
|
||||
JString();
|
||||
JString(const char *data);
|
||||
|
||||
void set(ZString path, const char *value);
|
||||
void set(ZString &path, ZString &value);
|
||||
|
||||
///
|
||||
/// Use the find method to look through an object for member specified by
|
||||
/// the key in parameter 1. The cursor must be pointing to the { character
|
||||
/// the key in parameter 1. The cursor must be pointing to the { character
|
||||
/// that begins the object's list.
|
||||
///
|
||||
|
||||
ZString find(ZString path);
|
||||
|
||||
void operator=(ZString &value);
|
||||
JString& operator=(const char *value);
|
||||
|
||||
JString& operator[](const char *path);
|
||||
// operator const ZString () const {
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
// MString & operator[](ZString &key);
|
||||
|
||||
// MString & operator[](std::string key);
|
||||
ZString find(ZString &path);
|
||||
|
||||
private:
|
||||
bool locate(ZString path);
|
||||
bool locate(ZString &path);
|
||||
bool notfirst;
|
||||
MString path;
|
||||
ZString path;
|
||||
|
||||
class Proxy {
|
||||
|
||||
public:
|
||||
Proxy(JString &jstring, ZString key) : jstring(jstring), key(key) {}
|
||||
|
||||
operator coreutils::ZString () {
|
||||
ZString result;
|
||||
result = jstring.find(key);
|
||||
return result;
|
||||
}
|
||||
|
||||
Proxy& operator=(coreutils::ZString value) {
|
||||
jstring.set(key, value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
JString &jstring;
|
||||
ZString key;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
Proxy operator[](coreutils::ZString key) {
|
||||
return Proxy(*this, key);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,39 +0,0 @@
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <cstring>
|
||||
#include <sys/types.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <math.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/err.h>
|
||||
#include <dirent.h>
|
||||
#include <iomanip>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
|
Binary file not shown.
@ -16,20 +16,37 @@ int main(int argc, char **argv) {
|
||||
// test1.set("key4", "data4");
|
||||
// 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\"}");
|
||||
std::cout << test2 << std::endl;
|
||||
std::cout << "--------" << std::endl;
|
||||
// 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["key1"] << std::endl;
|
||||
// std::cout << "value: " << test2["key1.name[id=2]"] << std::endl;
|
||||
// std::cout << "value: " << test2["key1.name[id=3]"] << std::endl;
|
||||
|
||||
test2["key2"] = "newvalue1";
|
||||
std::cout << "--------" << std::endl;
|
||||
// test2["key2"] = "newvalue1";
|
||||
// std::cout << "--------" << std::endl;
|
||||
// test2 = "newvalue";
|
||||
// std::cout << test2 << std::endl;
|
||||
// std::cout << "--------" << std::endl;
|
||||
// std::cout << "key2: " << test2["key2"] << std::endl;
|
||||
|
||||
coreutils::JString test1;
|
||||
coreutils::MString test2;
|
||||
test1["name"] = "Cohen";
|
||||
test1["health"] = "100";
|
||||
test1["comment"] = "this is a comment";
|
||||
test1["race"] = "human";
|
||||
std::cout << test1 << std::endl;
|
||||
test2 = test1["name"];
|
||||
std::cout << test2 << std::endl;
|
||||
std::cout << "--------" << std::endl;
|
||||
std::cout << "key2: " << test2["key2"] << std::endl;
|
||||
test2 = test1["health"];
|
||||
std::cout << test2 << std::endl;
|
||||
test2 = test1["comment"];
|
||||
std::cout << test2 << std::endl;
|
||||
test2 = test1["race"];
|
||||
std::cout << test2 << std::endl;
|
||||
// std::cout << "[" << test1["name"] << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Binary file not shown.
@ -64,7 +64,9 @@ int main(int argc, char **argv) {
|
||||
coreutils::MString test21;
|
||||
test21 = test20;
|
||||
std::cout << "mstring = zstring: [" << test21 << "]" << std::endl;
|
||||
|
||||
coreutils::MString test22;
|
||||
test22 << test20;
|
||||
std::cout << "mstring << zstring: [" << test22 << "]" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user