Skip to content

Reapply clang-format. #867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion include/json/assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
#define CPPTL_JSON_ASSERTIONS_H_INCLUDED

#include <sstream>
#include <cstdlib>
#include <sstream>

#if !defined(JSON_IS_AMALGAMATION)
#include "config.h"
Expand Down
23 changes: 13 additions & 10 deletions include/json/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define JSON_CONFIG_H_INCLUDED
#include <cstddef>
#include <cstdint> //typedef int64_t, uint64_t
#include <string> //typedef String
#include <string> //typedef String

/// If defined, indicates that json library is embedded in CppTL library.
//# define JSON_IN_CPPTL 1
Expand Down Expand Up @@ -55,15 +55,18 @@
#endif

#if defined(_MSC_VER) && _MSC_VER < 1800
#error "ERROR: Visual Studio 12 (2013) with _MSC_VER=1800 is the oldest supported compiler with sufficient C++11 capabilities"
#error \
"ERROR: Visual Studio 12 (2013) with _MSC_VER=1800 is the oldest supported compiler with sufficient C++11 capabilities"
#endif

#if defined(_MSC_VER) && _MSC_VER < 1900
// As recommended at https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
extern JSON_API int msvc_pre1900_c99_snprintf(char *outBuf, size_t size, const char *format, ...);
# define jsoncpp_snprintf msvc_pre1900_c99_snprintf
// As recommended at
// https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
extern JSON_API int
msvc_pre1900_c99_snprintf(char* outBuf, size_t size, const char* format, ...);
#define jsoncpp_snprintf msvc_pre1900_c99_snprintf
#else
# define jsoncpp_snprintf std::snprintf
#define jsoncpp_snprintf std::snprintf
#endif

// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
Expand All @@ -75,10 +78,10 @@
#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
#endif // defined(_MSC_VER)

// In c++11 the override keyword allows you to explicitly define that a function
// is intended to override the base-class version. This makes the code more
// manageable and fixes a set of common hard-to-find bugs.
#define JSONCPP_OVERRIDE override // Define maintained for backwards compatibility of external tools. C++11 should be used directly in JSONCPP
// JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools.
// C++11 should be used directly in JSONCPP.
#define JSONCPP_OVERRIDE override

#if __cplusplus >= 201103L
#define JSONCPP_NOEXCEPT noexcept
#define JSONCPP_OP_EXPLICIT explicit
Expand Down
8 changes: 4 additions & 4 deletions include/json/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class JSON_API Features {
Features();

/// \c true if comments are allowed. Default: \c true.
bool allowComments_{true};
bool allowComments_{ true };

/// \c true if root must be either an array or an object value. Default: \c
/// false.
bool strictRoot_{false};
bool strictRoot_{ false };

/// \c true if dropped null placeholders are allowed. Default: \c false.
bool allowDroppedNullPlaceholders_{false};
bool allowDroppedNullPlaceholders_{ false };

/// \c true if numeric object key are allowed. Default: \c false.
bool allowNumericKeys_{false};
bool allowNumericKeys_{ false };
};

} // namespace Json
Expand Down
5 changes: 3 additions & 2 deletions include/json/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ class JSON_API Reader {
Location& current,
Location end,
unsigned int& unicode);
bool
addError(const JSONCPP_STRING& message, Token& token, Location extra = nullptr);
bool addError(const JSONCPP_STRING& message,
Token& token,
Location extra = nullptr);
bool recoverFromError(TokenType skipUntilToken);
bool addErrorAndRecover(const JSONCPP_STRING& message,
Token& token,
Expand Down
6 changes: 3 additions & 3 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ Json::Value obj_value(Json::objectValue); // {}

void setComment(const char* text, size_t len);

char* comment_{nullptr};
char* comment_{ nullptr };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like this behavior, but it's what our .clang-format specifies so we'd better either accept it or change our .clang-format file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no preference, except for consistency. The status-quo is fine.

I'll also use clang-format in the future to maintain style consistency.

};

// struct MemberNamesTransform
Expand Down Expand Up @@ -679,7 +679,7 @@ class JSON_API PathArgument {
enum Kind { kindNone = 0, kindIndex, kindKey };
JSONCPP_STRING key_;
ArrayIndex index_{};
Kind kind_{kindNone};
Kind kind_{ kindNone };
};

