1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 12:41:15 +02:00

OCD: foreach -> C++11 ranged for

This commit is contained in:
Eelco Dolstra 2015-07-17 19:24:28 +02:00
parent 1511aa9f48
commit 6bd2c7bb38
30 changed files with 849 additions and 874 deletions

View file

@ -12,14 +12,14 @@ namespace nix {
void escapeJSON(std::ostream & str, const string & s)
{
str << "\"";
foreach (string::const_iterator, i, s)
if (*i == '\"' || *i == '\\') str << "\\" << *i;
else if (*i == '\n') str << "\\n";
else if (*i == '\r') str << "\\r";
else if (*i == '\t') str << "\\t";
else if (*i >= 0 && *i < 32)
str << "\\u" << std::setfill('0') << std::setw(4) << std::hex << (uint16_t) *i << std::dec;
else str << *i;
for (auto & i : s)
if (i == '\"' || i == '\\') str << "\\" << i;
else if (i == '\n') str << "\\n";
else if (i == '\r') str << "\\r";
else if (i == '\t') str << "\\t";
else if (i >= 0 && i < 32)
str << "\\u" << std::setfill('0') << std::setw(4) << std::hex << (uint16_t) i << std::dec;
else str << i;
str << "\"";
}
@ -59,11 +59,11 @@ void printValueAsJSON(EvalState & state, bool strict,
if (i == v.attrs->end()) {
JSONObject json(str);
StringSet names;
foreach (Bindings::iterator, i, *v.attrs)
names.insert(i->name);
foreach (StringSet::iterator, i, names) {
Attr & a(*v.attrs->find(state.symbols.create(*i)));
json.attr(*i);
for (auto & j : *v.attrs)
names.insert(j.name);
for (auto & j : names) {
Attr & a(*v.attrs->find(state.symbols.create(j)));
json.attr(j);
printValueAsJSON(state, strict, *a.value, str, context);
}
} else
@ -80,7 +80,7 @@ void printValueAsJSON(EvalState & state, bool strict,
break;
}
case tExternal:
case tExternal:
v.external->printValueAsJSON(state, strict, str, context);
break;