From 95b56a703505e26f5457627934405c766ac926f5 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Sat, 5 Feb 2005 09:51:39 +0000 Subject: [PATCH] Moved 'static' functions into 'parserHelpers' class. --- ChangeLog | 4 ++ src/address.cpp | 2 +- src/body.cpp | 2 +- src/dateTime.cpp | 86 ++++++++++++++++---------------- src/encoderB64.cpp | 4 +- src/encoderUUE.cpp | 8 +-- src/header.cpp | 6 +-- src/mailbox.cpp | 18 +++---- src/mailboxGroup.cpp | 2 +- src/messaging/url.cpp | 2 +- src/messaging/urlUtils.cpp | 3 +- src/parameterizedHeaderField.cpp | 10 ++-- src/propertySet.cpp | 9 ++-- src/text.cpp | 6 +-- src/utility/stringUtils.cpp | 6 +-- vmime/parserHelpers.hpp | 65 +++++++++++++----------- 16 files changed, 122 insertions(+), 111 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4c499e98..4e0d5cbb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ VERSION 0.6.4cvs ================ +2005-02-05 Vincent Richard + + * parserHelpers.hpp: moved 'static' functions into 'parserHelpers' class. + 2005-02-05 Vincent Richard * platforms/posix/posixHandler.cpp: removed extra '::' before diff --git a/src/address.cpp b/src/address.cpp index a9673bb9..14786d54 100644 --- a/src/address.cpp +++ b/src/address.cpp @@ -74,7 +74,7 @@ address* address::parseNext(const string& buffer, const string::size_type positi string::size_type pos = position; - while (pos < end && isspace(buffer[pos])) + while (pos < end && parserHelpers::isspace(buffer[pos])) ++pos; const string::size_type start = pos; diff --git a/src/body.cpp b/src/body.cpp index 74c3a8e8..6f3b0ec6 100644 --- a/src/body.cpp +++ b/src/body.cpp @@ -109,7 +109,7 @@ void body::parse(const string& buffer, const string::size_type position, // characters from a set of characters known to be very // robust through email gateways, and NOT ending with // white space..." - while (pos != start && isspace(buffer[pos - 1])) + while (pos != start && parserHelpers::isspace(buffer[pos - 1])) --pos; boundary = string(buffer.begin() + start, diff --git a/src/dateTime.cpp b/src/dateTime.cpp index ce554be6..6d314306 100644 --- a/src/dateTime.cpp +++ b/src/dateTime.cpp @@ -70,22 +70,22 @@ void datetime::parse(const string& buffer, const string::size_type position, const string::value_type* p = buffer.data() + position; // Parse the date and time value - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; if (p < pend) { - if (isalpha(*p)) + if (parserHelpers::isalpha(*p)) { // Ignore week day - while (p < pend && isalpha(*p)) ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isalpha(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; if (p < pend && *p == ',') ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; } - while (p < pend && !isdigit(*p)) ++p; + while (p < pend && !parserHelpers::isdigit(*p)) ++p; - if (p < pend && isdigit(*p)) + if (p < pend && parserHelpers::isdigit(*p)) { // Month day int day = 0; @@ -95,23 +95,23 @@ void datetime::parse(const string& buffer, const string::size_type position, day = day * 10 + (*p - '0'); ++p; } - while (p < pend && isdigit(*p)); + while (p < pend && parserHelpers::isdigit(*p)); m_day = (day >= 1 && day <= 31) ? day : 1; - while (p < pend && !isspace(*p)) ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && !parserHelpers::isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; } else { m_day = 1; // Skip everything to the next field - while (p < pend && !isspace(*p)) ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && !parserHelpers::isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; } - if (p < pend && isalpha(*p)) + if (p < pend && parserHelpers::isalpha(*p)) { // Month char_t month[4] = { 0 }; @@ -122,9 +122,9 @@ void datetime::parse(const string& buffer, const string::size_type position, month[monthLength++] = *p; ++p; } - while (monthLength < 3 && p < pend && isalpha(*p)); + while (monthLength < 3 && p < pend && parserHelpers::isalpha(*p)); - while (p < pend && isalpha(*p)) ++p; + while (p < pend && parserHelpers::isalpha(*p)) ++p; switch (month[0]) { @@ -208,19 +208,19 @@ void datetime::parse(const string& buffer, const string::size_type position, } - while (p < pend && !isspace(*p)) ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && !parserHelpers::isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; } else { m_month = JANUARY; // Skip everything to the next field - while (p < pend && !isspace(*p)) ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && !parserHelpers::isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; } - if (p < pend && isdigit(*p)) + if (p < pend && parserHelpers::isdigit(*p)) { // Year int year = 0; @@ -230,25 +230,25 @@ void datetime::parse(const string& buffer, const string::size_type position, year = year * 10 + (*p - '0'); ++p; } - while (p < pend && isdigit(*p)); + while (p < pend && parserHelpers::isdigit(*p)); if (year < 70) m_year = year + 2000; else if (year < 1000) m_year = year + 1900; else m_year = year; - while (p < pend && !isspace(*p)) ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && !parserHelpers::isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; } else { m_year = 1970; // Skip everything to the next field - while (p < pend && !isspace(*p)) ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && !parserHelpers::isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; } - if (p < pend && isdigit(*p)) + if (p < pend && parserHelpers::isdigit(*p)) { // Hour int hour = 0; @@ -258,19 +258,19 @@ void datetime::parse(const string& buffer, const string::size_type position, hour = hour * 10 + (*p - '0'); ++p; } - while (p < pend && isdigit(*p)); + while (p < pend && parserHelpers::isdigit(*p)); m_hour = (hour >= 0 && hour <= 23) ? hour : 0; - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; if (p < pend && *p == ':') { ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; - if (p < pend && isdigit(*p)) + if (p < pend && parserHelpers::isdigit(*p)) { // Minute int minute = 0; @@ -280,19 +280,19 @@ void datetime::parse(const string& buffer, const string::size_type position, minute = minute * 10 + (*p - '0'); ++p; } - while (p < pend && isdigit(*p)); + while (p < pend && parserHelpers::isdigit(*p)); m_minute = (minute >= 0 && minute <= 59) ? minute : 0; - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; if (p < pend && *p == ':') { ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; - if (p < pend && isdigit(*p)) + if (p < pend && parserHelpers::isdigit(*p)) { // Second int second = 0; @@ -302,12 +302,12 @@ void datetime::parse(const string& buffer, const string::size_type position, second = second * 10 + (*p - '0'); ++p; } - while (p < pend && isdigit(*p)); + while (p < pend && parserHelpers::isdigit(*p)); m_second = (second >= 0 && second <= 59) ? second : 0; - while (p < pend && !isspace(*p)) ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && !parserHelpers::isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; } else { @@ -334,11 +334,11 @@ void datetime::parse(const string& buffer, const string::size_type position, m_hour = 0; // Skip everything to the next field - while (p < pend && !isspace(*p)) ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && !parserHelpers::isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; } - if (p + 1 < pend && (*p == '+' || *p == '-') && isdigit(*(p + 1))) + if (p + 1 < pend && (*p == '+' || *p == '-') && parserHelpers::isdigit(*(p + 1))) { const char_t sign = *p; ++p; @@ -351,7 +351,7 @@ void datetime::parse(const string& buffer, const string::size_type position, offset = offset * 10 + (*p - '0'); ++p; } - while (p < pend && isdigit(*p)); + while (p < pend && parserHelpers::isdigit(*p)); const int hourOff = offset / 100; const int minOff = offset % 100; @@ -374,7 +374,7 @@ void datetime::parse(const string& buffer, const string::size_type position, zone[zoneLength++] = *p; ++p; } - while (zoneLength < 3 && p < pend && isdigit(*p)); + while (zoneLength < 3 && p < pend && parserHelpers::isdigit(*p)); switch (zone[0]) { @@ -495,7 +495,7 @@ void datetime::parse(const string& buffer, const string::size_type position, ::vmime::end(offsetMapInit)); Map::const_iterator pos = - offsetMap.find(tolower(z)); + offsetMap.find(parserHelpers::tolower(z)); if (pos != offsetMap.end()) m_zone = (*pos).second; diff --git a/src/encoderB64.cpp b/src/encoderB64.cpp index b700e6cd..581ea857 100644 --- a/src/encoderB64.cpp +++ b/src/encoderB64.cpp @@ -205,7 +205,7 @@ const utility::stream::size_type encoderB64::decode(utility::inputStream& in, ut { const unsigned char c = buffer[bufferPos++]; - if (!isspace(c)) + if (!parserHelpers::isspace(c)) bytes[count++] = c; } @@ -221,7 +221,7 @@ const utility::stream::size_type encoderB64::decode(utility::inputStream& in, ut { const unsigned char c = buffer[bufferPos++]; - if (!isspace(c)) + if (!parserHelpers::isspace(c)) bytes[count++] = c; } } diff --git a/src/encoderUUE.cpp b/src/encoderUUE.cpp index 8f082e12..8f6ad72f 100644 --- a/src/encoderUUE.cpp +++ b/src/encoderUUE.cpp @@ -173,7 +173,7 @@ const utility::stream::size_type encoderUUE::decode(utility::inputStream& in, ut inBuffer[1] == 'g' && inBuffer[2] == 'i' && inBuffer[3] == 'n' && - isspace(inBuffer[4])) + parserHelpers::isspace(inBuffer[4])) { utility::stream::value_type c = 0; @@ -201,15 +201,15 @@ const utility::stream::size_type encoderUUE::decode(utility::inputStream& in, ut utility::stream::value_type* p = buffer; - while (*p && isspace(*p)) ++p; + while (*p && parserHelpers::isspace(*p)) ++p; utility::stream::value_type* modeStart = buffer; - while (*p && !isspace(*p)) ++p; + while (*p && !parserHelpers::isspace(*p)) ++p; getResults()["mode"] = string(modeStart, p); - while (*p && isspace(*p)) ++p; + while (*p && parserHelpers::isspace(*p)) ++p; utility::stream::value_type* filenameStart = buffer; diff --git a/src/header.cpp b/src/header.cpp index ddbf183e..886283ba 100644 --- a/src/header.cpp +++ b/src/header.cpp @@ -81,16 +81,16 @@ void header::parse(const string& buffer, const string::size_type position, } // This line may be a field description - if (!isspace(c)) + if (!parserHelpers::isspace(c)) { const string::size_type nameStart = pos; // remember the start position of the line - while (pos < end && (buffer[pos] != ':' && !isspace(buffer[pos]))) + while (pos < end && (buffer[pos] != ':' && !parserHelpers::isspace(buffer[pos]))) ++pos; const string::size_type nameEnd = pos; - while (pos < end && isspace(buffer[pos])) + while (pos < end && parserHelpers::isspace(buffer[pos])) ++pos; if (buffer[pos] != ':') diff --git a/src/mailbox.cpp b/src/mailbox.cpp index aa9de741..f8d72aa0 100644 --- a/src/mailbox.cpp +++ b/src/mailbox.cpp @@ -69,7 +69,7 @@ void mailbox::parse(const string& buffer, const string::size_type position, const string::value_type* p = pstart; // Ignore blank spaces at the beginning - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; // Current state for parsing machine enum States @@ -161,12 +161,12 @@ void mailbox::parse(const string& buffer, const string::size_type position, { // Erase any space between display name and
string::iterator q = name.end(); - for ( ; q != name.begin() && isspace(*(q - 1)) ; --q); + for ( ; q != name.begin() && parserHelpers::isspace(*(q - 1)) ; --q); name.erase(q, name.end()); break; } - else if (/* isspace(*p) || */ *p == '@') + else if (/* parserHelpers::isspace(*p) || */ *p == '@') { break; } @@ -213,7 +213,7 @@ void mailbox::parse(const string& buffer, const string::size_type position, { ++comment; } - else if (isspace(*p)) + else if (parserHelpers::isspace(*p)) { break; } @@ -229,7 +229,7 @@ void mailbox::parse(const string& buffer, const string::size_type position, } else { - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; state = State_None; } } @@ -278,7 +278,7 @@ void mailbox::parse(const string& buffer, const string::size_type position, { break; } - else if (!isspace(*p)) + else if (!parserHelpers::isspace(*p)) { address += *p; } @@ -290,7 +290,7 @@ void mailbox::parse(const string& buffer, const string::size_type position, } else { - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; if (p < pend) { @@ -310,7 +310,7 @@ void mailbox::parse(const string& buffer, const string::size_type position, for (string::size_type i = 0 ; i < name.size() ; ++i) { - if (!isspace(name[i])) + if (!parserHelpers::isspace(name[i])) m_email += name[i]; } } @@ -322,7 +322,7 @@ void mailbox::parse(const string& buffer, const string::size_type position, for (string::size_type i = 0 ; i < address.size() ; ++i) { - if (!isspace(address[i])) + if (!parserHelpers::isspace(address[i])) m_email += address[i]; } } diff --git a/src/mailboxGroup.cpp b/src/mailboxGroup.cpp index b8b5fdec..1e653aa4 100644 --- a/src/mailboxGroup.cpp +++ b/src/mailboxGroup.cpp @@ -57,7 +57,7 @@ void mailboxGroup::parse(const string& buffer, const string::size_type position, const string::value_type* const pstart = buffer.data() + position; const string::value_type* p = pstart; - while (p < pend && isspace(*p)) + while (p < pend && parserHelpers::isspace(*p)) ++p; string name; diff --git a/src/messaging/url.cpp b/src/messaging/url.cpp index 33f31236..85025c64 100644 --- a/src/messaging/url.cpp +++ b/src/messaging/url.cpp @@ -206,7 +206,7 @@ void url::parse(const string& str) for (string::const_iterator it = port.begin() ; onlyDigit && it != port.end() ; ++it) { - onlyDigit = isdigit(*it); + onlyDigit = parserHelpers::isdigit(*it); } if (!onlyDigit) diff --git a/src/messaging/urlUtils.cpp b/src/messaging/urlUtils.cpp index 51db470d..d3eefc3d 100644 --- a/src/messaging/urlUtils.cpp +++ b/src/messaging/urlUtils.cpp @@ -18,6 +18,7 @@ // #include "vmime/messaging/urlUtils.hpp" +#include "vmime/parserHelpers.hpp" namespace vmime { @@ -33,7 +34,7 @@ const string urlUtils::encode(const string& s) { const char_t c = *it; - if (isprint(c) && c != '%') + if (parserHelpers::isprint(c) && c != '%') { result += c; } diff --git a/src/parameterizedHeaderField.cpp b/src/parameterizedHeaderField.cpp index 348eca21..2d7257be 100644 --- a/src/parameterizedHeaderField.cpp +++ b/src/parameterizedHeaderField.cpp @@ -78,7 +78,7 @@ void parameterizedHeaderField::parse(const string& buffer, const string::size_ty // Skip ';' ++p; - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; const string::size_type attrStart = position + (p - pstart); @@ -98,14 +98,14 @@ void parameterizedHeaderField::parse(const string& buffer, const string::size_ty // Extract the attribute name string::size_type attrEnd = position + (p - pstart); - while (attrEnd != attrStart && isspace(buffer[attrEnd - 1])) + while (attrEnd != attrStart && parserHelpers::isspace(buffer[attrEnd - 1])) --attrEnd; // Skip '=' ++p; // Skip white-spaces between '=' and the value - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; // Extract the value string value; @@ -173,7 +173,7 @@ void parameterizedHeaderField::parse(const string& buffer, const string::size_ty string::size_type valEnd = position + (p - pstart); - while (valEnd != valStart && isspace(buffer[valEnd - 1])) + while (valEnd != valStart && parserHelpers::isspace(buffer[valEnd - 1])) --valEnd; value = string(buffer.begin() + valStart, @@ -190,7 +190,7 @@ void parameterizedHeaderField::parse(const string& buffer, const string::size_ty } // Skip white-spaces after this parameter - while (p < pend && isspace(*p)) ++p; + while (p < pend && parserHelpers::isspace(*p)) ++p; } } } diff --git a/src/propertySet.cpp b/src/propertySet.cpp index 1a128771..839e5600 100644 --- a/src/propertySet.cpp +++ b/src/propertySet.cpp @@ -18,6 +18,7 @@ // #include "vmime/propertySet.hpp" +#include "vmime/parserHelpers.hpp" namespace vmime @@ -92,7 +93,7 @@ void propertySet::parse(const string& props) for ( ; pos != end ; ) { // Skip white-spaces - for ( ; pos != end && isspace(*pos) ; ++pos); + for ( ; pos != end && parserHelpers::isspace(*pos) ; ++pos); if (pos != end) { @@ -109,7 +110,7 @@ void propertySet::parse(const string& props) string::const_iterator optEnd = pos; - for ( ; optEnd != optStart && isspace(*(optEnd - 1)) ; --optEnd); + for ( ; optEnd != optStart && parserHelpers::isspace(*(optEnd - 1)) ; --optEnd); const string option(optStart, optEnd); string value = "1"; @@ -119,7 +120,7 @@ void propertySet::parse(const string& props) ++pos; // skip '=' // Extract the value - for ( ; pos != end && isspace(*pos) ; ++pos); + for ( ; pos != end && parserHelpers::isspace(*pos) ; ++pos); if (pos != end) { @@ -158,7 +159,7 @@ void propertySet::parse(const string& props) { const string::const_iterator valStart = pos; - for ( ; pos != end && !isspace(*pos) ; ++pos); + for ( ; pos != end && !parserHelpers::isspace(*pos) ; ++pos); value = string(valStart, pos); } diff --git a/src/text.cpp b/src/text.cpp index e0a6e1de..daf79d44 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -264,7 +264,7 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE for ( ; ; ) { - if (p == end || isspace(*p)) + if (p == end || parserHelpers::isspace(*p)) { if (p != end) ++p; @@ -309,7 +309,7 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE is8bit = false; start = p; } - else if (!isascii(*p)) + else if (!parserHelpers::isascii(*p)) { is8bit = true; ++p; @@ -784,7 +784,7 @@ void text::decodeAndUnfold(const string::const_iterator& inStart, const string:: { // Check whether there are only white-spaces between // the two encoded words - for ( ; (p != wordPos) && isspace(*p) ; ++p); + for ( ; (p != wordPos) && parserHelpers::isspace(*p) ; ++p); } if (p != wordPos) // if not empty diff --git a/src/utility/stringUtils.cpp b/src/utility/stringUtils.cpp index 3f91362f..988a6f53 100644 --- a/src/utility/stringUtils.cpp +++ b/src/utility/stringUtils.cpp @@ -94,8 +94,8 @@ const string stringUtils::trim(const string& str) if (b != e) { - for ( ; b != e && isspace(*b) ; ++b); - for ( ; e != b && isspace(*(e - 1)) ; --e); + for ( ; b != e && parserHelpers::isspace(*b) ; ++b); + for ( ; e != b && parserHelpers::isspace(*(e - 1)) ; --e); } return (string(b, e)); @@ -109,7 +109,7 @@ const string::size_type stringUtils::countASCIIchars for (string::const_iterator i = begin ; i != end ; ++i) { - if (isascii(*i)) + if (parserHelpers::isascii(*i)) { if (*i != '=' || *(i + 1) != '?') // To avoid bad behaviour... ++count; diff --git a/vmime/parserHelpers.hpp b/vmime/parserHelpers.hpp index 2830e1c6..7d44f05a 100644 --- a/vmime/parserHelpers.hpp +++ b/vmime/parserHelpers.hpp @@ -32,49 +32,54 @@ namespace vmime { -inline const bool isspace(const char_t c) +class parserHelpers { - return (c == ' ' || c == '\t' || c == '\n' || c == '\r'); -} +public: + + static const bool isspace(const char_t c) + { + return (c == ' ' || c == '\t' || c == '\n' || c == '\r'); + } -inline const bool isdigit(const char_t c) -{ - return (c >= '0' && c <= '9'); -} + static const bool isdigit(const char_t c) + { + return (c >= '0' && c <= '9'); + } -inline const bool isalpha(const char_t c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); -} + static const bool isalpha(const char_t c) + { + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); + } -inline const char_t tolower(const char_t c) -{ - if (c >= 'A' && c <= 'Z') - return ('a' + (c - 'A')); - else - return c; -} + static const char_t tolower(const char_t c) + { + if (c >= 'A' && c <= 'Z') + return ('a' + (c - 'A')); + else + return c; + } -// Checks whether a character is in the 7-bit US-ASCII charset + // Checks whether a character is in the 7-bit US-ASCII charset -inline const bool isascii(const char_t c) -{ - const unsigned int x = static_cast (c); - return (x <= 127); -} + static const bool isascii(const char_t c) + { + const unsigned int x = static_cast (c); + return (x <= 127); + } -// Checks whether a character has a visual representation + // Checks whether a character has a visual representation -inline const bool isprint(const char_t c) -{ - const unsigned int x = static_cast (c); - return (x >= 0x20 && x <= 0x7E); -} + static const bool isprint(const char_t c) + { + const unsigned int x = static_cast (c); + return (x >= 0x20 && x <= 0x7E); + } +}; } // vmime