/** \brief Experimental and untested: represents a "path" to access a node.
Expand Down Expand Up @@ -780,7 +780,7 @@ class JSON_API ValueIteratorBase {
private:
Value::ObjectValues::iterator current_;
// Indicates that iterator is for a null value.
bool isNull_{true};
bool isNull_{ true };

public:
// For some reason, BORLAND needs these at the end, rather
Expand Down
14 changes: 7 additions & 7 deletions include/json/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter
void writeValue(const Value& value);

JSONCPP_STRING document_;
bool yamlCompatibilityEnabled_{false};
bool dropNullPlaceholders_{false};
bool omitEndingLineFeed_{false};
bool yamlCompatibilityEnabled_{ false };
bool dropNullPlaceholders_{ false };
bool omitEndingLineFeed_{ false };
};
#if defined(_MSC_VER)
#pragma warning(pop)
Expand Down Expand Up @@ -257,9 +257,9 @@ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
ChildValues childValues_;
JSONCPP_STRING document_;
JSONCPP_STRING indentString_;
unsigned int rightMargin_{74};
unsigned int indentSize_{3};
bool addChildValues_{false};
unsigned int rightMargin_{ 74 };
unsigned int indentSize_{ 3 };
bool addChildValues_{ false };
};
#if defined(_MSC_VER)
#pragma warning(pop)
Expand Down Expand Up @@ -331,7 +331,7 @@ class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API
ChildValues childValues_;
JSONCPP_OSTREAM* document_;
JSONCPP_STRING indentString_;
unsigned int rightMargin_{74};
unsigned int rightMargin_{ 74 };
JSONCPP_STRING indentation_;
bool addChildValues_ : 1;
bool indented_ : 1;
Expand Down
2 changes: 1 addition & 1 deletion src/jsontestrunner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*/

#include <algorithm> // sort
#include <cstdio>
#include <json/json.h>
#include <sstream>
#include <cstdio>

