changeset 499:ff8f81775564

Json: new braces style
author David Demelier <markand@malikania.fr>
date Wed, 27 Jan 2016 19:45:19 +0100
parents 1c0342584e55
children d8ed4da7688c
files modules/json/json.cpp modules/json/json.h
diffstat 2 files changed, 29 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/modules/json/json.cpp	Wed Dec 16 11:33:39 2015 +0100
+++ b/modules/json/json.cpp	Wed Jan 27 19:45:19 2016 +0100
@@ -31,21 +31,16 @@
 
 Value readValue(json_t *v)
 {
-	if (json_is_null(v)) {
+	if (json_is_null(v))
 		return Value{nullptr};
-	}
-	if (json_is_string(v)) {
+	if (json_is_string(v))
 		return Value{json_string_value(v)};
-	}
-	if (json_is_real(v)) {
+	if (json_is_real(v))
 		return Value{json_number_value(v)};
-	}
-	if (json_is_integer(v)) {
+	if (json_is_integer(v))
 		return Value{static_cast<int>(json_integer_value(v))};
-	}
-	if (json_is_boolean(v)) {
+	if (json_is_boolean(v))
 		return Value{json_boolean_value(v)};
-	}
 	if (json_is_object(v)) {
 		Value object{Type::Object};
 
@@ -69,9 +64,8 @@
 	const char *key;
 	json_t *value;
 
-	json_object_foreach(object, key, value) {
+	json_object_foreach(object, key, value)
 		parent.insert(key, readValue(value));
-	}
 }
 
 void readArray(Value &parent, json_t *array)
@@ -79,9 +73,8 @@
 	size_t index;
 	json_t *value;
 
-	json_array_foreach(array, index, value) {
+	json_array_foreach(array, index, value)
 		parent.append(readValue(value));
-	}
 }
 
 template <typename Func, typename... Args>
@@ -90,9 +83,8 @@
 	json_error_t error;
 	json_t *json = fn(std::forward<Args>(args)..., &error);
 
-	if (json == nullptr) {
+	if (json == nullptr)
 		throw Error{error.text, error.source, error.line, error.column, error.position};
-	}
 
 	Value value;
 
@@ -113,11 +105,10 @@
 {
 	std::string str;
 
-	if (param < 0) {
+	if (param < 0)
 		str = std::string(level, '\t');
-	} else if (param > 0) {
+	else if (param > 0)
 		str = std::string(param * level, ' ');
-	}
 
 	return str;
 }
@@ -226,27 +217,24 @@
 
 bool Value::toBool() const noexcept
 {
-	if (m_type != Type::Boolean) {
+	if (m_type != Type::Boolean)
 		return false;
-	}
 
 	return m_boolean;
 }
 
 double Value::toReal() const noexcept
 {
-	if (m_type != Type::Real) {
+	if (m_type != Type::Real)
 		return 0;
-	}
 
 	return m_number;
 }
 
 int Value::toInt() const noexcept
 {
-	if (m_type != Type::Int) {
+	if (m_type != Type::Int)
 		return 0;
-	}
 
 	return m_integer;
 }
@@ -255,11 +243,10 @@
 {
 	std::string result;
 
-	if (m_type == Type::String) {
+	if (m_type == Type::String)
 		result = m_string;
-	} else if (coerce) {
+	else if (coerce)
 		result = toJson();
-	}
 
 	return result;
 }
--- a/modules/json/json.h	Wed Dec 16 11:33:39 2015 +0100
+++ b/modules/json/json.h	Wed Jan 27 19:45:19 2016 +0100
@@ -206,11 +206,10 @@
 
 		inline void increment()
 		{
-			if (m_value.isObject()) {
+			if (m_value.isObject())
 				m_itm++;
-			} else {
+			else
 				m_ita++;
-			}
 		}
 
 		BaseIterator(ValueType &value, ObjectIteratorType it)
@@ -359,7 +358,7 @@
 	/**
 	 * Construct a null value.
 	 */
-	inline Value()
+	inline Value() noexcept
 	{
 	}
 
@@ -445,9 +444,8 @@
 	inline Value(std::map<std::string, Value> values)
 		: Value{Type::Object}
 	{
-		for (const auto &pair : values) {
+		for (const auto &pair : values)
 			insert(pair.first, pair.second);
-		}
 	}
 
 	/**
@@ -459,9 +457,8 @@
 	inline Value(std::vector<Value> values)
 		: Value{Type::Array}
 	{
-		for (Value value : values) {
+		for (Value value : values)
 			append(std::move(value));
-		}
 	}
 
 	/**
@@ -739,9 +736,8 @@
 	{
 		assert(isArray() || isObject());
 
-		if (m_type == Type::Object) {
+		if (m_type == Type::Object)
 			return m_object.size();
-		}
 
 		return m_array.size();
 	}
@@ -755,11 +751,10 @@
 	{
 		assert(isArray() || isObject());
 
-		if (m_type == Type::Array) {
+		if (m_type == Type::Array)
 			m_array.clear();
-		} else {
+		else
 			m_object.clear();
-		}
 	}
 
 	/*
@@ -777,9 +772,8 @@
 	template <typename DefaultValue>
 	inline Value valueOr(unsigned position, DefaultValue &&defaultValue) const
 	{
-		if (m_type != Type::Array || position >= m_array.size()) {
+		if (m_type != Type::Array || position >= m_array.size())
 			return defaultValue;
-		}
 
 		return m_array[position];
 	}
@@ -795,9 +789,8 @@
 	template <typename DefaultValue>
 	inline Value valueOr(unsigned position, Type type, DefaultValue &&defaultValue) const
 	{
-		if (m_type != Type::Array || position >= m_array.size() || m_array[position].typeOf() != type) {
+		if (m_type != Type::Array || position >= m_array.size() || m_array[position].typeOf() != type)
 			return defaultValue;
-		}
 
 		return m_array[position];
 	}
@@ -978,15 +971,13 @@
 	template <typename DefaultValue>
 	Value valueOr(const std::string &name, DefaultValue &&defaultValue) const
 	{
-		if (m_type != Type::Object) {
+		if (m_type != Type::Object)
 			return defaultValue;
-		}
 
 		auto it = m_object.find(name);
 
-		if (it == m_object.end()) {
+		if (it == m_object.end())
 			return defaultValue;
-		}
 
 		return it->second;
 	}
@@ -1002,15 +993,13 @@
 	template <typename DefaultValue>
 	Value valueOr(const std::string &name, Type type, DefaultValue &&defaultValue) const
 	{
-		if (m_type != Type::Object) {
+		if (m_type != Type::Object)
 			return defaultValue;
-		}
 
 		auto it = m_object.find(name);
 
-		if (it == m_object.end() || it->second.typeOf() != type) {
+		if (it == m_object.end() || it->second.typeOf() != type)
 			return defaultValue;
-		}
 
 		return it->second;
 	}