Skip to content

C++11 clang format #870

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
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerBindsToType: true
SpacesBeforeTrailingComments: 1
Cpp11BracedListStyle: false
Standard: Cpp03
Cpp11BracedListStyle: true
Standard: Cpp11
IndentWidth: 2
TabWidth: 8
UseTab: Never
Expand Down
5 changes: 2 additions & 3 deletions include/json/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ typedef UInt64 LargestUInt;
template <typename T>
using Allocator = typename std::conditional<JSONCPP_USING_SECURE_MEMORY,
SecureAllocator<T>,
std::allocator<T> >::type;
using String =
std::basic_string<char, std::char_traits<char>, Allocator<char> >;
std::allocator<T>>::type;
using String = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
using IStringStream = std::basic_istringstream<String::value_type,
String::traits_type,
String::allocator_type>;
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
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};
};

// struct MemberNamesTransform
Expand Down Expand Up @@ -679,7 +679,7 @@ class JSON_API PathArgument {
enum Kind { kindNone = 0, kindIndex, kindKey };
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);

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_;
String document_;
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_;
OStream* document_;
String indentString_;
unsigned int rightMargin_{ 74 };
unsigned int rightMargin_{74};
String indentation_;
bool addChildValues_ : 1;
bool indented_ : 1;
Expand Down
10 changes: 6 additions & 4 deletions src/jsontestrunner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct Options {
Json::String path;
Json::Features features;
bool parseOnly;
using writeFuncType = Json::String(*)(Json::Value const&);
using writeFuncType = Json::String (*)(Json::Value const&);
writeFuncType write;
};

