Working flat JString sorta
This commit is contained in:
parent
7b333a3984
commit
74ab316e64
35
JString.cpp
35
JString.cpp
@ -7,7 +7,7 @@ namespace coreutils {
|
|||||||
|
|
||||||
JString::JString(const char *data) : MString(data) {}
|
JString::JString(const char *data) : MString(data) {}
|
||||||
|
|
||||||
void JString::set(ZString path, const char *value) {
|
void JString::set(ZString &path, ZString &value) {
|
||||||
reset();
|
reset();
|
||||||
if(locate(path)) {
|
if(locate(path)) {
|
||||||
push();
|
push();
|
||||||
@ -32,46 +32,21 @@ namespace coreutils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ZString JString::find(ZString path) {
|
ZString JString::find(ZString &path) {
|
||||||
|
reset();
|
||||||
if(locate(path)) {
|
if(locate(path)) {
|
||||||
if(ifNext("\""))
|
if(ifNext("\""))
|
||||||
return getTokenExclude("\"");
|
return getTokenExclude("\"");
|
||||||
// TODO: Handle numbers that are not in double quotes.
|
// TODO: Handle numbers that are not in double quotes.
|
||||||
|
|
||||||
if(startsWith("[")) {
|
if(startsWith("[")) {
|
||||||
ZString temp = getContainer();
|
std::cout << getContainer() << std::endl;
|
||||||
std::cout << temp << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ZString();
|
return ZString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JString::operator=(ZString &value) {
|
bool JString::locate(ZString &path) {
|
||||||
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) {
|
|
||||||
path.split(".", 1);
|
path.split(".", 1);
|
||||||
notfirst = false;
|
notfirst = false;
|
||||||
if(ifNext("{")) {
|
if(ifNext("{")) {
|
||||||
|
47
JString.h
47
JString.h
@ -35,7 +35,7 @@ namespace coreutils {
|
|||||||
JString();
|
JString();
|
||||||
JString(const char *data);
|
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
|
/// Use the find method to look through an object for member specified by
|
||||||
@ -43,24 +43,39 @@ namespace coreutils {
|
|||||||
/// that begins the object's list.
|
/// that begins the object's list.
|
||||||
///
|
///
|
||||||
|
|
||||||
ZString find(ZString path);
|
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);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool locate(ZString path);
|
bool locate(ZString &path);
|
||||||
bool notfirst;
|
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");
|
// test1.set("key4", "data4");
|
||||||
// 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 << test2 << std::endl;
|
||||||
std::cout << "--------" << 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 << "--------" << std::endl;
|
// std::cout << "--------" << std::endl;
|
||||||
// test2 = "newvalue";
|
// 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 << test2 << std::endl;
|
||||||
std::cout << "--------" << std::endl;
|
test2 = test1["health"];
|
||||||
std::cout << "key2: " << test2["key2"] << std::endl;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -64,7 +64,9 @@ int main(int argc, char **argv) {
|
|||||||
coreutils::MString test21;
|
coreutils::MString test21;
|
||||||
test21 = test20;
|
test21 = test20;
|
||||||
std::cout << "mstring = zstring: [" << test21 << "]" << std::endl;
|
std::cout << "mstring = zstring: [" << test21 << "]" << std::endl;
|
||||||
|
coreutils::MString test22;
|
||||||
|
test22 << test20;
|
||||||
|
std::cout << "mstring << zstring: [" << test22 << "]" << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user