Skip to content
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