mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-18 03:29:46 +02:00
* Issue #958: Travis CI should enfore clang-format standards
This patch adds clang format support to the travis bots.
* Update path
* Roll back to version 8 since 9 is in test
* Cleanup clang
* Revert "Delete JSONCPP_DEPRECATED, use [[deprecated]] instead. (#978)" (#1029)
This reverts commit b27c83f691
.
This commit is contained in:
@@ -68,8 +68,8 @@ static Json::String readInputTestFile(const char* path) {
|
||||
return text;
|
||||
}
|
||||
|
||||
static void
|
||||
printValueTree(FILE* fout, Json::Value& value, const Json::String& path = ".") {
|
||||
static void printValueTree(FILE* fout, Json::Value& value,
|
||||
const Json::String& path = ".") {
|
||||
if (value.hasComment(Json::commentBefore)) {
|
||||
fprintf(fout, "%s\n", value.getComment(Json::commentBefore).c_str());
|
||||
}
|
||||
@@ -125,8 +125,7 @@ printValueTree(FILE* fout, Json::Value& value, const Json::String& path = ".") {
|
||||
static int parseAndSaveValueTree(const Json::String& input,
|
||||
const Json::String& actual,
|
||||
const Json::String& kind,
|
||||
const Json::Features& features,
|
||||
bool parseOnly,
|
||||
const Json::Features& features, bool parseOnly,
|
||||
Json::Value* root) {
|
||||
Json::Reader reader(features);
|
||||
bool parsingSuccessful =
|
||||
|
@@ -89,8 +89,7 @@ Reader::Reader() : features_(Features::all()) {}
|
||||
|
||||
Reader::Reader(const Features& features) : features_(features) {}
|
||||
|
||||
bool Reader::parse(const std::string& document,
|
||||
Value& root,
|
||||
bool Reader::parse(const std::string& document, Value& root,
|
||||
bool collectComments) {
|
||||
document_.assign(document.begin(), document.end());
|
||||
const char* begin = document_.c_str();
|
||||
@@ -111,9 +110,7 @@ bool Reader::parse(std::istream& is, Value& root, bool collectComments) {
|
||||
return parse(doc.data(), doc.data() + doc.size(), root, collectComments);
|
||||
}
|
||||
|
||||
bool Reader::parse(const char* beginDoc,
|
||||
const char* endDoc,
|
||||
Value& root,
|
||||
bool Reader::parse(const char* beginDoc, const char* endDoc, Value& root,
|
||||
bool collectComments) {
|
||||
if (!features_.allowComments_) {
|
||||
collectComments = false;
|
||||
@@ -373,8 +370,7 @@ String Reader::normalizeEOL(Reader::Location begin, Reader::Location end) {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
void Reader::addComment(Location begin,
|
||||
Location end,
|
||||
void Reader::addComment(Location begin, Location end,
|
||||
CommentPlacement placement) {
|
||||
assert(collectComments_);
|
||||
const String& normalized = normalizeEOL(begin, end);
|
||||
@@ -677,10 +673,8 @@ bool Reader::decodeString(Token& token, String& decoded) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::decodeUnicodeCodePoint(Token& token,
|
||||
Location& current,
|
||||
Location end,
|
||||
unsigned int& unicode) {
|
||||
bool Reader::decodeUnicodeCodePoint(Token& token, Location& current,
|
||||
Location end, unsigned int& unicode) {
|
||||
|
||||
if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
|
||||
return false;
|
||||
@@ -704,8 +698,7 @@ bool Reader::decodeUnicodeCodePoint(Token& token,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::decodeUnicodeEscapeSequence(Token& token,
|
||||
Location& current,
|
||||
bool Reader::decodeUnicodeEscapeSequence(Token& token, Location& current,
|
||||
Location end,
|
||||
unsigned int& ret_unicode) {
|
||||
if (end - current < 4)
|
||||
@@ -753,8 +746,7 @@ bool Reader::recoverFromError(TokenType skipUntilToken) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Reader::addErrorAndRecover(const String& message,
|
||||
Token& token,
|
||||
bool Reader::addErrorAndRecover(const String& message, Token& token,
|
||||
TokenType skipUntilToken) {
|
||||
addError(message, token);
|
||||
return recoverFromError(skipUntilToken);
|
||||
@@ -768,8 +760,7 @@ Reader::Char Reader::getNextChar() {
|
||||
return *current_++;
|
||||
}
|
||||
|
||||
void Reader::getLocationLineAndColumn(Location location,
|
||||
int& line,
|
||||
void Reader::getLocationLineAndColumn(Location location, int& line,
|
||||
int& column) const {
|
||||
Location current = begin_;
|
||||
Location lastLineStart = current;
|
||||
@@ -845,8 +836,7 @@ bool Reader::pushError(const Value& value, const String& message) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Reader::pushError(const Value& value,
|
||||
const String& message,
|
||||
bool Reader::pushError(const Value& value, const String& message,
|
||||
const Value& extra) {
|
||||
ptrdiff_t const length = end_ - begin_;
|
||||
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
|
||||
@@ -900,9 +890,7 @@ public:
|
||||
};
|
||||
|
||||
OurReader(OurFeatures const& features);
|
||||
bool parse(const char* beginDoc,
|
||||
const char* endDoc,
|
||||
Value& root,
|
||||
bool parse(const char* beginDoc, const char* endDoc, Value& root,
|
||||
bool collectComments = true);
|
||||
String getFormattedErrorMessages() const;
|
||||
std::vector<StructuredError> getStructuredErrors() const;
|
||||
@@ -968,24 +956,19 @@ private:
|
||||
bool decodeString(Token& token, String& decoded);
|
||||
bool decodeDouble(Token& token);
|
||||
bool decodeDouble(Token& token, Value& decoded);
|
||||
bool decodeUnicodeCodePoint(Token& token,
|
||||
Location& current,
|
||||
Location end,
|
||||
bool decodeUnicodeCodePoint(Token& token, Location& current, Location end,
|
||||
unsigned int& unicode);
|
||||
bool decodeUnicodeEscapeSequence(Token& token,
|
||||
Location& current,
|
||||
Location end,
|
||||
unsigned int& unicode);
|
||||
bool decodeUnicodeEscapeSequence(Token& token, Location& current,
|
||||
Location end, unsigned int& unicode);
|
||||
bool addError(const String& message, Token& token, Location extra = nullptr);
|
||||
bool recoverFromError(TokenType skipUntilToken);
|
||||
bool addErrorAndRecover(const String& message,
|
||||
Token& token,
|
||||
bool addErrorAndRecover(const String& message, Token& token,
|
||||
TokenType skipUntilToken);
|
||||
void skipUntilSpace();
|
||||
Value& currentValue();
|
||||
Char getNextChar();
|
||||
void
|
||||
getLocationLineAndColumn(Location location, int& line, int& column) const;
|
||||
void getLocationLineAndColumn(Location location, int& line,
|
||||
int& column) const;
|
||||
String getLocationLineAndColumn(Location location) const;
|
||||
void addComment(Location begin, Location end, CommentPlacement placement);
|
||||
void skipCommentTokens(Token& token);
|
||||
@@ -1022,9 +1005,7 @@ OurReader::OurReader(OurFeatures const& features)
|
||||
: begin_(), end_(), current_(), lastValueEnd_(), lastValue_(),
|
||||
features_(features), collectComments_() {}
|
||||
|
||||
bool OurReader::parse(const char* beginDoc,
|
||||
const char* endDoc,
|
||||
Value& root,
|
||||
bool OurReader::parse(const char* beginDoc, const char* endDoc, Value& root,
|
||||
bool collectComments) {
|
||||
if (!features_.allowComments_) {
|
||||
collectComments = false;
|
||||
@@ -1341,8 +1322,7 @@ String OurReader::normalizeEOL(OurReader::Location begin,
|
||||
return normalized;
|
||||
}
|
||||
|
||||
void OurReader::addComment(Location begin,
|
||||
Location end,
|
||||
void OurReader::addComment(Location begin, Location end,
|
||||
CommentPlacement placement) {
|
||||
assert(collectComments_);
|
||||
const String& normalized = normalizeEOL(begin, end);
|
||||
@@ -1700,10 +1680,8 @@ bool OurReader::decodeString(Token& token, String& decoded) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OurReader::decodeUnicodeCodePoint(Token& token,
|
||||
Location& current,
|
||||
Location end,
|
||||
unsigned int& unicode) {
|
||||
bool OurReader::decodeUnicodeCodePoint(Token& token, Location& current,
|
||||
Location end, unsigned int& unicode) {
|
||||
|
||||
if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
|
||||
return false;
|
||||
@@ -1727,8 +1705,7 @@ bool OurReader::decodeUnicodeCodePoint(Token& token,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OurReader::decodeUnicodeEscapeSequence(Token& token,
|
||||
Location& current,
|
||||
bool OurReader::decodeUnicodeEscapeSequence(Token& token, Location& current,
|
||||
Location end,
|
||||
unsigned int& ret_unicode) {
|
||||
if (end - current < 4)
|
||||
@@ -1776,8 +1753,7 @@ bool OurReader::recoverFromError(TokenType skipUntilToken) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OurReader::addErrorAndRecover(const String& message,
|
||||
Token& token,
|
||||
bool OurReader::addErrorAndRecover(const String& message, Token& token,
|
||||
TokenType skipUntilToken) {
|
||||
addError(message, token);
|
||||
return recoverFromError(skipUntilToken);
|
||||
@@ -1791,8 +1767,7 @@ OurReader::Char OurReader::getNextChar() {
|
||||
return *current_++;
|
||||
}
|
||||
|
||||
void OurReader::getLocationLineAndColumn(Location location,
|
||||
int& line,
|
||||
void OurReader::getLocationLineAndColumn(Location location, int& line,
|
||||
int& column) const {
|
||||
Location current = begin_;
|
||||
Location lastLineStart = current;
|
||||
@@ -1863,8 +1838,7 @@ bool OurReader::pushError(const Value& value, const String& message) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OurReader::pushError(const Value& value,
|
||||
const String& message,
|
||||
bool OurReader::pushError(const Value& value, const String& message,
|
||||
const Value& extra) {
|
||||
ptrdiff_t length = end_ - begin_;
|
||||
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
|
||||
@@ -1891,9 +1865,7 @@ class OurCharReader : public CharReader {
|
||||
public:
|
||||
OurCharReader(bool collectComments, OurFeatures const& features)
|
||||
: collectComments_(collectComments), reader_(features) {}
|
||||
bool parse(char const* beginDoc,
|
||||
char const* endDoc,
|
||||
Value* root,
|
||||
bool parse(char const* beginDoc, char const* endDoc, Value* root,
|
||||
String* errs) override {
|
||||
bool ok = reader_.parse(beginDoc, endDoc, *root, collectComments_);
|
||||
if (errs) {
|
||||
@@ -1989,9 +1961,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
|
||||
//////////////////////////////////
|
||||
// global functions
|
||||
|
||||
bool parseFromStream(CharReader::Factory const& fact,
|
||||
IStream& sin,
|
||||
Value* root,
|
||||
bool parseFromStream(CharReader::Factory const& fact, IStream& sin, Value* root,
|
||||
String* errs) {
|
||||
OStringStream ssin;
|
||||
ssin << sin.rdbuf();
|
||||
|
@@ -22,10 +22,8 @@
|
||||
// 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) {
|
||||
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);
|
||||
@@ -34,10 +32,8 @@ static int msvc_pre1900_c99_vsnprintf(char* outBuf,
|
||||
return count;
|
||||
}
|
||||
|
||||
int JSON_API msvc_pre1900_c99_snprintf(char* outBuf,
|
||||
size_t size,
|
||||
const char* format,
|
||||
...) {
|
||||
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);
|
||||
@@ -156,10 +152,8 @@ static inline char* duplicateAndPrefixStringValue(const char* value,
|
||||
0; // to avoid buffer over-run accidents by users later
|
||||
return newString;
|
||||
}
|
||||
inline static void decodePrefixedString(bool isPrefixed,
|
||||
char const* prefixed,
|
||||
unsigned* length,
|
||||
char const** value) {
|
||||
inline static void decodePrefixedString(bool isPrefixed, char const* prefixed,
|
||||
unsigned* length, char const** value) {
|
||||
if (!isPrefixed) {
|
||||
*length = static_cast<unsigned>(strlen(prefixed));
|
||||
*value = prefixed;
|
||||
@@ -235,8 +229,7 @@ LogicError::LogicError(String const& msg) : Exception(msg) {}
|
||||
|
||||
Value::CZString::CZString(ArrayIndex index) : cstr_(nullptr), index_(index) {}
|
||||
|
||||
Value::CZString::CZString(char const* str,
|
||||
unsigned length,
|
||||
Value::CZString::CZString(char const* str, unsigned length,
|
||||
DuplicationPolicy allocate)
|
||||
: cstr_(str) {
|
||||
// allocate != duplicate
|
||||
@@ -1165,8 +1158,7 @@ Value& Value::append(Value&& value) {
|
||||
return this->value_.map_->emplace(size(), std::move(value)).first->second;
|
||||
}
|
||||
|
||||
Value Value::get(char const* begin,
|
||||
char const* end,
|
||||
Value Value::get(char const* begin, char const* end,
|
||||
Value const& defaultValue) const {
|
||||
Value const* found = find(begin, end);
|
||||
return !found ? defaultValue : *found;
|
||||
@@ -1564,11 +1556,8 @@ PathArgument::PathArgument(const String& key)
|
||||
// class Path
|
||||
// //////////////////////////////////////////////////////////////////
|
||||
|
||||
Path::Path(const String& path,
|
||||
const PathArgument& a1,
|
||||
const PathArgument& a2,
|
||||
const PathArgument& a3,
|
||||
const PathArgument& a4,
|
||||
Path::Path(const String& path, const PathArgument& a1, const PathArgument& a2,
|
||||
const PathArgument& a3, const PathArgument& a4,
|
||||
const PathArgument& a5) {
|
||||
InArgs in;
|
||||
in.reserve(5);
|
||||
@@ -1611,8 +1600,7 @@ void Path::makePath(const String& path, const InArgs& in) {
|
||||
}
|
||||
}
|
||||
|
||||
void Path::addPathInArg(const String& /*path*/,
|
||||
const InArgs& in,
|
||||
void Path::addPathInArg(const String& /*path*/, const InArgs& in,
|
||||
InArgs::const_iterator& itInArg,
|
||||
PathArgument::Kind kind) {
|
||||
if (itInArg == in.end()) {
|
||||
|
@@ -122,10 +122,8 @@ String valueToString(UInt value) { return valueToString(LargestUInt(value)); }
|
||||
#endif // # if defined(JSON_HAS_INT64)
|
||||
|
||||
namespace {
|
||||
String valueToString(double value,
|
||||
bool useSpecialFloats,
|
||||
unsigned int precision,
|
||||
PrecisionType precisionType) {
|
||||
String valueToString(double value, bool useSpecialFloats,
|
||||
unsigned int precision, PrecisionType precisionType) {
|
||||
// Print into the buffer. We need not request the alternative representation
|
||||
// that always has a decimal point because JSON doesn't distinguish the
|
||||
// concepts of reals and integers.
|
||||
@@ -168,8 +166,7 @@ String valueToString(double value,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
String valueToString(double value,
|
||||
unsigned int precision,
|
||||
String valueToString(double value, unsigned int precision,
|
||||
PrecisionType precisionType) {
|
||||
return valueToString(value, false, precision, precisionType);
|
||||
}
|
||||
@@ -864,14 +861,10 @@ struct CommentStyle {
|
||||
};
|
||||
|
||||
struct BuiltStyledStreamWriter : public StreamWriter {
|
||||
BuiltStyledStreamWriter(String indentation,
|
||||
CommentStyle::Enum cs,
|
||||
String colonSymbol,
|
||||
String nullSymbol,
|
||||
String endingLineFeedSymbol,
|
||||
bool useSpecialFloats,
|
||||
unsigned int precision,
|
||||
PrecisionType precisionType);
|
||||
BuiltStyledStreamWriter(String indentation, CommentStyle::Enum cs,
|
||||
String colonSymbol, String nullSymbol,
|
||||
String endingLineFeedSymbol, bool useSpecialFloats,
|
||||
unsigned int precision, PrecisionType precisionType);
|
||||
int write(Value const& root, OStream* sout) override;
|
||||
|
||||
private:
|
||||
@@ -903,14 +896,10 @@ private:
|
||||
unsigned int precision_;
|
||||
PrecisionType precisionType_;
|
||||
};
|
||||
BuiltStyledStreamWriter::BuiltStyledStreamWriter(String indentation,
|
||||
CommentStyle::Enum cs,
|
||||
String colonSymbol,
|
||||
String nullSymbol,
|
||||
String endingLineFeedSymbol,
|
||||
bool useSpecialFloats,
|
||||
unsigned int precision,
|
||||
PrecisionType precisionType)
|
||||
BuiltStyledStreamWriter::BuiltStyledStreamWriter(
|
||||
String indentation, CommentStyle::Enum cs, String colonSymbol,
|
||||
String nullSymbol, String endingLineFeedSymbol, bool useSpecialFloats,
|
||||
unsigned int precision, PrecisionType precisionType)
|
||||
: rightMargin_(74), indentation_(std::move(indentation)), cs_(cs),
|
||||
colonSymbol_(std::move(colonSymbol)), nullSymbol_(std::move(nullSymbol)),
|
||||
endingLineFeedSymbol_(std::move(endingLineFeedSymbol)),
|
||||
|
@@ -82,8 +82,8 @@ TestResult::TestResult() {
|
||||
|
||||
void TestResult::setTestName(const Json::String& name) { name_ = name; }
|
||||
|
||||
TestResult&
|
||||
TestResult::addFailure(const char* file, unsigned int line, const char* expr) {
|
||||
TestResult& TestResult::addFailure(const char* file, unsigned int line,
|
||||
const char* expr) {
|
||||
/// Walks the PredicateContext stack adding them to failures_ if not already
|
||||
/// added.
|
||||
unsigned int nestingLevel = 0;
|
||||
@@ -107,10 +107,8 @@ TestResult::addFailure(const char* file, unsigned int line, const char* expr) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void TestResult::addFailureInfo(const char* file,
|
||||
unsigned int line,
|
||||
const char* expr,
|
||||
unsigned int nestingLevel) {
|
||||
void TestResult::addFailureInfo(const char* file, unsigned int line,
|
||||
const char* expr, unsigned int nestingLevel) {
|
||||
Failure failure;
|
||||
failure.file_ = file;
|
||||
failure.line_ = line;
|
||||
@@ -342,8 +340,8 @@ int Runner::runCommandLine(int argc, const char* argv[]) const {
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||
// Hook MSVCRT assertions to prevent dialog from appearing
|
||||
static int
|
||||
msvcrtSilentReportHook(int reportType, char* message, int* /*returnValue*/) {
|
||||
static int msvcrtSilentReportHook(int reportType, char* message,
|
||||
int* /*returnValue*/) {
|
||||
// The default CRT handling of error and assertion is to display
|
||||
// an error dialog to the user.
|
||||
// Instead, when an error or an assertion occurs, we force the
|
||||
@@ -418,12 +416,9 @@ Json::String ToJsonString(std::string in) {
|
||||
}
|
||||
#endif
|
||||
|
||||
TestResult& checkStringEqual(TestResult& result,
|
||||
const Json::String& expected,
|
||||
const Json::String& actual,
|
||||
const char* file,
|
||||
unsigned int line,
|
||||
const char* expr) {
|
||||
TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
|
||||
const Json::String& actual, const char* file,
|
||||
unsigned int line, const char* expr) {
|
||||
if (expected != actual) {
|
||||
result.addFailure(file, line, expr);
|
||||
result << "Expected: '" << expected << "'\n";
|
||||
|
@@ -68,8 +68,8 @@ public:
|
||||
void setTestName(const Json::String& name);
|
||||
|
||||
/// Adds an assertion failure.
|
||||
TestResult&
|
||||
addFailure(const char* file, unsigned int line, const char* expr = nullptr);
|
||||
TestResult& addFailure(const char* file, unsigned int line,
|
||||
const char* expr = nullptr);
|
||||
|
||||
/// Removes the last PredicateContext added to the predicate stack
|
||||
/// chained list.
|
||||
@@ -98,9 +98,7 @@ public:
|
||||
private:
|
||||
TestResult& addToLastFailure(const Json::String& message);
|
||||
/// Adds a failure or a predicate context
|
||||
void addFailureInfo(const char* file,
|
||||
unsigned int line,
|
||||
const char* expr,
|
||||
void addFailureInfo(const char* file, unsigned int line, const char* expr,
|
||||
unsigned int nestingLevel);
|
||||
static Json::String indentText(const Json::String& text,
|
||||
const Json::String& indent);
|
||||
@@ -176,12 +174,8 @@ private:
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
TestResult& checkEqual(TestResult& result,
|
||||
T expected,
|
||||
U actual,
|
||||
const char* file,
|
||||
unsigned int line,
|
||||
const char* expr) {
|
||||
TestResult& checkEqual(TestResult& result, T expected, U actual,
|
||||
const char* file, unsigned int line, const char* expr) {
|
||||
if (static_cast<U>(expected) != actual) {
|
||||
result.addFailure(file, line, expr);
|
||||
result << "Expected: " << static_cast<U>(expected) << "\n";
|
||||
@@ -196,12 +190,9 @@ Json::String ToJsonString(Json::String in);
|
||||
Json::String ToJsonString(std::string in);
|
||||
#endif
|
||||
|
||||
TestResult& checkStringEqual(TestResult& result,
|
||||
const Json::String& expected,
|
||||
const Json::String& actual,
|
||||
const char* file,
|
||||
unsigned int line,
|
||||
const char* expr);
|
||||
TestResult& checkStringEqual(TestResult& result, const Json::String& expected,
|
||||
const Json::String& actual, const char* file,
|
||||
unsigned int line, const char* expr);
|
||||
|
||||
} // namespace JsonTest
|
||||
|
||||
|
Reference in New Issue
Block a user