Skip to content

extend json support for types other than strings #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 44 additions & 11 deletions src/Store/Store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,51 @@ void Store::JsonParser(std::string input){
int type=0;
std::string key;
std::string value;

bool term = false;

for(std::string::size_type i = 0; i < input.size(); ++i) {

if(input[i]=='\"')type++;
else if(type==1)key+=input[i];
else if(type==3)value+=input[i];
else if(type==4){
type=0;
m_variables[key]=value;
key="";
value="";
}

if(type==2){
// scanning a key
if(value.size()==0){
// not yet found start of key, might be string or otherwise
if(input[i]==':' || input[i]==' '){
continue; // still not found the start, keep looking
} else if(input[i]=='\"'){
// string value, set our scan to stop at a terminating '"'
term=true;
} else {
// not a string, set our scan to stop at a terminating ','
value+=input[i]; // this isn't a terminator, so add to value
}
} else {
// we're adding chars. check for terminator
if( (term && input[i]=='\"') || (!term && input[i]==',') || (!term && input[i]=='}') ){
// terminator found, add to internal map and reset
type=0;
size_t sz=value.size();
while(value[sz-1]==' ') --sz; // trim
value.resize(sz);
m_variables[key] = value;
key="";
value="";
term=false;
} else {
// just a char to add to value
value+=input[i];
}
}
}
else if(input[i]=='\"') type++;
else if(type==1)key+=input[i];
else if(type==3)value+=input[i];
else if(type==4){
type=0;
m_variables[key]=value;
key="";
value="";
term=false;
}


/*
Expand Down