struct Options {
JSONCPP_STRING path;
Expand Down
23 changes: 11 additions & 12 deletions src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#if defined(_MSC_VER)
#if !defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#endif //_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#endif //_MSC_VER
#endif //_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#endif //_MSC_VER

#if defined(_MSC_VER)
// Disable warning about strdup being deprecated.
Expand All @@ -59,8 +59,7 @@ typedef std::auto_ptr<CharReader> CharReaderPtr;
// Implementation of class Features
// ////////////////////////////////

Features::Features()
= default;
Features::Features() = default;

Features Features::all() { return {}; }

Expand All @@ -87,8 +86,7 @@ bool Reader::containsNewLine(Reader::Location begin, Reader::Location end) {
// //////////////////////////////////////////////////////////////////

Reader::Reader()
: errors_(), document_(), commentsBefore_(), features_(Features::all())
{}
: errors_(), document_(), commentsBefore_(), features_(Features::all()) {}

Reader::Reader(const Features& features)
: errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
Expand Down Expand Up @@ -816,7 +814,7 @@ JSONCPP_STRING Reader::getFormatedErrorMessages() const {

JSONCPP_STRING Reader::getFormattedErrorMessages() const {
JSONCPP_STRING formattedMessage;
for (const auto & error : errors_) {
for (const auto& error : errors_) {
formattedMessage +=
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
formattedMessage += " " + error.message_ + "\n";
Expand All @@ -829,7 +827,7 @@ JSONCPP_STRING Reader::getFormattedErrorMessages() const {

std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
std::vector<Reader::StructuredError> allErrors;
for (const auto & error : errors_) {
for (const auto& error : errors_) {
Reader::StructuredError structured;
structured.offset_start = error.token_.start_ - begin_;
structured.offset_limit = error.token_.end_ - begin_;
Expand Down Expand Up @@ -989,8 +987,9 @@ class OurReader {
Location& current,
Location end,
unsigned int& unicode);
bool
addError(const JSONCPP_STRING& message, Token& token, Location extra = nullptr);
bool addError(const JSONCPP_STRING& message,
Token& token,
Location extra = nullptr);
bool recoverFromError(TokenType skipUntilToken);
bool addErrorAndRecover(const JSONCPP_STRING& message,
Token& token,
Expand Down Expand Up @@ -1827,7 +1826,7 @@ JSONCPP_STRING OurReader::getLocationLineAndColumn(Location location) const {

JSONCPP_STRING OurReader::getFormattedErrorMessages() const {
JSONCPP_STRING formattedMessage;
for (const auto & error : errors_) {
for (const auto& error : errors_) {
formattedMessage +=
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
formattedMessage += " " + error.message_ + "\n";
Expand All @@ -1840,7 +1839,7 @@ JSONCPP_STRING OurReader::getFormattedErrorMessages() const {

std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
std::vector<OurReader::StructuredError> allErrors;
for (const auto & error : errors_) {
for (const auto& error : errors_) {
OurReader::StructuredError structured;
structured.offset_start = error.token_.start_ - begin_;
structured.offset_limit = error.token_.end_ - begin_;
Expand Down
58 changes: 31 additions & 27 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <json/writer.h>
#endif // if !defined(JSON_IS_AMALGAMATION)
#include <cassert>
#include <cstring>
#include <cmath>
#include <cstring>
#include <sstream>
#include <utility>
#ifdef JSON_USE_CPPTL
Expand All @@ -21,24 +21,28 @@

// Provide implementation equivalent of std::snprintf for older _MSC compilers
#if defined(_MSC_VER) && _MSC_VER < 1900
#include <stdarg.h>
static int msvc_pre1900_c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
{
int count = -1;
if (size != 0)
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}

int JSON_API msvc_pre1900_c99_snprintf(char *outBuf, size_t size, const char *format, ...)
{
va_list ap;
va_start(ap, format);
const int count = msvc_pre1900_c99_vsnprintf(outBuf, size, format, ap);
va_end(ap);
return count;
#include <stdarg.h>
static int msvc_pre1900_c99_vsnprintf(char* outBuf,
size_t size,
const char* format,
va_list ap) {
int count = -1;
if (size != 0)
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}

int JSON_API msvc_pre1900_c99_snprintf(char* outBuf,
size_t size,
const char* format,
...) {
va_list ap;
va_start(ap, format);
const int count = msvc_pre1900_c99_vsnprintf(outBuf, size, format, ap);
va_end(ap);
return count;
}
#endif

Expand Down Expand Up @@ -213,7 +217,7 @@ static inline void releaseStringValue(char* value, unsigned) { free(value); }

namespace Json {

Exception::Exception(JSONCPP_STRING msg) : msg_(std::move(msg)) {}
Exception::Exception(JSONCPP_STRING msg) : msg_(std::move(msg)) {}
Exception::~Exception() JSONCPP_NOEXCEPT {}
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
RuntimeError::RuntimeError(JSONCPP_STRING const& msg) : Exception(msg) {}
Expand All @@ -233,7 +237,7 @@ JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg) {
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////

Value::CommentInfo::CommentInfo() = default;
Value::CommentInfo::CommentInfo() = default;

Value::CommentInfo::~CommentInfo() {
if (comment_)
Expand Down Expand Up @@ -436,7 +440,8 @@ Value::Value(double value) {

Value::Value(const char* value) {
initBasic(stringValue, true);
JSON_ASSERT_MESSAGE(value != nullptr, "Null Value Passed to Value Constructor");
JSON_ASSERT_MESSAGE(value != nullptr,
"Null Value Passed to Value Constructor");
value_.string_ = duplicateAndPrefixStringValue(
value, static_cast<unsigned>(strlen(value)));
}
Expand Down Expand Up @@ -890,8 +895,7 @@ bool Value::isConvertibleTo(ValueType other) const {
(type_ == booleanValue && value_.bool_ == false) ||
(type_ == stringValue && asString().empty()) ||
(type_ == arrayValue && value_.map_->empty()) ||
(type_ == objectValue && value_.map_->empty()) ||
type_ == nullValue;
(type_ == objectValue && value_.map_->empty()) || type_ == nullValue;
case intValue:
return isInt() ||
(type_ == realValue && InRange(value_.real_, minInt, maxInt)) ||
Expand Down Expand Up @@ -1655,7 +1659,7 @@ void Path::invalidPath(const JSONCPP_STRING& /*path*/, int /*location*/) {

const Value& Path::resolve(const Value& root) const {
const Value* node = &root;
for (const auto & arg : args_) {
for (const auto& arg : args_) {
if (arg.kind_ == PathArgument::kindIndex) {
if (!node->isArray() || !node->isValidIndex(arg.index_)) {
// Error: unable to resolve path (array value expected at position...
Expand All @@ -1680,7 +1684,7 @@ const Value& Path::resolve(const Value& root) const {

Value Path::resolve(const Value& root, const Value& defaultValue) const {
const Value* node = &root;
for (const auto & arg : args_) {
for (const auto& arg : args_) {
if (arg.kind_ == PathArgument::kindIndex) {
if (!node->isArray() || !node->isValidIndex(arg.index_))
return defaultValue;
Expand All @@ -1698,7 +1702,7 @@ Value Path::resolve(const Value& root, const Value& defaultValue) const {

Value& Path::make(Value& root) const {
Value* node = &root;
for (const auto & arg : args_) {
for (const auto& arg : args_) {
if (arg.kind_ == PathArgument::kindIndex) {
if (!node->isArray()) {
// Error: node is not an array at position ...
Expand Down
Loading