mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-01-06 08:41:10 +01:00
Run Clang-tidy with modernize-use-auto (#1077)
* Run clang-tidy modify with modernize-use-auto * Use using instead of typedef
This commit is contained in:
parent
a0bd9adfef
commit
2983f5a89a
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
Checks: 'google-readability-casting,modernize-use-default-member-init,modernize-use-using,readability-redundant-member-init'
|
Checks: 'google-readability-casting,modernize-use-default-member-init,modernize-use-using,modernize-use-auto,readability-redundant-member-init'
|
||||||
WarningsAsErrors: ''
|
WarningsAsErrors: ''
|
||||||
HeaderFilterRegex: ''
|
HeaderFilterRegex: ''
|
||||||
AnalyzeTemporaryDtors: false
|
AnalyzeTemporaryDtors: false
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
const std::string rawJson = R"({"Age": 20, "Name": "colin"})";
|
const std::string rawJson = R"({"Age": 20, "Name": "colin"})";
|
||||||
const int rawJsonLength = static_cast<int>(rawJson.length());
|
const auto rawJsonLength = static_cast<int>(rawJson.length());
|
||||||
constexpr bool shouldUseOldWay = false;
|
constexpr bool shouldUseOldWay = false;
|
||||||
JSONCPP_STRING err;
|
JSONCPP_STRING err;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
|
@ -119,23 +119,23 @@ extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
|
|||||||
#endif // if !defined(JSON_IS_AMALGAMATION)
|
#endif // if !defined(JSON_IS_AMALGAMATION)
|
||||||
|
|
||||||
namespace Json {
|
namespace Json {
|
||||||
typedef int Int;
|
using Int = int;
|
||||||
typedef unsigned int UInt;
|
using UInt = unsigned int;
|
||||||
#if defined(JSON_NO_INT64)
|
#if defined(JSON_NO_INT64)
|
||||||
typedef int LargestInt;
|
using LargestInt = int;
|
||||||
typedef unsigned int LargestUInt;
|
using LargestUInt = unsigned int;
|
||||||
#undef JSON_HAS_INT64
|
#undef JSON_HAS_INT64
|
||||||
#else // if defined(JSON_NO_INT64)
|
#else // if defined(JSON_NO_INT64)
|
||||||
// For Microsoft Visual use specific types as long long is not supported
|
// For Microsoft Visual use specific types as long long is not supported
|
||||||
#if defined(_MSC_VER) // Microsoft Visual Studio
|
#if defined(_MSC_VER) // Microsoft Visual Studio
|
||||||
typedef __int64 Int64;
|
using Int64 = __int64;
|
||||||
typedef unsigned __int64 UInt64;
|
using UInt64 = unsigned __int64;
|
||||||
#else // if defined(_MSC_VER) // Other platforms, use long long
|
#else // if defined(_MSC_VER) // Other platforms, use long long
|
||||||
typedef int64_t Int64;
|
using Int64 = int64_t;
|
||||||
typedef uint64_t UInt64;
|
using UInt64 = uint64_t;
|
||||||
#endif // if defined(_MSC_VER)
|
#endif // if defined(_MSC_VER)
|
||||||
typedef Int64 LargestInt;
|
using LargestInt = Int64;
|
||||||
typedef UInt64 LargestUInt;
|
using LargestUInt = UInt64;
|
||||||
#define JSON_HAS_INT64
|
#define JSON_HAS_INT64
|
||||||
#endif // if defined(JSON_NO_INT64)
|
#endif // if defined(JSON_NO_INT64)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class CharReaderBuilder;
|
|||||||
class Features;
|
class Features;
|
||||||
|
|
||||||
// value.h
|
// value.h
|
||||||
typedef unsigned int ArrayIndex;
|
using ArrayIndex = unsigned int;
|
||||||
class StaticString;
|
class StaticString;
|
||||||
class Path;
|
class Path;
|
||||||
class PathArgument;
|
class PathArgument;
|
||||||
|
@ -36,8 +36,8 @@ namespace Json {
|
|||||||
class JSONCPP_DEPRECATED(
|
class JSONCPP_DEPRECATED(
|
||||||
"Use CharReader and CharReaderBuilder instead.") JSON_API Reader {
|
"Use CharReader and CharReaderBuilder instead.") JSON_API Reader {
|
||||||
public:
|
public:
|
||||||
typedef char Char;
|
using Char = char;
|
||||||
typedef const Char* Location;
|
using Location = const Char*;
|
||||||
|
|
||||||
/** \brief An error tagged with where in the JSON text it was encountered.
|
/** \brief An error tagged with where in the JSON text it was encountered.
|
||||||
*
|
*
|
||||||
@ -187,7 +187,7 @@ private:
|
|||||||
Location extra_;
|
Location extra_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::deque<ErrorInfo> Errors;
|
using Errors = std::deque<ErrorInfo>;
|
||||||
|
|
||||||
bool readToken(Token& token);
|
bool readToken(Token& token);
|
||||||
void skipSpaces();
|
void skipSpaces();
|
||||||
@ -226,7 +226,7 @@ private:
|
|||||||
static bool containsNewLine(Location begin, Location end);
|
static bool containsNewLine(Location begin, Location end);
|
||||||
static String normalizeEOL(Location begin, Location end);
|
static String normalizeEOL(Location begin, Location end);
|
||||||
|
|
||||||
typedef std::stack<Value*> Nodes;
|
using Nodes = std::stack<Value*>;
|
||||||
Nodes nodes_;
|
Nodes nodes_;
|
||||||
Errors errors_;
|
Errors errors_;
|
||||||
String document_;
|
String document_;
|
||||||
|
@ -176,21 +176,21 @@ class JSON_API Value {
|
|||||||
friend class ValueIteratorBase;
|
friend class ValueIteratorBase;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef std::vector<String> Members;
|
using Members = std::vector<String>;
|
||||||
typedef ValueIterator iterator;
|
using iterator = ValueIterator;
|
||||||
typedef ValueConstIterator const_iterator;
|
using const_iterator = ValueConstIterator;
|
||||||
typedef Json::UInt UInt;
|
using UInt = Json::UInt;
|
||||||
typedef Json::Int Int;
|
using Int = Json::Int;
|
||||||
#if defined(JSON_HAS_INT64)
|
#if defined(JSON_HAS_INT64)
|
||||||
typedef Json::UInt64 UInt64;
|
using UInt64 = Json::UInt64;
|
||||||
typedef Json::Int64 Int64;
|
using Int64 = Json::Int64;
|
||||||
#endif // defined(JSON_HAS_INT64)
|
#endif // defined(JSON_HAS_INT64)
|
||||||
typedef Json::LargestInt LargestInt;
|
using LargestInt = Json::LargestInt;
|
||||||
typedef Json::LargestUInt LargestUInt;
|
using LargestUInt = Json::LargestUInt;
|
||||||
typedef Json::ArrayIndex ArrayIndex;
|
using ArrayIndex = Json::ArrayIndex;
|
||||||
|
|
||||||
// Required for boost integration, e. g. BOOST_TEST
|
// Required for boost integration, e. g. BOOST_TEST
|
||||||
typedef std::string value_type;
|
using value_type = std::string;
|
||||||
|
|
||||||
#if JSON_USE_NULLREF
|
#if JSON_USE_NULLREF
|
||||||
// Binary compatibility kludges, do not use.
|
// Binary compatibility kludges, do not use.
|
||||||
@ -710,8 +710,8 @@ public:
|
|||||||
Value& make(Value& root) const;
|
Value& make(Value& root) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector<const PathArgument*> InArgs;
|
using InArgs = std::vector<const PathArgument*>;
|
||||||
typedef std::vector<PathArgument> Args;
|
using Args = std::vector<PathArgument>;
|
||||||
|
|
||||||
void makePath(const String& path, const InArgs& in);
|
void makePath(const String& path, const InArgs& in);
|
||||||
void addPathInArg(const String& path, const InArgs& in,
|
void addPathInArg(const String& path, const InArgs& in,
|
||||||
@ -726,10 +726,10 @@ private:
|
|||||||
*/
|
*/
|
||||||
class JSON_API ValueIteratorBase {
|
class JSON_API ValueIteratorBase {
|
||||||
public:
|
public:
|
||||||
typedef std::bidirectional_iterator_tag iterator_category;
|
using iterator_category = std::bidirectional_iterator_tag;
|
||||||
typedef unsigned int size_t;
|
using size_t = unsigned int;
|
||||||
typedef int difference_type;
|
using difference_type = int;
|
||||||
typedef ValueIteratorBase SelfType;
|
using SelfType = ValueIteratorBase;
|
||||||
|
|
||||||
bool operator==(const SelfType& other) const { return isEqual(other); }
|
bool operator==(const SelfType& other) const { return isEqual(other); }
|
||||||
|
|
||||||
@ -802,12 +802,12 @@ class JSON_API ValueConstIterator : public ValueIteratorBase {
|
|||||||
friend class Value;
|
friend class Value;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef const Value value_type;
|
using value_type = const Value;
|
||||||
// typedef unsigned int size_t;
|
// typedef unsigned int size_t;
|
||||||
// typedef int difference_type;
|
// typedef int difference_type;
|
||||||
typedef const Value& reference;
|
using reference = const Value&;
|
||||||
typedef const Value* pointer;
|
using pointer = const Value*;
|
||||||
typedef ValueConstIterator SelfType;
|
using SelfType = ValueConstIterator;
|
||||||
|
|
||||||
ValueConstIterator();
|
ValueConstIterator();
|
||||||
ValueConstIterator(ValueIterator const& other);
|
ValueConstIterator(ValueIterator const& other);
|
||||||
@ -853,12 +853,12 @@ class JSON_API ValueIterator : public ValueIteratorBase {
|
|||||||
friend class Value;
|
friend class Value;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef Value value_type;
|
using value_type = Value;
|
||||||
typedef unsigned int size_t;
|
using size_t = unsigned int;
|
||||||
typedef int difference_type;
|
using difference_type = int;
|
||||||
typedef Value& reference;
|
using reference = Value&;
|
||||||
typedef Value* pointer;
|
using pointer = Value*;
|
||||||
typedef ValueIterator SelfType;
|
using SelfType = ValueIterator;
|
||||||
|
|
||||||
ValueIterator();
|
ValueIterator();
|
||||||
explicit ValueIterator(const ValueConstIterator& other);
|
explicit ValueIterator(const ValueConstIterator& other);
|
||||||
|
@ -252,7 +252,7 @@ private:
|
|||||||
static bool hasCommentForValue(const Value& value);
|
static bool hasCommentForValue(const Value& value);
|
||||||
static String normalizeEOL(const String& text);
|
static String normalizeEOL(const String& text);
|
||||||
|
|
||||||
typedef std::vector<String> ChildValues;
|
using ChildValues = std::vector<String>;
|
||||||
|
|
||||||
ChildValues childValues_;
|
ChildValues childValues_;
|
||||||
String document_;
|
String document_;
|
||||||
@ -326,7 +326,7 @@ private:
|
|||||||
static bool hasCommentForValue(const Value& value);
|
static bool hasCommentForValue(const Value& value);
|
||||||
static String normalizeEOL(const String& text);
|
static String normalizeEOL(const String& text);
|
||||||
|
|
||||||
typedef std::vector<String> ChildValues;
|
using ChildValues = std::vector<String>;
|
||||||
|
|
||||||
ChildValues childValues_;
|
ChildValues childValues_;
|
||||||
OStream* document_;
|
OStream* document_;
|
||||||
|
@ -58,7 +58,7 @@ static Json::String readInputTestFile(const char* path) {
|
|||||||
return "";
|
return "";
|
||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
long const size = ftell(file);
|
long const size = ftell(file);
|
||||||
size_t const usize = static_cast<unsigned long>(size);
|
const auto usize = static_cast<size_t>(size);
|
||||||
fseek(file, 0, SEEK_SET);
|
fseek(file, 0, SEEK_SET);
|
||||||
char* buffer = new char[size + 1];
|
char* buffer = new char[size + 1];
|
||||||
buffer[size] = 0;
|
buffer[size] = 0;
|
||||||
|
@ -54,7 +54,7 @@ namespace Json {
|
|||||||
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
|
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
|
||||||
using CharReaderPtr = std::unique_ptr<CharReader>;
|
using CharReaderPtr = std::unique_ptr<CharReader>;
|
||||||
#else
|
#else
|
||||||
typedef std::auto_ptr<CharReader> CharReaderPtr;
|
using CharReaderPtr = std::auto_ptr<CharReader>;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Implementation of class Features
|
// Implementation of class Features
|
||||||
|
@ -71,7 +71,7 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Defines a char buffer for use with uintToString().
|
// Defines a char buffer for use with uintToString().
|
||||||
typedef char UIntToStringBuffer[uintToStringBufferSize];
|
using UIntToStringBuffer = char[uintToStringBufferSize];
|
||||||
|
|
||||||
/** Converts an unsigned integer to string.
|
/** Converts an unsigned integer to string.
|
||||||
* @param value Unsigned integer to convert to string
|
* @param value Unsigned integer to convert to string
|
||||||
|
@ -117,7 +117,7 @@ static inline char* duplicateStringValue(const char* value, size_t length) {
|
|||||||
if (length >= static_cast<size_t>(Value::maxInt))
|
if (length >= static_cast<size_t>(Value::maxInt))
|
||||||
length = Value::maxInt - 1;
|
length = Value::maxInt - 1;
|
||||||
|
|
||||||
char* newString = static_cast<char*>(malloc(length + 1));
|
auto newString = static_cast<char*>(malloc(length + 1));
|
||||||
if (newString == nullptr) {
|
if (newString == nullptr) {
|
||||||
throwRuntimeError("in Json::Value::duplicateStringValue(): "
|
throwRuntimeError("in Json::Value::duplicateStringValue(): "
|
||||||
"Failed to allocate string value buffer");
|
"Failed to allocate string value buffer");
|
||||||
@ -137,8 +137,8 @@ static inline char* duplicateAndPrefixStringValue(const char* value,
|
|||||||
sizeof(unsigned) - 1U,
|
sizeof(unsigned) - 1U,
|
||||||
"in Json::Value::duplicateAndPrefixStringValue(): "
|
"in Json::Value::duplicateAndPrefixStringValue(): "
|
||||||
"length too big for prefixing");
|
"length too big for prefixing");
|
||||||
unsigned actualLength = length + static_cast<unsigned>(sizeof(unsigned)) + 1U;
|
size_t actualLength = sizeof(length) + length + 1;
|
||||||
char* newString = static_cast<char*>(malloc(actualLength));
|
auto newString = static_cast<char*>(malloc(actualLength));
|
||||||
if (newString == nullptr) {
|
if (newString == nullptr) {
|
||||||
throwRuntimeError("in Json::Value::duplicateAndPrefixStringValue(): "
|
throwRuntimeError("in Json::Value::duplicateAndPrefixStringValue(): "
|
||||||
"Failed to allocate string value buffer");
|
"Failed to allocate string value buffer");
|
||||||
@ -518,9 +518,10 @@ bool Value::operator<(const Value& other) const {
|
|||||||
}
|
}
|
||||||
case arrayValue:
|
case arrayValue:
|
||||||
case objectValue: {
|
case objectValue: {
|
||||||
int delta = int(value_.map_->size() - other.value_.map_->size());
|
auto thisSize = value_.map_->size();
|
||||||
if (delta)
|
auto otherSize = other.value_.map_->size();
|
||||||
return delta < 0;
|
if (thisSize != otherSize)
|
||||||
|
return thisSize < otherSize;
|
||||||
return (*value_.map_) < (*other.value_.map_);
|
return (*value_.map_) < (*other.value_.map_);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -86,7 +86,7 @@ namespace Json {
|
|||||||
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
|
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
|
||||||
using StreamWriterPtr = std::unique_ptr<StreamWriter>;
|
using StreamWriterPtr = std::unique_ptr<StreamWriter>;
|
||||||
#else
|
#else
|
||||||
typedef std::auto_ptr<StreamWriter> StreamWriterPtr;
|
using StreamWriterPtr = std::auto_ptr<StreamWriter>;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
String valueToString(LargestInt value) {
|
String valueToString(LargestInt value) {
|
||||||
|
@ -45,7 +45,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||||||
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
|
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
|
||||||
|
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
const char* data_str = reinterpret_cast<const char*>(data);
|
const auto data_str = reinterpret_cast<const char*>(data);
|
||||||
try {
|
try {
|
||||||
reader->parse(data_str, data_str + size, &root, nullptr);
|
reader->parse(data_str, data_str + size, &root, nullptr);
|
||||||
} catch (Json::Exception const&) {
|
} catch (Json::Exception const&) {
|
||||||
|
@ -42,7 +42,7 @@ public:
|
|||||||
/// Must be a POD to allow inline initialisation without stepping
|
/// Must be a POD to allow inline initialisation without stepping
|
||||||
/// into the debugger.
|
/// into the debugger.
|
||||||
struct PredicateContext {
|
struct PredicateContext {
|
||||||
typedef unsigned int Id;
|
using Id = unsigned int;
|
||||||
Id id_;
|
Id id_;
|
||||||
const char* file_;
|
const char* file_;
|
||||||
unsigned int line_;
|
unsigned int line_;
|
||||||
@ -102,7 +102,7 @@ private:
|
|||||||
static Json::String indentText(const Json::String& text,
|
static Json::String indentText(const Json::String& text,
|
||||||
const Json::String& indent);
|
const Json::String& indent);
|
||||||
|
|
||||||
typedef std::deque<Failure> Failures;
|
using Failures = std::deque<Failure>;
|
||||||
Failures failures_;
|
Failures failures_;
|
||||||
Json::String name_;
|
Json::String name_;
|
||||||
PredicateContext rootPredicateNode_;
|
PredicateContext rootPredicateNode_;
|
||||||
@ -129,7 +129,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Function pointer type for TestCase factory
|
/// Function pointer type for TestCase factory
|
||||||
typedef TestCase* (*TestCaseFactory)();
|
using TestCaseFactory = TestCase* (*)();
|
||||||
|
|
||||||
class Runner {
|
class Runner {
|
||||||
public:
|
public:
|
||||||
@ -168,7 +168,7 @@ private:
|
|||||||
static void preventDialogOnCrash();
|
static void preventDialogOnCrash();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::deque<TestCaseFactory> Factories;
|
using Factories = std::deque<TestCaseFactory>;
|
||||||
Factories tests_;
|
Factories tests_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user