Skip to content

Commit

Permalink
Insert string keys in map without quotes.
Browse files Browse the repository at this point in the history
Stripping the first and the last instance of the character '"' when
adding a key to the map, in order to facilitate the future searches.
  • Loading branch information
kutsurak committed Dec 14, 2011
1 parent 6503545 commit 759b840
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion JSON.cpp
Expand Up @@ -57,7 +57,7 @@ std::string Members::toJSON(int spc, bool skip_initial) const {
typedef std::map<std::string, Value*>::const_iterator map_iterator;
for (map_iterator it = pairs_.begin();
it != pairs_.end(); it++) {
str += spcs + it->first + " : " + it->second->toJSON(spc, true);
str += spcs + "\"" + it->first + "\"" + " : " + it->second->toJSON(spc, true);
if (i < sz - 1) {
str += ",\n";
i++;
Expand Down
6 changes: 5 additions & 1 deletion JSONParser.cpp
Expand Up @@ -110,7 +110,11 @@ std::pair<string, Value*> Parser::jPair() {
}
Value *val = jValue();

std::pair<std::string, Value*> ret(str->toJSON(0, false), val);
std::string key = str->toJSON(0, false);
// Strip the first and last double quote from the key
// for easier searching in the map.
key = key.substr(key.find_first_of("\"") + 1, key.find_last_of("\"") - 1);
std::pair<std::string, Value*> ret(key, val);
delete str;
return ret;
}
Expand Down

0 comments on commit 759b840

Please sign in to comment.