From ff003e5b178e5aa226b5206e57c8c22592116de1 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 30 Dec 2017 22:09:48 -0500 Subject: [PATCH] Use range-based loops when possible. --- backends/barcode/GnuBarcode.cpp | 8 ++++---- glbarcode/BarcodeCode39.cpp | 16 ++++++++-------- glbarcode/BarcodeCode39Ext.cpp | 8 ++++---- glbarcode/BarcodeEan13.cpp | 6 +++--- glbarcode/BarcodeOnecode.cpp | 24 ++++++++++++------------ glbarcode/BarcodePostnet.cpp | 16 ++++++++-------- glbarcode/BarcodeUpcA.cpp | 6 +++--- glbarcode/BarcodeUpcBase.cpp | 12 ++++++------ 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/backends/barcode/GnuBarcode.cpp b/backends/barcode/GnuBarcode.cpp index 6190115..95a7ecf 100644 --- a/backends/barcode/GnuBarcode.cpp +++ b/backends/barcode/GnuBarcode.cpp @@ -43,9 +43,9 @@ namespace glabels bool Base::isAscii( const std::string& data ) const { - for ( unsigned int i = 0; i < data.size(); i++ ) + for (char c : data) { - if ( (data[i] & 0x80) != 0 ) + if ( (c & 0x80) != 0 ) { return false; } @@ -61,9 +61,9 @@ namespace glabels { unsigned int n = 0; - for ( unsigned int i = 0; i < data.size(); i++ ) + for (char c : data) { - if ( isdigit(data[i]) ) + if ( isdigit(c) ) { n++; } diff --git a/glbarcode/BarcodeCode39.cpp b/glbarcode/BarcodeCode39.cpp index 0aef10e..953987d 100644 --- a/glbarcode/BarcodeCode39.cpp +++ b/glbarcode/BarcodeCode39.cpp @@ -114,9 +114,9 @@ namespace glbarcode */ bool BarcodeCode39::validate( const std::string& rawData ) { - for ( unsigned int i = 0; i < rawData.size(); i++ ) + for (char r : rawData) { - char c = toupper( rawData[i] ); + char c = toupper( r ); if ( alphabet.find(c) == std::string::npos ) { @@ -140,9 +140,9 @@ namespace glbarcode code += "i"; int sum = 0; - for ( unsigned int i=0; i < cookedData.size(); i++ ) + for (char c : cookedData) { - size_t cValue = alphabet.find( toupper( cookedData[i] ) ); + size_t cValue = alphabet.find( toupper( c ) ); code += symbols[cValue]; code += "i"; @@ -170,9 +170,9 @@ namespace glbarcode { std::string displayText; - for ( unsigned int i = 0; i < rawData.size(); i++ ) + for (char c : rawData) { - displayText += toupper( rawData[i] ); + displayText += toupper( c ); } return displayText; @@ -230,11 +230,11 @@ namespace glbarcode /* Now traverse the code string and draw each bar */ double x1 = xQuiet; - for ( unsigned int i=0; i < codedData.size(); i++ ) + for (char c : codedData) { double lwidth; - switch ( codedData[i] ) + switch ( c ) { case 'i': diff --git a/glbarcode/BarcodeCode39Ext.cpp b/glbarcode/BarcodeCode39Ext.cpp index a22d7ae..a4ff355 100644 --- a/glbarcode/BarcodeCode39Ext.cpp +++ b/glbarcode/BarcodeCode39Ext.cpp @@ -78,9 +78,9 @@ namespace glbarcode */ bool BarcodeCode39Ext::validate( const std::string& rawData ) { - for ( unsigned int i = 0; i < rawData.size(); i++ ) + for (char c : rawData) { - if ( (rawData[i] < 0) || (rawData[i] > 0x7F) ) + if ( (c < 0) || (c > 0x7F) ) { return false; } @@ -97,9 +97,9 @@ namespace glbarcode { std::string cookedData; - for ( unsigned int i = 0; i < rawData.size(); i++ ) + for (char c : rawData) { - cookedData += asciiMap[ int(rawData[i]) ]; + cookedData += asciiMap[ int(c) ]; } return cookedData; diff --git a/glbarcode/BarcodeEan13.cpp b/glbarcode/BarcodeEan13.cpp index a67eca4..1dc9da4 100644 --- a/glbarcode/BarcodeEan13.cpp +++ b/glbarcode/BarcodeEan13.cpp @@ -61,11 +61,11 @@ namespace glbarcode { std::string cookedData; - for ( unsigned int i = 0; i < rawData.size(); i++ ) + for (char c : rawData) { - if ( isdigit( rawData[i] ) ) + if ( isdigit( c ) ) { - cookedData += rawData[i]; + cookedData += c; } } diff --git a/glbarcode/BarcodeOnecode.cpp b/glbarcode/BarcodeOnecode.cpp index f7cbd8d..5c905e6 100644 --- a/glbarcode/BarcodeOnecode.cpp +++ b/glbarcode/BarcodeOnecode.cpp @@ -300,9 +300,9 @@ namespace public: Int104( ) { - for ( int i = 0; i < 13; i++ ) + for (unsigned char& c : mByteArray) { - mByteArray[i] = 0; + c = 0; } } @@ -334,11 +334,11 @@ namespace uint32_t divUint( uint32_t y ) { uint32_t carry = 0; - for ( int i = 0; i < 13; i++ ) + for (unsigned char& c : mByteArray) { - uint32_t temp = mByteArray[i] + (carry << 8); + uint32_t temp = c + (carry << 8); - mByteArray[i] = (uint8_t)(temp / y); + c = (uint8_t)(temp / y); carry = temp % y; } return carry; @@ -375,9 +375,9 @@ namespace glbarcode return false; } - for ( unsigned int i = 0; i < rawData.size(); i++ ) + for (char c : rawData) { - if ( !isdigit( rawData[i] ) ) + if ( !isdigit( c ) ) { return false; } @@ -493,10 +493,10 @@ namespace glbarcode /*-----------------------------------------------------------*/ std::string code; - for ( int i = 0; i < 65; i++ ) + for (auto b : barMap) { - int d = (character[ barMap[i].descender.i ] & barMap[i].descender.mask) != 0 ? 1 : 0; - int a = (character[ barMap[i].ascender.i ] & barMap[i].ascender.mask) != 0 ? 1 : 0; + int d = (character[ b.descender.i ] & b.descender.mask) != 0 ? 1 : 0; + int a = (character[ b.ascender.i ] & b.ascender.mask) != 0 ? 1 : 0; code += tdafTable[ (a<<1) + d ]; } @@ -516,12 +516,12 @@ namespace glbarcode double& h ) { double x = ONECODE_HORIZ_MARGIN; - for ( unsigned int i = 0; i < codedData.size(); i++ ) + for (char c : codedData) { double y = ONECODE_VERT_MARGIN; double length = 0; - switch ( codedData[i] ) + switch ( c ) { case 'T': y += ONECODE_TRACKER_OFFSET; diff --git a/glbarcode/BarcodePostnet.cpp b/glbarcode/BarcodePostnet.cpp index f70457a..90497da 100644 --- a/glbarcode/BarcodePostnet.cpp +++ b/glbarcode/BarcodePostnet.cpp @@ -91,13 +91,13 @@ namespace glbarcode bool BarcodePostnet::validate( const std::string& rawData ) { int nDigits = 0; - for ( unsigned int i = 0; i < rawData.size(); i++ ) + for (char c : rawData) { - if ( isdigit( rawData[i] ) ) + if ( isdigit( c ) ) { nDigits++; } - else if ( (rawData[i] != '-') && (rawData[i] != ' ') ) + else if ( (c != '-') && (c != ' ') ) { /* Only allow digits, dashes, and spaces. */ return false; @@ -120,12 +120,12 @@ namespace glbarcode /* process each digit, adding approptiate symbol */ int sum = 0; - for ( unsigned int i = 0; i < cookedData.size(); i++ ) + for (char c : cookedData) { - if ( isdigit( cookedData[i] ) ) + if ( isdigit( c ) ) { /* Only translate the digits (0-9) */ - int d = cookedData[i] - '0'; + int d = c - '0'; code += symbols[d]; sum += d; } @@ -151,12 +151,12 @@ namespace glbarcode double& h ) { double x = POSTNET_HORIZ_MARGIN; - for ( unsigned int i=0; i < codedData.size(); i++ ) + for (char c : codedData) { double y = POSTNET_VERT_MARGIN; double length = 0; - switch ( codedData[i] ) + switch ( c ) { case '0': y += POSTNET_FULLBAR_HEIGHT - POSTNET_HALFBAR_HEIGHT; diff --git a/glbarcode/BarcodeUpcA.cpp b/glbarcode/BarcodeUpcA.cpp index 821b3ee..026e563 100644 --- a/glbarcode/BarcodeUpcA.cpp +++ b/glbarcode/BarcodeUpcA.cpp @@ -61,11 +61,11 @@ namespace glbarcode { std::string cookedData; - for ( unsigned int i = 0; i < rawData.size(); i++ ) + for (char c : rawData) { - if ( isdigit( rawData[i] ) ) + if ( isdigit( c ) ) { - cookedData += rawData[i]; + cookedData += c; } } diff --git a/glbarcode/BarcodeUpcBase.cpp b/glbarcode/BarcodeUpcBase.cpp index e2a9952..177a62f 100644 --- a/glbarcode/BarcodeUpcBase.cpp +++ b/glbarcode/BarcodeUpcBase.cpp @@ -99,13 +99,13 @@ namespace glbarcode { int nDigits = 0; - for ( unsigned int i = 0; i < rawData.size(); i++ ) + for (char c : rawData) { - if ( isdigit( rawData[i] ) ) + if ( isdigit( c ) ) { nDigits++; } - else if ( rawData[i] != ' ') + else if ( c != ' ') { /* Only allow digits and spaces -- ignoring spaces. */ return false; @@ -192,11 +192,11 @@ namespace glbarcode { std::string displayText; - for ( unsigned int i = 0; i < rawData.size(); i++ ) + for (char c : rawData) { - if ( isdigit( rawData[i] ) ) + if ( isdigit( c ) ) { - displayText += rawData[i]; + displayText += c; } }