diff --git a/src/utils/md5.cpp b/src/utils/md5.cpp index f84d8dc1..f4bab2cd 100644 --- a/src/utils/md5.cpp +++ b/src/utils/md5.cpp @@ -26,9 +26,10 @@ #include "md5.h" #include +#include #define PUT_BIT_LE(i, cp, value) do { \ - (cp)[i] = (uint8_t)(((value) >> 8 * i) & 0xFF); \ + (cp)[i] = uint8_t(((value) >> 8 * i) & 0xFF); \ } while (0) #define PUT_64BIT_LE(cp, value) do { \ diff --git a/src/utils/smallut.cpp b/src/utils/smallut.cpp index c3cd8454..d4a2ceef 100644 --- a/src/utils/smallut.cpp +++ b/src/utils/smallut.cpp @@ -294,25 +294,18 @@ template string stringsToString(const T& tokens) return out; } -template void stringsToCSV(const T& tokens, string& s, - char sep) +template void stringsToCSV(const T& tokens, string& s, char sep) { s.erase(); - for (auto it = tokens.begin(); - it != tokens.end(); it++) { + for (const auto& tok : tokens) { bool needquotes = false; - if (it->empty() || - it->find_first_of(string(1, sep) + "\"\n") != string::npos) { + if (tok.empty() || tok.find_first_of(string(1, sep) + "\"\n") != string::npos) { needquotes = true; } - if (it != tokens.begin()) { - s.append(1, sep); - } if (needquotes) { s.append(1, '"'); } - for (unsigned int i = 0; i < it->length(); i++) { - char car = it->at(i); + for (auto&& car : tok) { if (car == '"') { s.append(2, '"'); } else { @@ -322,7 +315,11 @@ template void stringsToCSV(const T& tokens, string& s, if (needquotes) { s.append(1, '"'); } + s.append(1, sep); } + // Remove last separator. + if (s.size()) + s.pop_back(); } #ifdef SMALLUT_EXTERNAL_INSTANTIATIONS diff --git a/src/utils/utf8iter.h b/src/utils/utf8iter.h index 22651787..a8ed4c80 100644 --- a/src/utils/utf8iter.h +++ b/src/utils/utf8iter.h @@ -21,6 +21,7 @@ #include "assert.h" #endif #include +#include /** * A small helper class to iterate over utf8 strings. This is not an @@ -60,7 +61,7 @@ public: /** "Direct" access. Awfully inefficient as we skip from start or current * position at best. This can only be useful for a lookahead from the * current position */ - unsigned int operator[](std::string::size_type charpos) const { + uint32_t operator[](std::string::size_type charpos) const { std::string::size_type mypos = 0; unsigned int mycp = 0; if (charpos >= m_charpos) { @@ -71,7 +72,7 @@ public: while (mypos < m_sp->length() && mycp != charpos) { l = get_cl(mypos); if (l <= 0 || !poslok(mypos, l) || !checkvalidat(mypos, l)) - return (unsigned int)-1; + return uint32_t(-1); mypos += l; ++mycp; } @@ -80,7 +81,7 @@ public: if (poslok(mypos, l) && checkvalidat(mypos, l)) return getvalueat(mypos, l); } - return (unsigned int)-1; + return uint32_t(-1); } /** Increment current position to next utf-8 char */ @@ -100,11 +101,11 @@ public: } /** operator* returns the ucs4 value as a machine integer*/ - unsigned int operator*() { + uint32_t operator*() { #ifdef UTF8ITER_CHECK assert(m_cl > 0); #endif - return m_cl == 0 ? (unsigned int)-1 : getvalueat(m_pos, m_cl); + return m_cl == 0 ? uint32_t(-1) : getvalueat(m_pos, m_cl); } /** Append current utf-8 possibly multi-byte character to string param. @@ -186,20 +187,20 @@ private: inline bool checkvalidat(std::string::size_type p, int l) const { switch (l) { case 1: - return (unsigned char)(*m_sp)[p] < 128; + return uint8_t((*m_sp)[p]) < 128; case 2: - return (((unsigned char)(*m_sp)[p]) & 224) == 192 - && (((unsigned char)(*m_sp)[p+1]) & 192) == 128; + return uint8_t((*m_sp)[p] & 224) == 192 + && uint8_t((*m_sp)[p+1] & 192) == 128; case 3: - return (((unsigned char)(*m_sp)[p]) & 240) == 224 - && (((unsigned char)(*m_sp)[p+1]) & 192) == 128 - && (((unsigned char)(*m_sp)[p+2]) & 192) == 128 + return uint8_t((*m_sp)[p] & 240) == 224 + && uint8_t((*m_sp)[p+1] & 192) == 128 + && uint8_t((*m_sp)[p+2] & 192) == 128 ; case 4: - return (((unsigned char)(*m_sp)[p]) & 248) == 240 - && (((unsigned char)(*m_sp)[p+1]) & 192) == 128 - && (((unsigned char)(*m_sp)[p+2]) & 192) == 128 - && (((unsigned char)(*m_sp)[p+3]) & 192) == 128 + return uint8_t((*m_sp)[p] & 248) == 240 + && uint8_t((*m_sp)[p+1] & 192) == 128 + && uint8_t((*m_sp)[p+2] & 192) == 128 + && uint8_t((*m_sp)[p+3] & 192) == 128 ; default: return false; @@ -208,7 +209,7 @@ private: // Get character byte length at specified position. Returns 0 for error. inline int get_cl(std::string::size_type p) const { - unsigned int z = (unsigned char)(*m_sp)[p]; + unsigned int z = uint8_t((*m_sp)[p]); if (z <= 127) { return 1; } else if ((z & 224) == 192) { @@ -232,16 +233,16 @@ private: #ifdef UTF8ITER_CHECK assert((unsigned char)(*m_sp)[p] < 128); #endif - return (unsigned char)(*m_sp)[p]; + return uint8_t((*m_sp)[p]); case 2: #ifdef UTF8ITER_CHECK assert( - ((unsigned char)(*m_sp)[p] & 224) == 192 + uint8_t((*m_sp)[p] & 224) == 192 && ((unsigned char)(*m_sp)[p+1] & 192) == 128 ); #endif - return ((unsigned char)(*m_sp)[p] - 192) * 64 + - (unsigned char)(*m_sp)[p+1] - 128 ; + return uint8_t((*m_sp)[p] - 192) * 64 + + uint8_t((*m_sp)[p+1] - 128); case 3: #ifdef UTF8ITER_CHECK assert( @@ -251,29 +252,29 @@ private: ); #endif - return ((unsigned char)(*m_sp)[p] - 224) * 4096 + - ((unsigned char)(*m_sp)[p+1] - 128) * 64 + - (unsigned char)(*m_sp)[p+2] - 128; + return uint8_t((*m_sp)[p] - 224) * 4096 + + uint8_t((*m_sp)[p+1] - 128) * 64 + + uint8_t((*m_sp)[p+2] - 128); case 4: #ifdef UTF8ITER_CHECK assert( - (((unsigned char)(*m_sp)[p]) & 248) == 240 - && (((unsigned char)(*m_sp)[p+1]) & 192) == 128 - && (((unsigned char)(*m_sp)[p+2]) & 192) == 128 - && (((unsigned char)(*m_sp)[p+3]) & 192) == 128 + uint8_t((*m_sp)[p] & 248) == 240 + && uint8_t((*m_sp)[p+1] & 192) == 128 + && uint8_t((*m_sp)[p+2] & 192) == 128 + && uint8_t((*m_sp)[p+3] & 192) == 128 ); #endif - return ((unsigned char)(*m_sp)[p]-240)*262144 + - ((unsigned char)(*m_sp)[p+1]-128)*4096 + - ((unsigned char)(*m_sp)[p+2]-128)*64 + - (unsigned char)(*m_sp)[p+3]-128; + return uint8_t((*m_sp)[p]-240)*262144 + + uint8_t((*m_sp)[p+1]-128)*4096 + + uint8_t((*m_sp)[p+2]-128)*64 + + uint8_t((*m_sp)[p+3]-128); default: #ifdef UTF8ITER_CHECK assert(l <= 4); #endif - return (unsigned int)-1; + return uint32_t(-1); } }