Skip to content

Commit bcad4e4

Browse files
nehebdota17
authored andcommitted
clang-tidy cleanups 2 (open-source-parsers#1048)
* [clang-tidy] Add explicit to single argument constructor Found with hicpp-explicit-conversions Signed-off-by: Rosen Penev <[email protected]> * [clang-tidy] Fix mismatching declaration Found with readability-inconsistent-declaration-parameter-name Signed-off-by: Rosen Penev <[email protected]> * [clang-tidy] Replace {} with = default Found with modernize-use-equals-default Signed-off-by: Rosen Penev <[email protected]> * [clang-tidy] Remove redundant .c_Str Found with readability-redundant-string-cstr Signed-off-by: Rosen Penev <[email protected]> * [clang-tidy] Simplify boolean expressions Found with readability-simplify-boolean-expr Signed-off-by: Rosen Penev <[email protected]> * [clang-tidy] Use std::move Found with modernize-pass-by-value Signed-off-by: Rosen Penev <[email protected]> * [clang-tidy] Uppercase literal suffixes Found with hicpp-uppercase-literal-suffix Signed-off-by: Rosen Penev <[email protected]>
1 parent 7329223 commit bcad4e4

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

include/json/value.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ class JSON_API Value {
657657
Comments& operator=(Comments&& that);
658658
bool has(CommentPlacement slot) const;
659659
String get(CommentPlacement slot) const;
660-
void set(CommentPlacement slot, String s);
660+
void set(CommentPlacement slot, String comment);
661661

662662
private:
663663
using Array = std::array<String, numberOfCommentPlacement>;
@@ -681,7 +681,7 @@ class JSON_API PathArgument {
681681
PathArgument();
682682
PathArgument(ArrayIndex index);
683683
PathArgument(const char* key);
684-
PathArgument(const String& key);
684+
PathArgument(String key);
685685

686686
private:
687687
enum Kind { kindNone = 0, kindIndex, kindKey };

src/lib_json/json_reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ class OurReader {
889889
String message;
890890
};
891891

892-
OurReader(OurFeatures const& features);
892+
explicit OurReader(OurFeatures const& features);
893893
bool parse(const char* beginDoc, const char* endDoc, Value& root,
894894
bool collectComments = true);
895895
String getFormattedErrorMessages() const;

src/lib_json/json_value.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ namespace Json {
203203

204204
#if JSON_USE_EXCEPTION
205205
Exception::Exception(String msg) : msg_(std::move(msg)) {}
206-
Exception::~Exception() JSONCPP_NOEXCEPT {}
206+
Exception::~Exception() JSONCPP_NOEXCEPT = default;
207207
char const* Exception::what() const JSONCPP_NOEXCEPT { return msg_.c_str(); }
208208
RuntimeError::RuntimeError(String const& msg) : Exception(msg) {}
209209
LogicError::LogicError(String const& msg) : Exception(msg) {}
@@ -263,7 +263,7 @@ Value::CZString::CZString(CZString&& other)
263263
Value::CZString::~CZString() {
264264
if (cstr_ && storage_.policy_ == duplicate) {
265265
releaseStringValue(const_cast<char*>(cstr_),
266-
storage_.length_ + 1u); // +1 for null terminating
266+
storage_.length_ + 1U); // +1 for null terminating
267267
// character for sake of
268268
// completeness but not actually
269269
// necessary
@@ -494,7 +494,7 @@ int Value::compare(const Value& other) const {
494494
bool Value::operator<(const Value& other) const {
495495
int typeDelta = type() - other.type();
496496
if (typeDelta)
497-
return typeDelta < 0 ? true : false;
497+
return typeDelta < 0;
498498
switch (type()) {
499499
case nullValue:
500500
return false;
@@ -508,10 +508,7 @@ bool Value::operator<(const Value& other) const {
508508
return value_.bool_ < other.value_.bool_;
509509
case stringValue: {
510510
if ((value_.string_ == nullptr) || (other.value_.string_ == nullptr)) {
511-
if (other.value_.string_)
512-
return true;
513-
else
514-
return false;
511+
return other.value_.string_ != nullptr;
515512
}
516513
unsigned this_len;
517514
unsigned other_len;
@@ -809,7 +806,7 @@ float Value::asFloat() const {
809806
case nullValue:
810807
return 0.0;
811808
case booleanValue:
812-
return value_.bool_ ? 1.0f : 0.0f;
809+
return value_.bool_ ? 1.0F : 0.0F;
813810
default:
814811
break;
815812
}
@@ -823,9 +820,9 @@ bool Value::asBool() const {
823820
case nullValue:
824821
return false;
825822
case intValue:
826-
return value_.int_ ? true : false;
823+
return value_.int_ != 0;
827824
case uintValue:
828-
return value_.uint_ ? true : false;
825+
return value_.uint_ != 0;
829826
case realValue: {
830827
// According to JavaScript language zero or NaN is regarded as false
831828
const auto value_classification = std::fpclassify(value_.real_);
@@ -841,7 +838,7 @@ bool Value::isConvertibleTo(ValueType other) const {
841838
switch (other) {
842839
case nullValue:
843840
return (isNumeric() && asDouble() == 0.0) ||
844-
(type() == booleanValue && value_.bool_ == false) ||
841+
(type() == booleanValue && !value_.bool_) ||
845842
(type() == stringValue && asString().empty()) ||
846843
(type() == arrayValue && value_.map_->empty()) ||
847844
(type() == objectValue && value_.map_->empty()) ||
@@ -896,7 +893,7 @@ ArrayIndex Value::size() const {
896893

897894
bool Value::empty() const {
898895
if (isNull() || isArray() || isObject())
899-
return size() == 0u;
896+
return size() == 0U;
900897
else
901898
return false;
902899
}
@@ -1545,15 +1542,14 @@ Value::iterator Value::end() {
15451542
// class PathArgument
15461543
// //////////////////////////////////////////////////////////////////
15471544

1548-
PathArgument::PathArgument() {}
1545+
PathArgument::PathArgument() = default;
15491546

15501547
PathArgument::PathArgument(ArrayIndex index)
15511548
: index_(index), kind_(kindIndex) {}
15521549

15531550
PathArgument::PathArgument(const char* key) : key_(key), kind_(kindKey) {}
15541551

1555-
PathArgument::PathArgument(const String& key)
1556-
: key_(key.c_str()), kind_(kindKey) {}
1552+
PathArgument::PathArgument(String key) : key_(std::move(key)), kind_(kindKey) {}
15571553

15581554
// class Path
15591555
// //////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)