diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-19T19·47+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-19T19·51+0100 |
commit | 39087321811e81e26a1a47d6967df1088dcf0e95 (patch) | |
tree | 57110be423eeb7869e9960466f4b17c0ea7cd961 /third_party/nix/src/libexpr/json-to-value.cc | |
parent | cf40d08908ede4061eb15513b770c98877844b8b (diff) |
style(3p/nix): Final act in the brace-wrapping saga r/777
This last change set was generated by a full clang-tidy run (including compilation): clang-tidy -p ~/projects/nix-build/ \ -checks=-*,readability-braces-around-statements -fix src/*/*.cc Actually running clang-tidy requires some massaging to make it play nice with Nix + meson, I'll be adding a wrapper or something for that soon.
Diffstat (limited to 'third_party/nix/src/libexpr/json-to-value.cc')
-rw-r--r-- | third_party/nix/src/libexpr/json-to-value.cc | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/third_party/nix/src/libexpr/json-to-value.cc b/third_party/nix/src/libexpr/json-to-value.cc index 51d001d8a530..70628636e16b 100644 --- a/third_party/nix/src/libexpr/json-to-value.cc +++ b/third_party/nix/src/libexpr/json-to-value.cc @@ -21,29 +21,30 @@ static string parseJSONString(const char*& s) { } if (*s == '\\') { s++; - if (*s == '"') + if (*s == '"') { res += '"'; - else if (*s == '\\') + } else if (*s == '\\') { res += '\\'; - else if (*s == '/') + } else if (*s == '/') { res += '/'; - else if (*s == '/') + } else if (*s == '/') { res += '/'; - else if (*s == 'b') + } else if (*s == 'b') { res += '\b'; - else if (*s == 'f') + } else if (*s == 'f') { res += '\f'; - else if (*s == 'n') + } else if (*s == 'n') { res += '\n'; - else if (*s == 'r') + } else if (*s == 'r') { res += '\r'; - else if (*s == 't') + } else if (*s == 't') { res += '\t'; - else if (*s == 'u') + } else if (*s == 'u') { throw JSONParseError( "\\u characters in JSON strings are currently not supported"); - else + } else { throw JSONParseError("invalid escaped character in JSON string"); + } s++; } else { res += *s++; @@ -76,8 +77,9 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) { if (*s == ']') { break; } - if (*s != ',') + if (*s != ',') { throw JSONParseError("expected ',' or ']' after JSON array element"); + } s++; } s++; @@ -108,8 +110,9 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) { if (*s == '}') { break; } - if (*s != ',') + if (*s != ',') { throw JSONParseError("expected ',' or '}' after JSON member"); + } s++; } state.mkAttrs(v, attrs.size()); @@ -137,10 +140,11 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) { } try { - if (number_type == tFloat) + if (number_type == tFloat) { mkFloat(v, stod(tmp_number)); - else + } else { mkInt(v, stol(tmp_number)); + } } catch (std::invalid_argument& e) { throw JSONParseError("invalid JSON number"); } catch (std::out_of_range& e) { @@ -163,17 +167,19 @@ static void parseJSON(EvalState& state, const char*& s, Value& v) { mkNull(v); } - else + else { throw JSONParseError("unrecognised JSON value"); + } } void parseJSON(EvalState& state, const string& s_, Value& v) { const char* s = s_.c_str(); parseJSON(state, s, v); skipWhitespace(s); - if (*s) + if (*s) { throw JSONParseError( format("expected end-of-string while parsing JSON value: %1%") % s); + } } } // namespace nix |