Expand All @@ -37,10 +37,11 @@ static Json::String normalizeFloatingPointStr(double value) {
(s[index + 1] == '+' || s[index + 1] == '-') ? 1 : 0;
Json::String::size_type exponentStartIndex = index + 1 + hasSign;
Json::String normalized = s.substr(0, exponentStartIndex);
Json::String::size_type indexDigit = s.find_first_not_of('0', exponentStartIndex);
Json::String::size_type indexDigit =
s.find_first_not_of('0', exponentStartIndex);
Json::String exponent = "0";
if (indexDigit != Json::String::npos) // There is an exponent different
// from 0
// from 0
{
exponent = s.substr(indexDigit);
}
Expand Down Expand Up @@ -180,7 +181,8 @@ static int rewriteValueTree(const Json::String& rewritePath,
return 0;
}

static Json::String removeSuffix(const Json::String& path, const Json::String& extension) {
static Json::String removeSuffix(const Json::String& path,
const Json::String& extension) {
if (extension.length() >= path.length())
return Json::String("");
Json::String suffix = path.substr(path.length() - extension.length());
Expand Down
4 changes: 2 additions & 2 deletions src/lib_json/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ String valueToString(double value,
// that always has a decimal point because JSON doesn't distinguish the
// concepts of reals and integers.
if (!isfinite(value)) {
static const char* const reps[2][3] = { { "NaN", "-Infinity", "Infinity" },
{ "null", "-1e+9999", "1e+9999" } };
static const char* const reps[2][3] = {{"NaN", "-Infinity", "Infinity"},
{"null", "-1e+9999", "1e+9999"}};
return reps[useSpecialFloats ? 0 : 1]
[isnan(value) ? 0 : (value < 0) ? 1 : 2];
}
Expand Down
7 changes: 5 additions & 2 deletions src/test_lib_json/jsontest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ void TestResult::printFailure(bool printTestName) const {
}
}

Json::String TestResult::indentText(const Json::String& text, const Json::String& indent) {
Json::String TestResult::indentText(const Json::String& text,
const Json::String& indent) {
Json::String reindented;
Json::String::size_type lastIndex = 0;
while (lastIndex < text.size()) {
Expand Down Expand Up @@ -405,7 +406,9 @@ void Runner::printUsage(const char* appName) {
// Assertion functions
// //////////////////////////////////////////////////////////////////

Json::String ToJsonString(const char* toConvert) { return Json::String(toConvert); }
Json::String ToJsonString(const char* toConvert) {
return Json::String(toConvert);
}

Json::String ToJsonString(Json::String in) { return in; }

Expand Down
14 changes: 7 additions & 7 deletions src/test_lib_json/jsontest.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TestResult {
/// Not encapsulated to prevent step into when debugging failed assertions
/// Incremented by one on assertion predicate entry, decreased by one
/// by addPredicateContext().
PredicateContext::Id predicateId_{ 1 };
PredicateContext::Id predicateId_{1};

/// \internal Implementation detail for predicate macros
PredicateContext* predicateStackTail_;
Expand Down Expand Up @@ -102,15 +102,16 @@ class TestResult {
unsigned int line,
const char* expr,
unsigned int nestingLevel);
static Json::String indentText(const Json::String& text, const Json::String& indent);
static Json::String indentText(const Json::String& text,
const Json::String& indent);

typedef std::deque<Failure> Failures;
Failures failures_;
Json::String name_;
PredicateContext rootPredicateNode_;
PredicateContext::Id lastUsedPredicateId_{ 0 };
PredicateContext::Id lastUsedPredicateId_{0};
/// Failure which is the target of the messages added using operator <<
Failure* messageTarget_{ nullptr };
Failure* messageTarget_{nullptr};
};

class TestCase {
Expand All @@ -124,7 +125,7 @@ class TestCase {
virtual const char* testName() const = 0;

protected:
TestResult* result_{ nullptr };
TestResult* result_{nullptr};

private:
virtual void runTestCase() = 0;
Expand Down Expand Up @@ -218,8 +219,7 @@ TestResult& checkStringEqual(TestResult& result,
#define JSONTEST_ASSERT_PRED(expr) \
{ \
JsonTest::PredicateContext _minitest_Context = { \
result_->predicateId_, __FILE__, __LINE__, #expr, NULL, NULL \
}; \
result_->predicateId_, __FILE__, __LINE__, #expr, NULL, NULL}; \
result_->predicateStackTail_->next_ = &_minitest_Context; \
result_->predicateId_ += 1; \
result_->predicateStackTail_ = &_minitest_Context; \
Expand Down
63 changes: 32 additions & 31 deletions src/test_lib_json/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ struct ValueTest : JsonTest::TestCase {
/// Initialize all checks to \c false by default.
IsCheck();

bool isObject_{ false };
bool isArray_{ false };
bool isBool_{ false };
bool isString_{ false };
bool isNull_{ false };

bool isInt_{ false };
bool isInt64_{ false };
bool isUInt_{ false };
bool isUInt64_{ false };
bool isIntegral_{ false };
bool isDouble_{ false };
bool isNumeric_{ false };
bool isObject_{false};
bool isArray_{false};
bool isBool_{false};
bool isString_{false};
bool isNull_{false};

bool isInt_{false};
bool isInt64_{false};
bool isUInt_{false};
bool isUInt64_{false};
bool isIntegral_{false};
bool isDouble_{false};
bool isNumeric_{false};
};

void checkConstMemberCount(const Json::Value& value,
Expand All @@ -120,10 +120,11 @@ Json::String ValueTest::normalizeFloatingPointStr(const Json::String& s) {
(s[index + 1] == '+' || s[index + 1] == '-') ? 1 : 0;
Json::String::size_type exponentStartIndex = index + 1 + hasSign;
Json::String normalized = s.substr(0, exponentStartIndex);
Json::String::size_type indexDigit = s.find_first_not_of('0', exponentStartIndex);
Json::String::size_type indexDigit =
s.find_first_not_of('0', exponentStartIndex);
Json::String exponent = "0";
if (indexDigit != Json::String::npos) // There is an exponent different
// from 0
// from 0
{
exponent = s.substr(indexDigit);
}
Expand Down Expand Up @@ -2353,22 +2354,22 @@ JSONTEST_FIXTURE(CharReaderAllowSpecialFloatsTest, issue209) {
Json::String in;
};
const TestData test_data[] = {
{ __LINE__, true, "{\"a\":9}" }, //
{ __LINE__, false, "{\"a\":0Infinity}" }, //
{ __LINE__, false, "{\"a\":1Infinity}" }, //
{ __LINE__, false, "{\"a\":9Infinity}" }, //
{ __LINE__, false, "{\"a\":0nfinity}" }, //
{ __LINE__, false, "{\"a\":1nfinity}" }, //
{ __LINE__, false, "{\"a\":9nfinity}" }, //
{ __LINE__, false, "{\"a\":nfinity}" }, //
{ __LINE__, false, "{\"a\":.nfinity}" }, //
{ __LINE__, false, "{\"a\":9nfinity}" }, //
{ __LINE__, false, "{\"a\":-nfinity}" }, //
{ __LINE__, true, "{\"a\":Infinity}" }, //
{ __LINE__, false, "{\"a\":.Infinity}" }, //
{ __LINE__, false, "{\"a\":_Infinity}" }, //
{ __LINE__, false, "{\"a\":_nfinity}" }, //
{ __LINE__, true, "{\"a\":-Infinity}" } //
{__LINE__, true, "{\"a\":9}"}, //
{__LINE__, false, "{\"a\":0Infinity}"}, //
{__LINE__, false, "{\"a\":1Infinity}"}, //
{__LINE__, false, "{\"a\":9Infinity}"}, //
{__LINE__, false, "{\"a\":0nfinity}"}, //
{__LINE__, false, "{\"a\":1nfinity}"}, //
{__LINE__, false, "{\"a\":9nfinity}"}, //
{__LINE__, false, "{\"a\":nfinity}"}, //
{__LINE__, false, "{\"a\":.nfinity}"}, //
{__LINE__, false, "{\"a\":9nfinity}"}, //
{__LINE__, false, "{\"a\":-nfinity}"}, //
{__LINE__, true, "{\"a\":Infinity}"}, //
{__LINE__, false, "{\"a\":.Infinity}"}, //
{__LINE__, false, "{\"a\":_Infinity}"}, //
{__LINE__, false, "{\"a\":_nfinity}"}, //
{__LINE__, true, "{\"a\":-Infinity}"} //
};
for (const auto& td : test_data) {
bool ok = reader->parse(&*td.in.begin(), &*td.in.begin() + td.in.size(),
Expand Down