mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-06-07 17:14:56 +02:00
STYLE: Avoid unnecessary conversions from size_t to unsigned int
Make the index values consistent with size_t.
This commit is contained in:
parent
d11732043a
commit
21a4185634
@ -888,7 +888,7 @@ public:
|
|||||||
bool failIfExtra_;
|
bool failIfExtra_;
|
||||||
bool rejectDupKeys_;
|
bool rejectDupKeys_;
|
||||||
bool allowSpecialFloats_;
|
bool allowSpecialFloats_;
|
||||||
int stackLimit_;
|
size_t stackLimit_;
|
||||||
}; // OurFeatures
|
}; // OurFeatures
|
||||||
|
|
||||||
// exact copy of Implementation of class Features
|
// exact copy of Implementation of class Features
|
||||||
@ -1087,7 +1087,7 @@ bool OurReader::parse(const char* beginDoc,
|
|||||||
|
|
||||||
bool OurReader::readValue() {
|
bool OurReader::readValue() {
|
||||||
// To preserve the old behaviour we cast size_t to int.
|
// To preserve the old behaviour we cast size_t to int.
|
||||||
if (static_cast<int>(nodes_.size()) > features_.stackLimit_)
|
if (nodes_.size() > features_.stackLimit_)
|
||||||
throwRuntimeError("Exceeded stackLimit in readValue().");
|
throwRuntimeError("Exceeded stackLimit in readValue().");
|
||||||
Token token;
|
Token token;
|
||||||
skipCommentTokens(token);
|
skipCommentTokens(token);
|
||||||
@ -1917,7 +1917,11 @@ CharReader* CharReaderBuilder::newCharReader() const {
|
|||||||
settings_["allowDroppedNullPlaceholders"].asBool();
|
settings_["allowDroppedNullPlaceholders"].asBool();
|
||||||
features.allowNumericKeys_ = settings_["allowNumericKeys"].asBool();
|
features.allowNumericKeys_ = settings_["allowNumericKeys"].asBool();
|
||||||
features.allowSingleQuotes_ = settings_["allowSingleQuotes"].asBool();
|
features.allowSingleQuotes_ = settings_["allowSingleQuotes"].asBool();
|
||||||
features.stackLimit_ = settings_["stackLimit"].asInt();
|
#if defined(JSON_HAS_INT64)
|
||||||
|
features.stackLimit_ = settings_["stackLimit"].asUInt64();
|
||||||
|
#else
|
||||||
|
features.stackLimit_ = settings_["stackLimit"].asUInt();
|
||||||
|
#endif
|
||||||
features.failIfExtra_ = settings_["failIfExtra"].asBool();
|
features.failIfExtra_ = settings_["failIfExtra"].asBool();
|
||||||
features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool();
|
features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool();
|
||||||
features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
|
features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
|
||||||
|
@ -224,18 +224,18 @@ Runner& Runner::add(TestCaseFactory factory) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Runner::testCount() const {
|
size_t Runner::testCount() const {
|
||||||
return static_cast<unsigned int>(tests_.size());
|
return tests_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONCPP_STRING Runner::testNameAt(unsigned int index) const {
|
JSONCPP_STRING Runner::testNameAt(size_t index) const {
|
||||||
TestCase* test = tests_[index]();
|
TestCase* test = tests_[index]();
|
||||||
JSONCPP_STRING name = test->testName();
|
JSONCPP_STRING name = test->testName();
|
||||||
delete test;
|
delete test;
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner::runTestAt(unsigned int index, TestResult& result) const {
|
void Runner::runTestAt(size_t index, TestResult& result) const {
|
||||||
TestCase* test = tests_[index]();
|
TestCase* test = tests_[index]();
|
||||||
result.setTestName(test->testName());
|
result.setTestName(test->testName());
|
||||||
printf("Testing %s: ", test->testName());
|
printf("Testing %s: ", test->testName());
|
||||||
@ -257,9 +257,9 @@ void Runner::runTestAt(unsigned int index, TestResult& result) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Runner::runAllTest(bool printSummary) const {
|
bool Runner::runAllTest(bool printSummary) const {
|
||||||
unsigned int count = testCount();
|
size_t const count = testCount();
|
||||||
std::deque<TestResult> failures;
|
std::deque<TestResult> failures;
|
||||||
for (unsigned int index = 0; index < count; ++index) {
|
for (size_t index = 0; index < count; ++index) {
|
||||||
TestResult result;
|
TestResult result;
|
||||||
runTestAt(index, result);
|
runTestAt(index, result);
|
||||||
if (result.failed()) {
|
if (result.failed()) {
|
||||||
@ -269,7 +269,7 @@ bool Runner::runAllTest(bool printSummary) const {
|
|||||||
|
|
||||||
if (failures.empty()) {
|
if (failures.empty()) {
|
||||||
if (printSummary) {
|
if (printSummary) {
|
||||||
printf("All %u tests passed\n", count);
|
printf("All %zu tests passed\n", count);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -278,19 +278,19 @@ bool Runner::runAllTest(bool printSummary) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (printSummary) {
|
if (printSummary) {
|
||||||
auto failedCount = static_cast<unsigned int>(failures.size());
|
size_t const failedCount = failures.size();
|
||||||
unsigned int passedCount = count - failedCount;
|
size_t const passedCount = count - failedCount;
|
||||||
printf("%u/%u tests passed (%u failure(s))\n", passedCount, count,
|
printf("%zu/%zu tests passed (%zu failure(s))\n",
|
||||||
failedCount);
|
passedCount, count, failedCount);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Runner::testIndex(const JSONCPP_STRING& testName,
|
bool Runner::testIndex(const JSONCPP_STRING& testName,
|
||||||
unsigned int& indexOut) const {
|
size_t& indexOut) const {
|
||||||
unsigned int count = testCount();
|
const size_t count = testCount();
|
||||||
for (unsigned int index = 0; index < count; ++index) {
|
for (size_t index = 0; index < count; ++index) {
|
||||||
if (testNameAt(index) == testName) {
|
if (testNameAt(index) == testName) {
|
||||||
indexOut = index;
|
indexOut = index;
|
||||||
return true;
|
return true;
|
||||||
@ -300,8 +300,8 @@ bool Runner::testIndex(const JSONCPP_STRING& testName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Runner::listTests() const {
|
void Runner::listTests() const {
|
||||||
unsigned int count = testCount();
|
const size_t count = testCount();
|
||||||
for (unsigned int index = 0; index < count; ++index) {
|
for (size_t index = 0; index < count; ++index) {
|
||||||
printf("%s\n", testNameAt(index).c_str());
|
printf("%s\n", testNameAt(index).c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -319,7 +319,7 @@ int Runner::runCommandLine(int argc, const char* argv[]) const {
|
|||||||
} else if (opt == "--test") {
|
} else if (opt == "--test") {
|
||||||
++index;
|
++index;
|
||||||
if (index < argc) {
|
if (index < argc) {
|
||||||
unsigned int testNameIndex;
|
size_t testNameIndex;
|
||||||
if (testIndex(argv[index], testNameIndex)) {
|
if (testIndex(argv[index], testNameIndex)) {
|
||||||
subrunner.add(tests_[testNameIndex]);
|
subrunner.add(tests_[testNameIndex]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,13 +151,13 @@ public:
|
|||||||
bool runAllTest(bool printSummary) const;
|
bool runAllTest(bool printSummary) const;
|
||||||
|
|
||||||
/// Returns the number of test case in the suite
|
/// Returns the number of test case in the suite
|
||||||
unsigned int testCount() const;
|
size_t testCount() const;
|
||||||
|
|
||||||
/// Returns the name of the test case at the specified index
|
/// Returns the name of the test case at the specified index
|
||||||
JSONCPP_STRING testNameAt(unsigned int index) const;
|
JSONCPP_STRING testNameAt(size_t index) const;
|
||||||
|
|
||||||
/// Runs the test case at the specified index using the specified TestResult
|
/// Runs the test case at the specified index using the specified TestResult
|
||||||
void runTestAt(unsigned int index, TestResult& result) const;
|
void runTestAt(size_t index, TestResult& result) const;
|
||||||
|
|
||||||
static void printUsage(const char* appName);
|
static void printUsage(const char* appName);
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ private: // prevents copy construction and assignment
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void listTests() const;
|
void listTests() const;
|
||||||
bool testIndex(const JSONCPP_STRING& testName, unsigned int& indexOut) const;
|
bool testIndex(const JSONCPP_STRING& testName, size_t& indexOut) const;
|
||||||
static void preventDialogOnCrash();
|
static void preventDialogOnCrash();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user