From 231dfc176e1ae56f30554fc4fd188286640a4864 Mon Sep 17 00:00:00 2001 From: Heiko Thiel Date: Fri, 3 May 2019 17:12:30 +0200 Subject: Changes are done by run-clang-tidy -header-filter='.*' -checks='-*,modernize-loop-convert' -fix --- src/NMEAParser.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/NMEAParser.cpp') diff --git a/src/NMEAParser.cpp b/src/NMEAParser.cpp index e7b0901..4560b30 100644 --- a/src/NMEAParser.cpp +++ b/src/NMEAParser.cpp @@ -64,8 +64,8 @@ bool NMEASentence::checksumOK() const { // true if the text contains a non-alpha numeric value bool hasNonAlphaNum(string txt){ - for (size_t i = 0; i < txt.size(); i++){ - if ( !isalnum(txt[i]) ){ + for (char i : txt){ + if ( !isalnum(i) ){ return true; } } @@ -74,9 +74,9 @@ bool hasNonAlphaNum(string txt){ // true if alphanumeric or '-' bool validParamChars(string txt){ - for (size_t i = 0; i < txt.size(); i++){ - if (!isalnum(txt[i])){ - if (txt[i] != '-' && txt[i] != '.'){ + for (char i : txt){ + if (!isalnum(i)){ + if (i != '-' && i != '.'){ return false; } } @@ -88,10 +88,10 @@ bool validParamChars(string txt){ void squish(string& str){ char chars[] = {'\t',' '}; - for (size_t i = 0; i < sizeof(chars); ++i) + for (char i : chars) { // needs include - str.erase(std::remove(str.begin(), str.end(), chars[i]), str.end()); + str.erase(std::remove(str.begin(), str.end(), i), str.end()); } } @@ -129,10 +129,10 @@ string NMEAParser::getRegisteredSentenceHandlersCSV() } ostringstream ss; - for( auto it = eventTable.begin(); it != eventTable.end(); it++){ - ss << it->first; + for(auto& table : eventTable){ + ss << table.first; - if( ! it->second ){ + if( ! table.second ){ ss << "(not callable)"; } ss << ","; @@ -188,8 +188,8 @@ void NMEAParser::readBuffer(uint8_t* b, uint32_t size){ void NMEAParser::readLine(string cmd){ cmd += "\r\n"; - for (size_t i = 0; i < cmd.size(); ++i){ - readByte(cmd[i]); + for (char i : cmd){ + readByte(i); } } @@ -306,8 +306,8 @@ void NMEAParser::readSentence(std::string cmd){ // then calculates a rolling XOR on the bytes uint8_t NMEAParser::calculateChecksum(string s){ uint8_t checksum = 0; - for (size_t i = 0; i < s.size(); i++){ - checksum = checksum ^ s[i]; + for (char i : s){ + checksum = checksum ^ i; } // will display the calculated checksum in hex -- cgit v1.2.3 From d61436211637a9eb9e79b8560c6dd4ec930ee43c Mon Sep 17 00:00:00 2001 From: Heiko Thiel Date: Fri, 3 May 2019 17:45:14 +0200 Subject: Add const keyword to variables of for-ranged loops --- src/NMEAParser.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/NMEAParser.cpp') diff --git a/src/NMEAParser.cpp b/src/NMEAParser.cpp index 4560b30..14084c2 100644 --- a/src/NMEAParser.cpp +++ b/src/NMEAParser.cpp @@ -64,7 +64,7 @@ bool NMEASentence::checksumOK() const { // true if the text contains a non-alpha numeric value bool hasNonAlphaNum(string txt){ - for (char i : txt){ + for (const char i : txt){ if ( !isalnum(i) ){ return true; } @@ -74,7 +74,7 @@ bool hasNonAlphaNum(string txt){ // true if alphanumeric or '-' bool validParamChars(string txt){ - for (char i : txt){ + for (const char i : txt){ if (!isalnum(i)){ if (i != '-' && i != '.'){ return false; @@ -88,7 +88,7 @@ bool validParamChars(string txt){ void squish(string& str){ char chars[] = {'\t',' '}; - for (char i : chars) + for (const char i : chars) { // needs include str.erase(std::remove(str.begin(), str.end(), i), str.end()); @@ -129,7 +129,7 @@ string NMEAParser::getRegisteredSentenceHandlersCSV() } ostringstream ss; - for(auto& table : eventTable){ + for(const auto& table : eventTable){ ss << table.first; if( ! table.second ){ @@ -188,7 +188,7 @@ void NMEAParser::readBuffer(uint8_t* b, uint32_t size){ void NMEAParser::readLine(string cmd){ cmd += "\r\n"; - for (char i : cmd){ + for (const char i : cmd){ readByte(i); } } @@ -306,7 +306,7 @@ void NMEAParser::readSentence(std::string cmd){ // then calculates a rolling XOR on the bytes uint8_t NMEAParser::calculateChecksum(string s){ uint8_t checksum = 0; - for (char i : s){ + for (const char i : s){ checksum = checksum ^ i; } -- cgit v1.2.3