Use range-based loops when possible.

This commit is contained in:
Jim Evins
2017-12-30 22:09:48 -05:00
parent 9a135f8971
commit ff003e5b17
8 changed files with 48 additions and 48 deletions
+4 -4
View File
@@ -43,9 +43,9 @@ namespace glabels
bool Base::isAscii( const std::string& data ) const 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; return false;
} }
@@ -61,9 +61,9 @@ namespace glabels
{ {
unsigned int n = 0; 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++; n++;
} }
+8 -8
View File
@@ -114,9 +114,9 @@ namespace glbarcode
*/ */
bool BarcodeCode39::validate( const std::string& rawData ) 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 ) if ( alphabet.find(c) == std::string::npos )
{ {
@@ -140,9 +140,9 @@ namespace glbarcode
code += "i"; code += "i";
int sum = 0; 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 += symbols[cValue];
code += "i"; code += "i";
@@ -170,9 +170,9 @@ namespace glbarcode
{ {
std::string displayText; 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; return displayText;
@@ -230,11 +230,11 @@ namespace glbarcode
/* Now traverse the code string and draw each bar */ /* Now traverse the code string and draw each bar */
double x1 = xQuiet; double x1 = xQuiet;
for ( unsigned int i=0; i < codedData.size(); i++ ) for (char c : codedData)
{ {
double lwidth; double lwidth;
switch ( codedData[i] ) switch ( c )
{ {
case 'i': case 'i':
+4 -4
View File
@@ -78,9 +78,9 @@ namespace glbarcode
*/ */
bool BarcodeCode39Ext::validate( const std::string& rawData ) 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; return false;
} }
@@ -97,9 +97,9 @@ namespace glbarcode
{ {
std::string cookedData; 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; return cookedData;
+3 -3
View File
@@ -61,11 +61,11 @@ namespace glbarcode
{ {
std::string cookedData; 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;
} }
} }
+12 -12
View File
@@ -300,9 +300,9 @@ namespace
public: public:
Int104( ) 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 divUint( uint32_t y )
{ {
uint32_t carry = 0; 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; carry = temp % y;
} }
return carry; return carry;
@@ -375,9 +375,9 @@ namespace glbarcode
return false; return false;
} }
for ( unsigned int i = 0; i < rawData.size(); i++ ) for (char c : rawData)
{ {
if ( !isdigit( rawData[i] ) ) if ( !isdigit( c ) )
{ {
return false; return false;
} }
@@ -493,10 +493,10 @@ namespace glbarcode
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
std::string code; 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 d = (character[ b.descender.i ] & b.descender.mask) != 0 ? 1 : 0;
int a = (character[ barMap[i].ascender.i ] & barMap[i].ascender.mask) != 0 ? 1 : 0; int a = (character[ b.ascender.i ] & b.ascender.mask) != 0 ? 1 : 0;
code += tdafTable[ (a<<1) + d ]; code += tdafTable[ (a<<1) + d ];
} }
@@ -516,12 +516,12 @@ namespace glbarcode
double& h ) double& h )
{ {
double x = ONECODE_HORIZ_MARGIN; double x = ONECODE_HORIZ_MARGIN;
for ( unsigned int i = 0; i < codedData.size(); i++ ) for (char c : codedData)
{ {
double y = ONECODE_VERT_MARGIN; double y = ONECODE_VERT_MARGIN;
double length = 0; double length = 0;
switch ( codedData[i] ) switch ( c )
{ {
case 'T': case 'T':
y += ONECODE_TRACKER_OFFSET; y += ONECODE_TRACKER_OFFSET;
+8 -8
View File
@@ -91,13 +91,13 @@ namespace glbarcode
bool BarcodePostnet::validate( const std::string& rawData ) bool BarcodePostnet::validate( const std::string& rawData )
{ {
int nDigits = 0; int nDigits = 0;
for ( unsigned int i = 0; i < rawData.size(); i++ ) for (char c : rawData)
{ {
if ( isdigit( rawData[i] ) ) if ( isdigit( c ) )
{ {
nDigits++; nDigits++;
} }
else if ( (rawData[i] != '-') && (rawData[i] != ' ') ) else if ( (c != '-') && (c != ' ') )
{ {
/* Only allow digits, dashes, and spaces. */ /* Only allow digits, dashes, and spaces. */
return false; return false;
@@ -120,12 +120,12 @@ namespace glbarcode
/* process each digit, adding approptiate symbol */ /* process each digit, adding approptiate symbol */
int sum = 0; 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) */ /* Only translate the digits (0-9) */
int d = cookedData[i] - '0'; int d = c - '0';
code += symbols[d]; code += symbols[d];
sum += d; sum += d;
} }
@@ -151,12 +151,12 @@ namespace glbarcode
double& h ) double& h )
{ {
double x = POSTNET_HORIZ_MARGIN; double x = POSTNET_HORIZ_MARGIN;
for ( unsigned int i=0; i < codedData.size(); i++ ) for (char c : codedData)
{ {
double y = POSTNET_VERT_MARGIN; double y = POSTNET_VERT_MARGIN;
double length = 0; double length = 0;
switch ( codedData[i] ) switch ( c )
{ {
case '0': case '0':
y += POSTNET_FULLBAR_HEIGHT - POSTNET_HALFBAR_HEIGHT; y += POSTNET_FULLBAR_HEIGHT - POSTNET_HALFBAR_HEIGHT;
+3 -3
View File
@@ -61,11 +61,11 @@ namespace glbarcode
{ {
std::string cookedData; 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;
} }
} }
+6 -6
View File
@@ -99,13 +99,13 @@ namespace glbarcode
{ {
int nDigits = 0; int nDigits = 0;
for ( unsigned int i = 0; i < rawData.size(); i++ ) for (char c : rawData)
{ {
if ( isdigit( rawData[i] ) ) if ( isdigit( c ) )
{ {
nDigits++; nDigits++;
} }
else if ( rawData[i] != ' ') else if ( c != ' ')
{ {
/* Only allow digits and spaces -- ignoring spaces. */ /* Only allow digits and spaces -- ignoring spaces. */
return false; return false;
@@ -192,11 +192,11 @@ namespace glbarcode
{ {
std::string displayText; 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;
} }
} }