diff C++/Parser.cpp @ 187:600754c27c88

Update parser to style and remove useless stuff
author David Demelier <markand@malikania.fr>
date Tue, 26 Nov 2013 20:20:59 +0100
parents 2bcdee0fe8d4
children 1ffe6d4937b7
line wrap: on
line diff
--- a/C++/Parser.cpp	Sat Nov 23 16:14:05 2013 +0100
+++ b/C++/Parser.cpp	Tue Nov 26 20:20:59 2013 +0100
@@ -50,8 +50,7 @@
 	std::string ret;
 
 	for (const Option &o : m_options)
-		if (o.m_key == name)
-		{
+		if (o.m_key == name) {
 			ret = o.m_value;
 			break;
 		}
@@ -64,8 +63,7 @@
 {
 	bool result = false;
 
-	if (hasOption(name))
-	{
+	if (hasOption(name)) {
 		std::string value = findOption(name);
 
 		if (value == "yes" || value == "true"|| value == "1")
@@ -150,10 +148,8 @@
 {
 	size_t end;
 
-	if ((end = line.find_first_of(']')) != std::string::npos)
-	{
-		if (end > 1)
-		{
+	if ((end = line.find_first_of(']')) != std::string::npos) {
+		if (end > 1) {
 			std::string name = line.substr(1, end - 1);
 
 			/*
@@ -162,17 +158,13 @@
 			 * further read options should not be enabled until
 			 * a correct section is found again.
 			 */
-			if (hasSection(name) && (m_tuning & DisableRedefinition))
-			{
+			if (hasSection(name) && (m_tuning & DisableRedefinition)) {
 				if (!(m_tuning & DisableVerbosity))
 					log(lineno, name, "redefinition not allowed");
 				m_sections.back().m_allowed = false;
-			}
-			else
+			} else
 				addSection(name);
-		}
-		else if (!(m_tuning & DisableVerbosity))
-		{
+		} else if (!(m_tuning & DisableVerbosity)) {
 			/*
 			 * Do not add options at this step because it will
 			 * corrupt the previous one.
@@ -190,8 +182,7 @@
 	Section &current = m_sections.back();
 
 	// Error on last section?
-	if (!current.m_allowed)
-	{
+	if (!current.m_allowed) {
 		/*
 		 * If it is the root section, this has been probably set by
 		 * DisableRootSection flag, otherwise an error has occured
@@ -203,15 +194,13 @@
 		return;
 	}
 
-	if ((epos = line.find_first_of('=')) == std::string::npos)
-	{
+	if ((epos = line.find_first_of('=')) == std::string::npos) {
 		if (!(m_tuning & DisableVerbosity))
 			log(lineno, current.m_name, "missing `=' keyword");
 		return;
 	}
 
-	if (epos > 0)
-	{
+	if (epos > 0) {
 		size_t i, begin, last;
 		char c;
 
@@ -230,16 +219,13 @@
 	
 		c = value[0];
 		begin = 0;
-		if (c == '\'' || c == '"')
-		{
+		if (c == '\'' || c == '"') {
 			for (last = begin = 1; value[last] != c && last < value.length(); ++last)
 				continue;
 			if (value[last] != c && !(m_tuning & DisableVerbosity))
 				if (!(m_tuning & DisableVerbosity))
 					log(lineno, current.m_name, "undisclosed std::string");
-		}
-		else
-		{
+		} else {
 			for (last = begin; !isspace(value[last]) && last < value.length(); ++last)
 				continue;
 		}
@@ -265,10 +251,8 @@
 		continue;
 
 	buffer = line.substr(i);
-	if (buffer.length() > 0)
-	{
-		if (buffer[0] != m_commentChar)
-		{
+	if (buffer.length() > 0) {
+		if (buffer[0] != m_commentChar) {
 			if (buffer[0] == '[')
 				readSection(lineno, buffer);
 			else
@@ -312,8 +296,7 @@
 	int lineno = 1;
 
 	file.open(m_path.c_str());
-	if (!file.is_open())
-	{
+	if (!file.is_open()) {
 		m_error = "could not open file " + m_path;	// XXX: add a real error
 		return false;
 	}
@@ -362,14 +345,6 @@
 	throw NotFoundException(name);
 }
 
-const Section &Parser::requireSection(const std::string &name) const
-{
-	if (!hasSection(name))
-		throw NotFoundException(name);
-
-	return getSection(name);
-}
-
 void Parser::log(int number, const std::string &, const std::string &message)
 {
 	std::cout << "line " << number << ": " << message << std::endl;
@@ -377,8 +352,7 @@
 
 void Parser::dump()
 {
-	for (auto s : m_sections)
-	{
+	for (auto s : m_sections) {
 		dumpSection(s);
 
 		for (auto o : s.m_options)