clang-tidy: range loop conversions

Found with: modernize-loop-convert

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 4 years ago committed by Luis Díaz Más
parent 44256e8c5d
commit 8e52032ee0

@ -56,14 +56,9 @@ namespace Jzon
std::string GetIndentation(unsigned int level) const
{
if (!format.newline)
{
return "";
}
else
{
if (format.newline)
return std::string(format.indentSize * level, indentationChar);
}
return "";
}
inline const std::string &GetNewline() const
@ -104,57 +99,49 @@ namespace Jzon
{
if (IsObject())
return static_cast<const Object&>(*this);
else
throw TypeException();
}
Array &Node::AsArray()
{
if (IsArray())
return static_cast<Array&>(*this);
else
return static_cast<Array &>(*this);
throw TypeException();
}
const Array &Node::AsArray() const
{
if (IsArray())
return static_cast<const Array&>(*this);
else
return static_cast<const Array &>(*this);
throw TypeException();
}
Value &Node::AsValue()
{
if (IsValue())
return static_cast<Value&>(*this);
else
return static_cast<Value &>(*this);
throw TypeException();
}
const Value &Node::AsValue() const
{
if (IsValue())
return static_cast<const Value&>(*this);
else
return static_cast<const Value &>(*this);
throw TypeException();
}
Node::Type Node::DetermineType(const std::string &json)
{
auto jsonIt = json.begin();
while (jsonIt != json.end() && IsWhitespace(*jsonIt))
++jsonIt;
auto jsonIt = std::find_if(json.begin(), json.end(), IsWhitespace);
if (jsonIt == json.end())
return T_VALUE;
switch (*jsonIt)
{
case '{' : return T_OBJECT;
case '[' : return T_ARRAY;
default : return T_VALUE;
switch (*jsonIt) {
case '{':
return T_OBJECT;
case '[':
return T_ARRAY;
default:
return T_VALUE;
}
}
Value::Value() : Node()
{
SetNull();
@ -213,11 +200,8 @@ namespace Jzon
{
return "null";
}
else
{
return valueStr;
}
}
int Value::ToInt() const
{
if (IsNumber())
@ -227,11 +211,8 @@ namespace Jzon
sstr >> val;
return val;
}
else
{
return 0;
}
}
float Value::ToFloat() const
{
if (IsNumber())
@ -241,11 +222,8 @@ namespace Jzon
sstr >> val;
return val;
}
else
{
return 0.F;
}
}
double Value::ToDouble() const
{
if (IsNumber())
@ -255,22 +233,16 @@ namespace Jzon
sstr >> val;
return val;
}
else
{
return 0.0;
}
}
bool Value::ToBool() const
{
if (IsBool())
{
return (valueStr == "true");
}
else
{
return false;
}
}
void Value::SetNull()
{
@ -323,10 +295,7 @@ namespace Jzon
}
void Value::Set(const bool value)
{
if (value)
valueStr = "true";
else
valueStr = "false";
valueStr = value ? "true" : "false";
type = VT_BOOL;
}
@ -375,7 +344,7 @@ namespace Jzon
bool Value::operator==(const Value &other) const
{
return ((type == other.type)&&(valueStr == other.valueStr));
return ((type == other.type) && (valueStr == other.valueStr));
}
bool Value::operator!=(const Value &other) const
{
@ -388,35 +357,27 @@ namespace Jzon
}
// This is not the most beautiful place for these, but it'll do
static const char charsUnescaped[] = { '\\' , '/' , '\"' , '\n' , '\t' , '\b' , '\f' , '\r' };
static const char *charsEscaped[] = { "\\\\", "\\/", "\\\"", "\\n", "\\t", "\\b", "\\f", "\\r" };
static const char charsUnescaped[] = {'\\', '/', '\"', '\n', '\t', '\b', '\f', '\r'};
static const char *charsEscaped[] = {"\\\\", "\\/", "\\\"", "\\n", "\\t", "\\b", "\\f", "\\r"};
static const unsigned int numEscapeChars = 8;
static const char nullUnescaped = '\0';
static const char *nullEscaped = "\0\0";
const char *&getEscaped(const char &c)
{
for (unsigned int i = 0; i < numEscapeChars; ++i)
{
const char &ue = charsUnescaped[i];
if (c == ue)
{
const char *&e = charsEscaped[i];
return e;
for (unsigned int i = 0; i < numEscapeChars; ++i) {
if (c == charsUnescaped[i]) {
return charsEscaped[i];
}
}
return nullEscaped;
}
const char &getUnescaped(const char &c1, const char &c2)
{
for (unsigned int i = 0; i < numEscapeChars; ++i)
{
for (unsigned int i = 0; i < numEscapeChars; ++i) {
const char *&e = charsEscaped[i];
if (c1 == e[0] && c2 == e[1])
{
const char &ue = charsUnescaped[i];
return ue;
if (c1 == e[0] && c2 == e[1]) {
return charsUnescaped[i];
}
}
return nullUnescaped;
@ -426,16 +387,12 @@ namespace Jzon
{
std::string escaped;
for (const auto& c: value)
{
for (auto &&c : value) {
const char *&a = getEscaped(c);
if (a[0] != '\0')
{
if (a[0] != '\0') {
escaped += a[0];
escaped += a[1];
}
else
{
} else {
escaped += c;
}
}
@ -469,30 +426,22 @@ namespace Jzon
return unescaped;
}
Object::Object() : Node()
{
}
Object::Object(const Object &other) : Node()
{
for (auto it = other.children.cbegin(); it != other.children.cend(); ++it)
{
const std::string &name = (*it).first;
Node &value = *(*it).second;
for (auto &&it : other.children) {
const std::string &name = it.first;
Node &value = *it.second;
children.push_back(NamedNodePtr(name, value.GetCopy()));
}
}
Object::Object(const Node &other) : Node()
{
const Object &object = other.AsObject();
for (auto it = object.children.cbegin(); it != object.children.cend(); ++it)
{
const std::string &name = (*it).first;
Node &value = *(*it).second;
children.push_back(NamedNodePtr(name, value.GetCopy()));
for (auto &&child : other.AsObject().children) {
children.push_back(NamedNodePtr(child.first, child.second->GetCopy()));
}
}
Object::~Object()
@ -528,10 +477,9 @@ namespace Jzon
void Object::Clear()
{
for (auto it = children.begin(); it != children.end(); ++it)
{
delete (*it).second;
(*it).second = NULL;
for (auto &&child : children) {
delete child.second;
child.second = nullptr;
}
children.clear();
}
@ -540,7 +488,6 @@ namespace Jzon
{
if (!children.empty())
return Object::iterator(&children.front());
else
return Object::iterator(NULL);
}
@ -548,35 +495,26 @@ namespace Jzon
{
if (!children.empty())
return Object::const_iterator(&children.front());
else
return Object::const_iterator(NULL);
}
Object::iterator Object::end()
{
if (!children.empty())
return Object::iterator(&children.back()+1);
else
return Object::iterator(&children.back() + 1);
return Object::iterator(NULL);
}
Object::const_iterator Object::end() const
{
if (!children.empty())
return Object::const_iterator(&children.back()+1);
else
return Object::const_iterator(&children.back() + 1);
return Object::const_iterator(NULL);
}
bool Object::Has(const std::string &name) const
{
for (ChildList::const_iterator it = children.begin(); it != children.end(); ++it)
{
if ((*it).first == name)
{
return true;
}
}
return false;
return std::any_of(children.begin(), children.end(),
[&](const NamedNodePtr &child) { return child.first == name; });
}
size_t Object::GetCount() const
{
@ -584,11 +522,9 @@ namespace Jzon
}
Node &Object::Get(const std::string &name) const
{
for (ChildList::const_iterator it = children.begin(); it != children.end(); ++it)
{
if ((*it).first == name)
{
return *(*it).second;
for (auto &&child : children) {
if (child.first == name) {
return *child.second;
}
}
@ -600,17 +536,14 @@ namespace Jzon
return new Object(*this);
}
Array::Array() : Node()
{
}
Array::Array(const Array &other) : Node()
{
for (auto it = other.children.cbegin(); it != other.children.cend(); ++it)
{
const Node &value = *(*it);
children.push_back(value.GetCopy());
for (auto &&value : other.children) {
children.push_back(value->GetCopy());
}
}
@ -618,10 +551,8 @@ namespace Jzon
{
const Array &array = other.AsArray();
for (auto it = array.children.cbegin(); it != array.children.cend(); ++it)
{
const Node &value = *(*it);
children.push_back(value.GetCopy());
for (auto &&value : array.children) {
children.push_back(value->GetCopy());
}
}
@ -645,19 +576,17 @@ namespace Jzon
}
void Array::Remove(size_t index)
{
if (index < children.size())
{
ChildList::iterator it = children.begin()+index;
if (index < children.size()) {
ChildList::iterator it = children.begin() + index;
delete (*it);
children.erase(it);
}
}
void Array::Clear()
{
for (ChildList::iterator it = children.begin(); it != children.end(); ++it)
{
delete (*it);
(*it) = NULL;
for (auto &&child : children) {
delete child;
child = nullptr;
}
children.clear();
}
@ -666,28 +595,24 @@ namespace Jzon
{
if (!children.empty())
return Array::iterator(&children.front());
else
return Array::iterator(NULL);
}
Array::const_iterator Array::begin() const
{
if (!children.empty())
return Array::const_iterator(&children.front());
else
return Array::const_iterator(NULL);
}
Array::iterator Array::end()
{
if (!children.empty())
return Array::iterator(&children.back()+1);
else
return Array::iterator(&children.back() + 1);
return Array::iterator(NULL);
}
Array::const_iterator Array::end() const
{
if (!children.empty())
return Array::const_iterator(&children.back()+1);
else
return Array::const_iterator(&children.back() + 1);
return Array::const_iterator(NULL);
}
@ -697,8 +622,7 @@ namespace Jzon
}
Node &Array::Get(size_t index) const
{
if (index < children.size())
{
if (index < children.size()) {
return *children.at(index);
}
@ -710,7 +634,6 @@ namespace Jzon
return new Array(*this);
}
FileWriter::FileWriter(const std::string &filename) : filename(filename)
{
}
@ -759,11 +682,8 @@ namespace Jzon
error = parser.GetError();
return false;
}
else
{
return true;
}
}
Node::Type FileReader::DetermineType()
{
@ -1193,11 +1113,8 @@ namespace Jzon
{
return json.at(cursor+1);
}
else
{
return '\0';
}
}
void Parser::jumpToNext(char c)
{
++cursor;
@ -1265,26 +1182,12 @@ namespace Jzon
}
else
{
bool number = true;
for (std::string::const_iterator it = value.begin(); it != value.end(); ++it)
{
if (!IsNumber(*it))
{
number = false;
break;
}
}
if (number)
{
data.push(std::make_pair(Value::VT_NUMBER, value));
}
else
{
bool number = std::all_of(value.begin(), value.end(), IsNumber);
if (!number) {
return false;
}
data.push(std::make_pair(Value::VT_NUMBER, value));
}
return true;
}
} // namespace Jzon

@ -211,11 +211,8 @@ void push(Jzon::Node& node,const std::string& key,T i)
ABORT_IF_I_EMTPY
Jzon::Object l ;
const Exiv2::LangAltValue& langs = dynamic_cast<const Exiv2::LangAltValue&>(i->value());
for ( Exiv2::LangAltValue::ValueType::const_iterator lang = langs.value_.begin()
; lang != langs.value_.end()
; lang++
) {
l.Add(lang->first,lang->second);
for (auto&& lang : langs.value_) {
l.Add(lang.first, lang.second);
}
Jzon::Object o ;
o.Add("lang",l);
@ -350,10 +347,8 @@ int main(int argc, char* const argv[])
// create and populate a Jzon::Object for the namespaces
Jzon::Object xmlns;
for ( auto it = namespaces.begin() ; it != namespaces.end() ; it++ ) {
std::string ns = *it ;
std::string uri = nsDict[ns];
xmlns.Add(ns,uri);
for (auto&& ns : namespaces) {
xmlns.Add(ns, nsDict[ns]);
}
// add xmlns as Xmp.xmlns

@ -727,9 +727,8 @@ namespace Exiv2 {
assert(object != 0);
byte* p = object->start() + 2;
for (TiffDirectory::Components::iterator i = object->components_.begin();
i != object->components_.end(); ++i) {
p += updateDirEntry(p, byteOrder(), *i);
for (auto&& component : object->components_) {
p += updateDirEntry(p, byteOrder(), component);
}
}
@ -794,8 +793,8 @@ namespace Exiv2 {
static const char* synthesizedTags[] = {
"Exif.MakerNote.Offset",
};
for (unsigned int i = 0; i < EXV_COUNTOF(synthesizedTags); ++i) {
pos = exifData_.findKey(ExifKey(synthesizedTags[i]));
for (auto&& synthesizedTag : synthesizedTags) {
pos = exifData_.findKey(ExifKey(synthesizedTag));
if (pos != exifData_.end()) exifData_.erase(pos);
}
}
@ -1293,8 +1292,8 @@ namespace Exiv2 {
{
setMnState(); // All components to be post-processed must be from the Makernote
postProc_ = true;
for (PostList::const_iterator pos = postList_.begin(); pos != postList_.end(); ++pos) {
(*pos)->accept(*this);
for (auto&& pos : postList_) {
pos->accept(*this);
}
postProc_ = false;
setOrigState();

Loading…
Cancel
Save