From 1479b2ab1ae2e5a82ab6ac79663939ae651000fd Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Fri, 26 Sep 2014 22:55:05 +0200 Subject: Replaced array-like accesses with their named member method counterparts --- src/tree.cc | 8 ++++---- src/utils.cc | 8 ++++++-- src/utils.h | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/tree.cc b/src/tree.cc index 11bb299..900d891 100644 --- a/src/tree.cc +++ b/src/tree.cc @@ -117,7 +117,7 @@ Node* Tree::buildTree(const std::string& term) { elementIterator != topElements.end(); ++elementIterator ) { const std::string& element = *elementIterator; - const TokenType elementToken = determineToken(element[0]); + const TokenType elementToken = determineToken(element.front()); if ( elementToken != TokenType::VALUE_NUMBER && elementToken != TokenType::VALUE_IDENTIFIER && @@ -151,18 +151,18 @@ Node* Tree::buildTree(const std::string& term) { }; if ( subElements.size() == 1 ) { - switch ( determineToken(subElements[0][0]) ) { + switch ( determineToken(subElements.front()) ) { case TokenType::VALUE_NUMBER: case TokenType::OPERATOR_MINUS: { operands.push(this->addNode( - doubleToString(subElements[0]) + doubleToString(subElements.front()) )); break; } case TokenType::VALUE_IDENTIFIER: { operands.push(this->addNode( - subElements[0], + subElements.front(), this->constants_ )); diff --git a/src/utils.cc b/src/utils.cc index 752b774..832b701 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -34,6 +34,10 @@ TokenType determineToken(const char tmp) { } } +TokenType determineToken(const std::string& tmp) { + return determineToken(tmp.front()); +} + PrecedenceLevel precedence(const TokenType token) { switch ( token ) { case TokenType::VALUE_NUMBER: @@ -61,7 +65,7 @@ PrecedenceLevel precedence(const TokenType token) { } } -std::vector lexer(std::string term) { +std::vector lexer(const std::string& term) { std::vector resultBuffer; std::string levelBuffer; @@ -185,7 +189,7 @@ std::vector lexer(std::string term) { if ( previousToken == TokenType::PARENTHESES_CLOSE && resultBuffer.size() == 1 ) { - resultBuffer = lexer(resultBuffer[0]); + resultBuffer = lexer(resultBuffer.front()); } return resultBuffer; diff --git a/src/utils.h b/src/utils.h index ca2c77f..63ccf55 100644 --- a/src/utils.h +++ b/src/utils.h @@ -28,9 +28,10 @@ enum class TokenType { VALUE_IDENTIFIER, }; -TokenType determineToken(char); +TokenType determineToken(const char); +TokenType determineToken(const std::string&); PrecedenceLevel precedence(TokenType); -std::vector lexer(std::string); +std::vector lexer(const std::string&); double doubleToString(const std::string&); -- cgit v1.2.3