diff --git a/src/Store/Store.cpp b/src/Store/Store.cpp index 799bc51..a84756c 100644 --- a/src/Store/Store.cpp +++ b/src/Store/Store.cpp @@ -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; + } /*