aboutsummaryrefslogtreecommitdiffstats
path: root/src/utility
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/utility/encoder/b64Encoder.cpp70
-rw-r--r--src/utility/encoder/noopEncoder.cpp12
-rw-r--r--src/utility/encoder/qpEncoder.cpp76
-rw-r--r--src/utility/encoder/uuEncoder.cpp91
-rw-r--r--src/utility/filteredStream.cpp66
-rw-r--r--src/utility/inputStreamAdapter.cpp12
-rw-r--r--src/utility/inputStreamByteBufferAdapter.cpp16
-rw-r--r--src/utility/inputStreamSocketAdapter.cpp10
-rw-r--r--src/utility/inputStreamStringAdapter.cpp16
-rw-r--r--src/utility/inputStreamStringProxyAdapter.cpp14
-rw-r--r--src/utility/outputStream.cpp12
-rw-r--r--src/utility/outputStreamAdapter.cpp6
-rw-r--r--src/utility/outputStreamByteArrayAdapter.cpp3
-rw-r--r--src/utility/outputStreamSocketAdapter.cpp6
-rw-r--r--src/utility/outputStreamStringAdapter.cpp7
-rw-r--r--src/utility/parserInputStreamAdapter.cpp40
-rw-r--r--src/utility/progressListener.cpp8
-rw-r--r--src/utility/random.cpp4
-rw-r--r--src/utility/seekableInputStreamRegionAdapter.cpp18
-rw-r--r--src/utility/stream.cpp5
-rw-r--r--src/utility/streamUtils.cpp34
-rw-r--r--src/utility/stringProxy.cpp22
-rw-r--r--src/utility/stringUtils.cpp26
-rw-r--r--src/utility/url.cpp20
-rw-r--r--src/utility/urlUtils.cpp6
25 files changed, 307 insertions, 293 deletions
diff --git a/src/utility/encoder/b64Encoder.cpp b/src/utility/encoder/b64Encoder.cpp
index 20e16b98..274c23c0 100644
--- a/src/utility/encoder/b64Encoder.cpp
+++ b/src/utility/encoder/b64Encoder.cpp
@@ -70,34 +70,34 @@ const unsigned char b64Encoder::sm_decodeMap[256] =
};
#ifndef VMIME_BUILDING_DOC
- #define B64_WRITE(s, x, l) s.write(reinterpret_cast <utility::stream::value_type*>(x), l)
+ #define B64_WRITE(s, x, l) s.write(reinterpret_cast <byte_t*>(x), l)
#endif // VMIME_BUILDING_DOC
-utility::stream::size_type b64Encoder::encode(utility::inputStream& in,
+size_t b64Encoder::encode(utility::inputStream& in,
utility::outputStream& out, utility::progressListener* progress)
{
in.reset(); // may not work...
- const string::size_type propMaxLineLength =
- getProperties().getProperty <string::size_type>("maxlinelength", static_cast <string::size_type>(-1));
+ const size_t propMaxLineLength =
+ getProperties().getProperty <size_t>("maxlinelength", static_cast <size_t>(-1));
- const bool cutLines = (propMaxLineLength != static_cast <string::size_type>(-1));
- const string::size_type maxLineLength = std::min(propMaxLineLength, static_cast <string::size_type>(76));
+ const bool cutLines = (propMaxLineLength != static_cast <size_t>(-1));
+ const size_t maxLineLength = std::min(propMaxLineLength, static_cast <size_t>(76));
// Process data
- utility::stream::value_type buffer[65536];
- utility::stream::size_type bufferLength = 0;
- utility::stream::size_type bufferPos = 0;
+ byte_t buffer[65536];
+ size_t bufferLength = 0;
+ size_t bufferPos = 0;
- unsigned char bytes[3];
- unsigned char output[4];
+ byte_t bytes[3];
+ byte_t output[4];
- utility::stream::size_type total = 0;
- utility::stream::size_type inTotal = 0;
+ size_t total = 0;
+ size_t inTotal = 0;
- string::size_type curCol = 0;
+ size_t curCol = 0;
if (progress)
progress->start(0);
@@ -191,21 +191,21 @@ utility::stream::size_type b64Encoder::encode(utility::inputStream& in,
}
-utility::stream::size_type b64Encoder::decode(utility::inputStream& in,
+size_t b64Encoder::decode(utility::inputStream& in,
utility::outputStream& out, utility::progressListener* progress)
{
in.reset(); // may not work...
// Process the data
- char buffer[16384];
- utility::stream::size_type bufferLength = 0;
- utility::stream::size_type bufferPos = 0;
+ byte_t buffer[16384];
+ size_t bufferLength = 0;
+ size_t bufferPos = 0;
- utility::stream::size_type total = 0;
- utility::stream::size_type inTotal = 0;
+ size_t total = 0;
+ size_t inTotal = 0;
- unsigned char bytes[4];
- unsigned char output[3];
+ byte_t bytes[4];
+ byte_t output[3];
if (progress)
progress->start(0);
@@ -234,7 +234,7 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in,
while (count < 4 && bufferPos < bufferLength)
{
- const unsigned char c = buffer[bufferPos++];
+ const byte_t c = buffer[bufferPos++];
if (!parserHelpers::isSpace(c))
bytes[count++] = c;
@@ -250,7 +250,7 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in,
while (count < 4 && bufferPos < bufferLength)
{
- const unsigned char c = buffer[bufferPos++];
+ const byte_t c = buffer[bufferPos++];
if (!parserHelpers::isSpace(c))
bytes[count++] = c;
@@ -259,13 +259,13 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in,
}
// Decode the bytes
- unsigned char c1 = bytes[0];
- unsigned char c2 = bytes[1];
+ byte_t c1 = bytes[0];
+ byte_t c2 = bytes[1];
if (c1 == '=' || c2 == '=') // end
break;
- output[0] = static_cast <unsigned char>((sm_decodeMap[c1] << 2) | ((sm_decodeMap[c2] & 0x30) >> 4));
+ output[0] = static_cast <byte_t>((sm_decodeMap[c1] << 2) | ((sm_decodeMap[c2] & 0x30) >> 4));
c1 = bytes[2];
@@ -276,7 +276,7 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in,
break;
}
- output[1] = static_cast <unsigned char>(((sm_decodeMap[c2] & 0xf) << 4) | ((sm_decodeMap[c1] & 0x3c) >> 2));
+ output[1] = static_cast <byte_t>(((sm_decodeMap[c2] & 0xf) << 4) | ((sm_decodeMap[c1] & 0x3c) >> 2));
c2 = bytes[3];
@@ -287,7 +287,7 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in,
break;
}
- output[2] = static_cast <unsigned char>(((sm_decodeMap[c1] & 0x03) << 6) | sm_decodeMap[c2]);
+ output[2] = static_cast <byte_t>(((sm_decodeMap[c1] & 0x03) << 6) | sm_decodeMap[c2]);
B64_WRITE(out, output, 3);
total += 3;
@@ -304,13 +304,13 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in,
}
-utility::stream::size_type b64Encoder::getEncodedSize(const utility::stream::size_type n) const
+size_t b64Encoder::getEncodedSize(const size_t n) const
{
- const string::size_type propMaxLineLength =
- getProperties().getProperty <string::size_type>("maxlinelength", static_cast <string::size_type>(-1));
+ const size_t propMaxLineLength =
+ getProperties().getProperty <size_t>("maxlinelength", static_cast <size_t>(-1));
- const bool cutLines = (propMaxLineLength != static_cast <string::size_type>(-1));
- const string::size_type maxLineLength = std::min(propMaxLineLength, static_cast <string::size_type>(76));
+ const bool cutLines = (propMaxLineLength != static_cast <size_t>(-1));
+ const size_t maxLineLength = std::min(propMaxLineLength, static_cast <size_t>(76));
return (n * 4) / 3 // 3 bytes of input provide 4 bytes of output
+ (cutLines ? (n / maxLineLength) * 2 : 0) // CRLF (2 bytes) for each line.
@@ -318,7 +318,7 @@ utility::stream::size_type b64Encoder::getEncodedSize(const utility::stream::siz
}
-utility::stream::size_type b64Encoder::getDecodedSize(const utility::stream::size_type n) const
+size_t b64Encoder::getDecodedSize(const size_t n) const
{
// 4 bytes of input provide 3 bytes of output
return (n * 3) / 4;
diff --git a/src/utility/encoder/noopEncoder.cpp b/src/utility/encoder/noopEncoder.cpp
index cf72a4f6..3d991b5d 100644
--- a/src/utility/encoder/noopEncoder.cpp
+++ b/src/utility/encoder/noopEncoder.cpp
@@ -36,13 +36,13 @@ noopEncoder::noopEncoder()
}
-utility::stream::size_type noopEncoder::encode(utility::inputStream& in,
+size_t noopEncoder::encode(utility::inputStream& in,
utility::outputStream& out, utility::progressListener* progress)
{
in.reset(); // may not work...
// No encoding performed
- utility::stream::size_type res = 0;
+ size_t res = 0;
if (progress)
res = utility::bufferedStreamCopy(in, out, 0, progress);
@@ -53,13 +53,13 @@ utility::stream::size_type noopEncoder::encode(utility::inputStream& in,
}
-utility::stream::size_type noopEncoder::decode(utility::inputStream& in,
+size_t noopEncoder::decode(utility::inputStream& in,
utility::outputStream& out, utility::progressListener* progress)
{
in.reset(); // may not work...
// No decoding performed
- utility::stream::size_type res = 0;
+ size_t res = 0;
if (progress)
res = utility::bufferedStreamCopy(in, out, 0, progress);
@@ -70,13 +70,13 @@ utility::stream::size_type noopEncoder::decode(utility::inputStream& in,
}
-utility::stream::size_type noopEncoder::getEncodedSize(const utility::stream::size_type n) const
+size_t noopEncoder::getEncodedSize(const size_t n) const
{
return n;
}
-utility::stream::size_type noopEncoder::getDecodedSize(const utility::stream::size_type n) const
+size_t noopEncoder::getDecodedSize(const size_t n) const
{
return n;
}
diff --git a/src/utility/encoder/qpEncoder.cpp b/src/utility/encoder/qpEncoder.cpp
index 1768818c..c77b5163 100644
--- a/src/utility/encoder/qpEncoder.cpp
+++ b/src/utility/encoder/qpEncoder.cpp
@@ -69,7 +69,7 @@ const unsigned char qpEncoder::sm_hexDigits[] = "0123456789ABCDEF";
// This is a quick lookup table:
// '1' means "encode", '0' means "no encoding"
//
-const unsigned char qpEncoder::sm_RFC2047EncodeTable[] =
+const vmime_uint8 qpEncoder::sm_RFC2047EncodeTable[] =
{
/* 0 NUL */ 1, /* 1 SOH */ 1, /* 2 STX */ 1, /* 3 ETX */ 1, /* 4 EOT */ 1, /* 5 ENQ */ 1,
/* 6 ACK */ 1, /* 7 BEL */ 1, /* 8 BS */ 1, /* 9 TAB */ 1, /* 10 LF */ 1, /* 11 VT */ 1,
@@ -97,7 +97,7 @@ const unsigned char qpEncoder::sm_RFC2047EncodeTable[] =
// Hex-decoding table
-const unsigned char qpEncoder::sm_hexDecodeTable[256] =
+const vmime_uint8 qpEncoder::sm_hexDecodeTable[256] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -119,14 +119,14 @@ const unsigned char qpEncoder::sm_hexDecodeTable[256] =
// static
-bool qpEncoder::RFC2047_isEncodingNeededForChar(const unsigned char c)
+bool qpEncoder::RFC2047_isEncodingNeededForChar(const byte_t c)
{
return (c >= 128 || sm_RFC2047EncodeTable[c] != 0);
}
// static
-int qpEncoder::RFC2047_getEncodedLength(const unsigned char c)
+int qpEncoder::RFC2047_getEncodedLength(const byte_t c)
{
if (c >= 128 || sm_RFC2047EncodeTable[c] != 0)
{
@@ -157,37 +157,37 @@ int qpEncoder::RFC2047_getEncodedLength(const unsigned char c)
outBufferPos += 3; \
curCol += 3
-#define QP_WRITE(s, x, l) s.write(reinterpret_cast <utility::stream::value_type*>(x), l)
+#define QP_WRITE(s, x, l) s.write(reinterpret_cast <byte_t*>(x), l)
#endif // VMIME_BUILDING_DOC
-utility::stream::size_type qpEncoder::encode(utility::inputStream& in,
+size_t qpEncoder::encode(utility::inputStream& in,
utility::outputStream& out, utility::progressListener* progress)
{
in.reset(); // may not work...
- const string::size_type propMaxLineLength =
- getProperties().getProperty <string::size_type>("maxlinelength", static_cast <string::size_type>(-1));
+ const size_t propMaxLineLength =
+ getProperties().getProperty <size_t>("maxlinelength", static_cast <size_t>(-1));
const bool rfc2047 = getProperties().getProperty <bool>("rfc2047", false);
const bool text = getProperties().getProperty <bool>("text", false); // binary mode by default
- const bool cutLines = (propMaxLineLength != static_cast <string::size_type>(-1));
- const string::size_type maxLineLength = std::min(propMaxLineLength, static_cast <string::size_type>(74));
+ const bool cutLines = (propMaxLineLength != static_cast <size_t>(-1));
+ const size_t maxLineLength = std::min(propMaxLineLength, static_cast <size_t>(74));
// Process the data
- char buffer[16384];
- utility::stream::size_type bufferLength = 0;
- utility::stream::size_type bufferPos = 0;
+ byte_t buffer[16384];
+ size_t bufferLength = 0;
+ size_t bufferPos = 0;
- string::size_type curCol = 0;
+ size_t curCol = 0;
- unsigned char outBuffer[16384];
- int outBufferPos = 0;
+ byte_t outBuffer[16384];
+ size_t outBufferPos = 0;
- utility::stream::size_type total = 0;
- utility::stream::size_type inTotal = 0;
+ size_t total = 0;
+ size_t inTotal = 0;
if (progress)
progress->start(0);
@@ -215,7 +215,7 @@ utility::stream::size_type qpEncoder::encode(utility::inputStream& in,
}
// Get the next char and encode it
- const unsigned char c = static_cast <unsigned char>(buffer[bufferPos++]);
+ const byte_t c = buffer[bufferPos++];
if (rfc2047)
{
@@ -371,7 +371,7 @@ utility::stream::size_type qpEncoder::encode(utility::inputStream& in,
}
-utility::stream::size_type qpEncoder::decode(utility::inputStream& in,
+size_t qpEncoder::decode(utility::inputStream& in,
utility::outputStream& out, utility::progressListener* progress)
{
in.reset(); // may not work...
@@ -379,20 +379,20 @@ utility::stream::size_type qpEncoder::decode(utility::inputStream& in,
// Process the data
const bool rfc2047 = getProperties().getProperty <bool>("rfc2047", false);
- char buffer[16384];
- utility::stream::size_type bufferLength = 0;
- utility::stream::size_type bufferPos = 0;
+ byte_t buffer[16384];
+ size_t bufferLength = 0;
+ size_t bufferPos = 0;
- unsigned char outBuffer[16384];
- int outBufferPos = 0;
+ byte_t outBuffer[16384];
+ size_t outBufferPos = 0;
- utility::stream::size_type total = 0;
- utility::stream::size_type inTotal = 0;
+ size_t total = 0;
+ size_t inTotal = 0;
while (bufferPos < bufferLength || !in.eof())
{
// Flush current output buffer
- if (outBufferPos >= static_cast <int>(sizeof(outBuffer)))
+ if (outBufferPos >= sizeof(outBuffer))
{
QP_WRITE(out, outBuffer, outBufferPos);
@@ -412,7 +412,7 @@ utility::stream::size_type qpEncoder::decode(utility::inputStream& in,
}
// Decode the next sequence (hex-encoded byte or printable character)
- unsigned char c = static_cast <unsigned char>(buffer[bufferPos++]);
+ byte_t c = buffer[bufferPos++];
++inTotal;
@@ -428,7 +428,7 @@ utility::stream::size_type qpEncoder::decode(utility::inputStream& in,
if (bufferPos < bufferLength)
{
- c = static_cast <unsigned char>(buffer[bufferPos++]);
+ c = buffer[bufferPos++];
++inTotal;
@@ -468,11 +468,11 @@ utility::stream::size_type qpEncoder::decode(utility::inputStream& in,
if (bufferPos < bufferLength)
{
- const unsigned char next = static_cast <unsigned char>(buffer[bufferPos++]);
+ const byte_t next = buffer[bufferPos++];
++inTotal;
- const unsigned char value = static_cast <unsigned char>
+ const byte_t value = static_cast <byte_t>
(sm_hexDecodeTable[c] * 16 + sm_hexDecodeTable[next]);
outBuffer[outBufferPos++] = value;
@@ -532,13 +532,13 @@ utility::stream::size_type qpEncoder::decode(utility::inputStream& in,
}
-utility::stream::size_type qpEncoder::getEncodedSize(const utility::stream::size_type n) const
+size_t qpEncoder::getEncodedSize(const size_t n) const
{
- const string::size_type propMaxLineLength =
- getProperties().getProperty <string::size_type>("maxlinelength", static_cast <string::size_type>(-1));
+ const size_t propMaxLineLength =
+ getProperties().getProperty <size_t>("maxlinelength", static_cast <size_t>(-1));
- const bool cutLines = (propMaxLineLength != static_cast <string::size_type>(-1));
- const string::size_type maxLineLength = std::min(propMaxLineLength, static_cast <string::size_type>(74));
+ const bool cutLines = (propMaxLineLength != static_cast <size_t>(-1));
+ const size_t maxLineLength = std::min(propMaxLineLength, static_cast <size_t>(74));
// Worst cast: 1 byte of input provide 3 bytes of output
// Count CRLF (2 bytes) for each line.
@@ -546,7 +546,7 @@ utility::stream::size_type qpEncoder::getEncodedSize(const utility::stream::size
}
-utility::stream::size_type qpEncoder::getDecodedSize(const utility::stream::size_type n) const
+size_t qpEncoder::getDecodedSize(const size_t n) const
{
// Worst case: 1 byte of input equals 1 byte of output
return n;
diff --git a/src/utility/encoder/uuEncoder.cpp b/src/utility/encoder/uuEncoder.cpp
index 3f751d3b..0375a397 100644
--- a/src/utility/encoder/uuEncoder.cpp
+++ b/src/utility/encoder/uuEncoder.cpp
@@ -52,19 +52,19 @@ const std::vector <string> uuEncoder::getAvailableProperties() const
// This is the character encoding function to make a character printable
-static inline unsigned char UUENCODE(const unsigned long c)
+static inline byte_t UUENCODE(const unsigned int c)
{
- return static_cast <unsigned char>((c & 077) + ' ');
+ return static_cast <byte_t>((c & 077) + ' ');
}
// Single character decoding
-static inline unsigned char UUDECODE(const unsigned long c)
+static inline unsigned int UUDECODE(const unsigned int c)
{
- return static_cast <unsigned char>((c - ' ') & 077);
+ return (c - ' ') & 077;
}
-utility::stream::size_type uuEncoder::encode(utility::inputStream& in,
+size_t uuEncoder::encode(utility::inputStream& in,
utility::outputStream& out, utility::progressListener* progress)
{
in.reset(); // may not work...
@@ -72,12 +72,11 @@ utility::stream::size_type uuEncoder::encode(utility::inputStream& in,
const string propFilename = getProperties().getProperty <string>("filename", "");
const string propMode = getProperties().getProperty <string>("mode", "644");
- const string::size_type maxLineLength =
- std::min(getProperties().getProperty <string::size_type>("maxlinelength", 46),
- static_cast <string::size_type>(46));
+ const size_t maxLineLength =
+ std::min(getProperties().getProperty <size_t>("maxlinelength", 46), static_cast <size_t>(46));
- utility::stream::size_type total = 0;
- utility::stream::size_type inTotal = 0;
+ size_t total = 0;
+ size_t inTotal = 0;
// Output the prelude text ("begin [mode] [filename]")
out << "begin";
@@ -92,8 +91,8 @@ utility::stream::size_type uuEncoder::encode(utility::inputStream& in,
total += 7;
// Process the data
- utility::stream::value_type inBuffer[64];
- utility::stream::value_type outBuffer[64];
+ byte_t inBuffer[64];
+ byte_t outBuffer[64];
if (progress)
progress->start(0);
@@ -103,17 +102,17 @@ utility::stream::size_type uuEncoder::encode(utility::inputStream& in,
// Process up to 45 characters per line
std::fill(inBuffer, inBuffer + sizeof(inBuffer), 0);
- const utility::stream::size_type inLength = in.read(inBuffer, maxLineLength - 1);
+ const size_t inLength = in.read(inBuffer, maxLineLength - 1);
- outBuffer[0] = UUENCODE(inLength); // Line length
+ outBuffer[0] = UUENCODE(static_cast <unsigned int>(inLength)); // Line length
- utility::stream::size_type j = 1;
+ size_t j = 1;
- for (utility::stream::size_type i = 0 ; i < inLength ; i += 3, j += 4)
+ for (size_t i = 0 ; i < inLength ; i += 3, j += 4)
{
- const unsigned char c1 = static_cast <unsigned char>(inBuffer[i]);
- const unsigned char c2 = static_cast <unsigned char>(inBuffer[i + 1]);
- const unsigned char c3 = static_cast <unsigned char>(inBuffer[i + 2]);
+ const byte_t c1 = inBuffer[i];
+ const byte_t c2 = inBuffer[i + 1];
+ const byte_t c3 = inBuffer[i + 2];
outBuffer[j] = UUENCODE(c1 >> 2);
outBuffer[j + 1] = UUENCODE(((c1 << 4) & 060) | ((c2 >> 4) & 017));
@@ -143,17 +142,17 @@ utility::stream::size_type uuEncoder::encode(utility::inputStream& in,
}
-utility::stream::size_type uuEncoder::decode(utility::inputStream& in,
+size_t uuEncoder::decode(utility::inputStream& in,
utility::outputStream& out, utility::progressListener* progress)
{
in.reset(); // may not work...
// Process the data
- utility::stream::value_type inBuffer[64];
- utility::stream::value_type outBuffer[64];
+ byte_t inBuffer[64];
+ byte_t outBuffer[64];
- utility::stream::size_type total = 0;
- utility::stream::size_type inTotal = 0;
+ size_t total = 0;
+ size_t inTotal = 0;
bool stop = false;
@@ -165,15 +164,14 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in,
while (!stop && !in.eof())
{
// Get the line length
- utility::stream::value_type lengthChar;
+ byte_t lengthChar;
if (in.read(&lengthChar, 1) == 0)
break;
- const utility::stream::size_type outLength = UUDECODE(lengthChar);
- const utility::stream::size_type inLength =
- std::min((outLength * 4) / 3, static_cast <utility::stream::size_type>(64));
- utility::stream::size_type inPos = 0;
+ const size_t outLength = UUDECODE(lengthChar);
+ const size_t inLength = std::min((outLength * 4) / 3, static_cast <size_t>(64));
+ size_t inPos = 0;
switch (lengthChar)
{
@@ -199,10 +197,10 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in,
{
inTotal += 5;
- utility::stream::value_type c = 0;
+ byte_t c = 0;
- utility::stream::size_type count = 0;
- utility::stream::value_type buffer[512];
+ size_t count = 0;
+ byte_t buffer[512];
while (count < sizeof(buffer) - 1 && in.read(&c, 1) == 1)
{
@@ -229,11 +227,11 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in,
{
buffer[count] = '\0';
- utility::stream::value_type* p = buffer;
+ byte_t* p = buffer;
while (*p && parserHelpers::isSpace(*p)) ++p;
- utility::stream::value_type* modeStart = buffer;
+ byte_t* modeStart = buffer;
while (*p && !parserHelpers::isSpace(*p)) ++p;
@@ -241,7 +239,7 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in,
while (*p && parserHelpers::isSpace(*p)) ++p;
- utility::stream::value_type* filenameStart = buffer;
+ byte_t* filenameStart = buffer;
while (*p && !(*p == '\r' || *p == '\n')) ++p;
@@ -289,22 +287,21 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in,
inTotal += (inLength - inPos);
// Decode data
- for (utility::stream::size_type i = 0, j = 0 ; i < inLength ; i += 4, j += 3)
+ for (size_t i = 0, j = 0 ; i < inLength ; i += 4, j += 3)
{
- const unsigned char c1 = static_cast <unsigned char>(inBuffer[i]);
- const unsigned char c2 = static_cast <unsigned char>(inBuffer[i + 1]);
- const unsigned char c3 = static_cast <unsigned char>(inBuffer[i + 2]);
- const unsigned char c4 = static_cast <unsigned char>(inBuffer[i + 3]);
+ const byte_t c1 = inBuffer[i];
+ const byte_t c2 = inBuffer[i + 1];
+ const byte_t c3 = inBuffer[i + 2];
+ const byte_t c4 = inBuffer[i + 3];
- const utility::stream::size_type n =
- std::min(inLength - i, static_cast <utility::stream::size_type>(3));
+ const size_t n = std::min(inLength - i, static_cast <size_t>(3));
switch (n)
{
default:
- case 3: outBuffer[j + 2] = static_cast <unsigned char>(UUDECODE(c3) << 6 | UUDECODE(c4));
- case 2: outBuffer[j + 1] = static_cast <unsigned char>(UUDECODE(c2) << 4 | UUDECODE(c3) >> 2);
- case 1: outBuffer[j] = static_cast <unsigned char>(UUDECODE(c1) << 2 | UUDECODE(c2) >> 4);
+ case 3: outBuffer[j + 2] = static_cast <byte_t>(UUDECODE(c3) << 6 | UUDECODE(c4));
+ case 2: outBuffer[j + 1] = static_cast <byte_t>(UUDECODE(c2) << 4 | UUDECODE(c3) >> 2);
+ case 1: outBuffer[j] = static_cast <byte_t>(UUDECODE(c1) << 2 | UUDECODE(c2) >> 4);
case 0: break;
}
@@ -326,7 +323,7 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in,
}
-utility::stream::size_type uuEncoder::getEncodedSize(const utility::stream::size_type n) const
+size_t uuEncoder::getEncodedSize(const size_t n) const
{
// 3 bytes of input provide 4 bytes of output.
// Count CRLF (2 bytes) for each line of 45 characters.
@@ -335,7 +332,7 @@ utility::stream::size_type uuEncoder::getEncodedSize(const utility::stream::size
}
-utility::stream::size_type uuEncoder::getDecodedSize(const utility::stream::size_type n) const
+size_t uuEncoder::getDecodedSize(const size_t n) const
{
// 4 bytes of input provide 3 bytes of output
return (n * 3) / 4;
diff --git a/src/utility/filteredStream.cpp b/src/utility/filteredStream.cpp
index ecc2eae2..bb705162 100644
--- a/src/utility/filteredStream.cpp
+++ b/src/utility/filteredStream.cpp
@@ -32,7 +32,7 @@ namespace utility {
// filteredInputStream
-stream::size_type filteredInputStream::getBlockSize()
+size_t filteredInputStream::getBlockSize()
{
return std::min(inputStream::getBlockSize(), getPreviousInputStream().getBlockSize());
}
@@ -40,7 +40,7 @@ stream::size_type filteredInputStream::getBlockSize()
// filteredOutputStream
-stream::size_type filteredOutputStream::getBlockSize()
+size_t filteredOutputStream::getBlockSize()
{
return std::min(outputStream::getBlockSize(), getNextOutputStream().getBlockSize());
}
@@ -75,26 +75,26 @@ void dotFilteredInputStream::reset()
}
-stream::size_type dotFilteredInputStream::read(value_type* const data, const size_type count)
+size_t dotFilteredInputStream::read(byte_t* const data, const size_t count)
{
- const stream::size_type read = m_stream.read(data, count);
+ const size_t read = m_stream.read(data, count);
- const value_type* readPtr = data;
- value_type* writePtr = data;
+ const byte_t* readPtr = data;
+ byte_t* writePtr = data;
- const value_type* end = data + read;
+ const byte_t* end = data + read;
- stream::size_type written = 0;
+ size_t written = 0;
// Replace "\n.." with "\n."
while (readPtr < end)
{
if (*readPtr == '.')
{
- const value_type prevChar2 =
+ const byte_t prevChar2 =
(readPtr == data + 1 ? m_previousChar1 :
readPtr == data ? m_previousChar2 : *(readPtr - 2));
- const value_type prevChar1 =
+ const byte_t prevChar1 =
(readPtr == data ? m_previousChar1 : *(readPtr - 1));
if (prevChar2 == '\n' && prevChar1 == '.')
@@ -127,7 +127,7 @@ stream::size_type dotFilteredInputStream::read(value_type* const data, const siz
}
-stream::size_type dotFilteredInputStream::skip(const size_type /* count */)
+size_t dotFilteredInputStream::skip(const size_t /* count */)
{
// Skipping bytes is not supported
return 0;
@@ -148,15 +148,15 @@ outputStream& dotFilteredOutputStream::getNextOutputStream()
}
-void dotFilteredOutputStream::write
- (const value_type* const data, const size_type count)
+void dotFilteredOutputStream::writeImpl
+ (const byte_t* const data, const size_t count)
{
if (count == 0)
return;
- const value_type* pos = data;
- const value_type* end = data + count;
- const value_type* start = data;
+ const byte_t* pos = data;
+ const byte_t* end = data + count;
+ const byte_t* start = data;
if (m_previousChar == '.')
{
@@ -172,7 +172,7 @@ void dotFilteredOutputStream::write
// Replace "\n." with "\n.."
while ((pos = std::find(pos, end, '.')) != end)
{
- const value_type previousChar =
+ const byte_t previousChar =
(pos == data ? m_previousChar : *(pos - 1));
if (previousChar == '\n')
@@ -224,15 +224,15 @@ outputStream& CRLFToLFFilteredOutputStream::getNextOutputStream()
}
-void CRLFToLFFilteredOutputStream::write
- (const value_type* const data, const size_type count)
+void CRLFToLFFilteredOutputStream::writeImpl
+ (const byte_t* const data, const size_t count)
{
if (count == 0)
return;
- const value_type* pos = data;
- const value_type* end = data + count;
- const value_type* start = data;
+ const byte_t* pos = data;
+ const byte_t* end = data + count;
+ const byte_t* start = data;
// Warning: if the whole buffer finishes with '\r', this
// last character will not be written back if flush() is
@@ -249,7 +249,7 @@ void CRLFToLFFilteredOutputStream::write
// Replace "\r\n" (CRLF) with "\n" (LF)
while ((pos = std::find(pos, end, '\n')) != end)
{
- const value_type previousChar =
+ const byte_t previousChar =
(pos == data ? m_previousChar : *(pos - 1));
if (previousChar == '\r')
@@ -300,8 +300,8 @@ outputStream& LFToCRLFFilteredOutputStream::getNextOutputStream()
}
-void LFToCRLFFilteredOutputStream::write
- (const value_type* const data, const size_type count)
+void LFToCRLFFilteredOutputStream::writeImpl
+ (const byte_t* const data, const size_t count)
{
if (count == 0)
return;
@@ -309,10 +309,10 @@ void LFToCRLFFilteredOutputStream::write
string buffer;
buffer.reserve(count);
- const value_type* pos = data;
- const value_type* end = data + count;
+ const byte_t* pos = data;
+ const byte_t* end = data + count;
- value_type previousChar = m_previousChar;
+ byte_t previousChar = m_previousChar;
while (pos < end)
{
@@ -360,8 +360,8 @@ void LFToCRLFFilteredOutputStream::flush()
// stopSequenceFilteredInputStream <1>
template <>
-stream::size_type stopSequenceFilteredInputStream <1>::read
- (value_type* const data, const size_type count)
+size_t stopSequenceFilteredInputStream <1>::read
+ (byte_t* const data, const size_t count)
{
if (eof() || m_stream.eof())
{
@@ -369,10 +369,10 @@ stream::size_type stopSequenceFilteredInputStream <1>::read
return 0;
}
- const size_type read = m_stream.read(data, count);
- value_type* end = data + read;
+ const size_t read = m_stream.read(data, count);
+ byte_t* end = data + read;
- value_type* pos = std::find(data, end, m_sequence[0]);
+ byte_t* pos = std::find(data, end, m_sequence[0]);
if (pos == end)
{
diff --git a/src/utility/inputStreamAdapter.cpp b/src/utility/inputStreamAdapter.cpp
index a9ce79f3..c0b06be4 100644
--- a/src/utility/inputStreamAdapter.cpp
+++ b/src/utility/inputStreamAdapter.cpp
@@ -48,16 +48,16 @@ void inputStreamAdapter::reset()
}
-stream::size_type inputStreamAdapter::read
- (value_type* const data, const size_type count)
+size_t inputStreamAdapter::read
+ (byte_t* const data, const size_t count)
{
m_stream.exceptions(std::ios_base::badbit);
- m_stream.read(data, count);
+ m_stream.read(reinterpret_cast <char*>(data), count);
return (m_stream.gcount());
}
-stream::size_type inputStreamAdapter::skip(const size_type count)
+size_t inputStreamAdapter::skip(const size_t count)
{
m_stream.exceptions(std::ios_base::badbit);
m_stream.ignore(count);
@@ -65,13 +65,13 @@ stream::size_type inputStreamAdapter::skip(const size_type count)
}
-stream::size_type inputStreamAdapter::getPosition() const
+size_t inputStreamAdapter::getPosition() const
{
return m_stream.tellg();
}
-void inputStreamAdapter::seek(const size_type pos)
+void inputStreamAdapter::seek(const size_t pos)
{
m_stream.clear();
m_stream.seekg(pos, std::ios_base::beg);
diff --git a/src/utility/inputStreamByteBufferAdapter.cpp b/src/utility/inputStreamByteBufferAdapter.cpp
index e55fd47e..c270ea56 100644
--- a/src/utility/inputStreamByteBufferAdapter.cpp
+++ b/src/utility/inputStreamByteBufferAdapter.cpp
@@ -28,7 +28,7 @@ namespace vmime {
namespace utility {
-inputStreamByteBufferAdapter::inputStreamByteBufferAdapter(const byte_t* buffer, const size_type length)
+inputStreamByteBufferAdapter::inputStreamByteBufferAdapter(const byte_t* buffer, const size_t length)
: m_buffer(buffer), m_length(length), m_pos(0)
{
}
@@ -46,10 +46,10 @@ void inputStreamByteBufferAdapter::reset()
}
-stream::size_type inputStreamByteBufferAdapter::read
- (value_type* const data, const size_type count)
+size_t inputStreamByteBufferAdapter::read
+ (byte_t* const data, const size_t count)
{
- const size_type remaining = m_length - m_pos;
+ const size_t remaining = m_length - m_pos;
if (remaining < count)
{
@@ -68,9 +68,9 @@ stream::size_type inputStreamByteBufferAdapter::read
}
-stream::size_type inputStreamByteBufferAdapter::skip(const size_type count)
+size_t inputStreamByteBufferAdapter::skip(const size_t count)
{
- const size_type remaining = m_length - m_pos;
+ const size_t remaining = m_length - m_pos;
if (remaining < count)
{
@@ -85,13 +85,13 @@ stream::size_type inputStreamByteBufferAdapter::skip(const size_type count)
}
-stream::size_type inputStreamByteBufferAdapter::getPosition() const
+size_t inputStreamByteBufferAdapter::getPosition() const
{
return m_pos;
}
-void inputStreamByteBufferAdapter::seek(const size_type pos)
+void inputStreamByteBufferAdapter::seek(const size_t pos)
{
if (pos <= m_length)
m_pos = pos;
diff --git a/src/utility/inputStreamSocketAdapter.cpp b/src/utility/inputStreamSocketAdapter.cpp
index 095522d6..d78855eb 100644
--- a/src/utility/inputStreamSocketAdapter.cpp
+++ b/src/utility/inputStreamSocketAdapter.cpp
@@ -53,22 +53,22 @@ void inputStreamSocketAdapter::reset()
}
-stream::size_type inputStreamSocketAdapter::read
- (value_type* const data, const size_type count)
+size_t inputStreamSocketAdapter::read
+ (byte_t* const data, const size_t count)
{
return m_socket.receiveRaw(data, count);
}
-stream::size_type inputStreamSocketAdapter::skip
- (const size_type /* count */)
+size_t inputStreamSocketAdapter::skip
+ (const size_t /* count */)
{
// Not supported
return 0;
}
-stream::size_type inputStreamSocketAdapter::getBlockSize()
+size_t inputStreamSocketAdapter::getBlockSize()
{
return m_socket.getBlockSize();
}
diff --git a/src/utility/inputStreamStringAdapter.cpp b/src/utility/inputStreamStringAdapter.cpp
index c6bcdf49..9b897b97 100644
--- a/src/utility/inputStreamStringAdapter.cpp
+++ b/src/utility/inputStreamStringAdapter.cpp
@@ -35,7 +35,7 @@ inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer)
inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer,
- const string::size_type begin, const string::size_type end)
+ const size_t begin, const size_t end)
: m_buffer(buffer), m_begin(begin), m_end(end), m_pos(begin)
{
}
@@ -53,12 +53,12 @@ void inputStreamStringAdapter::reset()
}
-stream::size_type inputStreamStringAdapter::read
- (value_type* const data, const size_type count)
+size_t inputStreamStringAdapter::read
+ (byte_t* const data, const size_t count)
{
if (m_pos + count >= m_end)
{
- const size_type remaining = m_end - m_pos;
+ const size_t remaining = m_end - m_pos;
std::copy(m_buffer.begin() + m_pos, m_buffer.end(), data);
m_pos = m_end;
@@ -73,11 +73,11 @@ stream::size_type inputStreamStringAdapter::read
}
-stream::size_type inputStreamStringAdapter::skip(const size_type count)
+size_t inputStreamStringAdapter::skip(const size_t count)
{
if (m_pos + count >= m_end)
{
- const size_type remaining = m_end - m_pos;
+ const size_t remaining = m_end - m_pos;
m_pos = m_end;
return (remaining);
}
@@ -89,13 +89,13 @@ stream::size_type inputStreamStringAdapter::skip(const size_type count)
}
-stream::size_type inputStreamStringAdapter::getPosition() const
+size_t inputStreamStringAdapter::getPosition() const
{
return m_pos - m_begin;
}
-void inputStreamStringAdapter::seek(const size_type pos)
+void inputStreamStringAdapter::seek(const size_t pos)
{
if (m_begin + pos <= m_end)
m_pos = m_begin + pos;
diff --git a/src/utility/inputStreamStringProxyAdapter.cpp b/src/utility/inputStreamStringProxyAdapter.cpp
index 4a78714a..5513de80 100644
--- a/src/utility/inputStreamStringProxyAdapter.cpp
+++ b/src/utility/inputStreamStringProxyAdapter.cpp
@@ -47,10 +47,10 @@ void inputStreamStringProxyAdapter::reset()
}
-stream::size_type inputStreamStringProxyAdapter::read
- (value_type* const data, const size_type count)
+size_t inputStreamStringProxyAdapter::read
+ (byte_t* const data, const size_t count)
{
- const size_type remaining = m_buffer.length() - m_pos;
+ const size_t remaining = m_buffer.length() - m_pos;
if (count > remaining)
{
@@ -67,9 +67,9 @@ stream::size_type inputStreamStringProxyAdapter::read
}
-stream::size_type inputStreamStringProxyAdapter::skip(const size_type count)
+size_t inputStreamStringProxyAdapter::skip(const size_t count)
{
- const size_type remaining = m_buffer.length() - m_pos;
+ const size_t remaining = m_buffer.length() - m_pos;
if (count > remaining)
{
@@ -84,13 +84,13 @@ stream::size_type inputStreamStringProxyAdapter::skip(const size_type count)
}
-stream::size_type inputStreamStringProxyAdapter::getPosition() const
+size_t inputStreamStringProxyAdapter::getPosition() const
{
return m_pos;
}
-void inputStreamStringProxyAdapter::seek(const size_type pos)
+void inputStreamStringProxyAdapter::seek(const size_t pos)
{
if (pos <= m_buffer.length())
m_pos = pos;
diff --git a/src/utility/outputStream.cpp b/src/utility/outputStream.cpp
index a6238c41..070e28c5 100644
--- a/src/utility/outputStream.cpp
+++ b/src/utility/outputStream.cpp
@@ -28,6 +28,18 @@ namespace vmime {
namespace utility {
+void outputStream::write(const byte_t* const data, const size_t count)
+{
+ writeImpl(data, count);
+}
+
+
+void outputStream::write(const char* const data, const size_t count)
+{
+ writeImpl(reinterpret_cast <const byte_t*>(data), count);
+}
+
+
} // utility
} // vmime
diff --git a/src/utility/outputStreamAdapter.cpp b/src/utility/outputStreamAdapter.cpp
index 54e983e7..ed90c7d3 100644
--- a/src/utility/outputStreamAdapter.cpp
+++ b/src/utility/outputStreamAdapter.cpp
@@ -34,11 +34,11 @@ outputStreamAdapter::outputStreamAdapter(std::ostream& os)
}
-void outputStreamAdapter::write
- (const value_type* const data, const size_type count)
+void outputStreamAdapter::writeImpl
+ (const byte_t* const data, const size_t count)
{
m_stream.exceptions(std::ios_base::badbit);
- m_stream.write(data, count);
+ m_stream.write(reinterpret_cast <const char*>(data), count);
}
diff --git a/src/utility/outputStreamByteArrayAdapter.cpp b/src/utility/outputStreamByteArrayAdapter.cpp
index 48c0ca0c..1bed735b 100644
--- a/src/utility/outputStreamByteArrayAdapter.cpp
+++ b/src/utility/outputStreamByteArrayAdapter.cpp
@@ -34,7 +34,8 @@ outputStreamByteArrayAdapter::outputStreamByteArrayAdapter(byteArray& array)
}
-void outputStreamByteArrayAdapter::write(const value_type* const data, const size_type count)
+void outputStreamByteArrayAdapter::writeImpl
+ (const byte_t* const data, const size_t count)
{
m_array.insert(m_array.end(), data, data + count);
}
diff --git a/src/utility/outputStreamSocketAdapter.cpp b/src/utility/outputStreamSocketAdapter.cpp
index 222ffb0a..03194497 100644
--- a/src/utility/outputStreamSocketAdapter.cpp
+++ b/src/utility/outputStreamSocketAdapter.cpp
@@ -40,8 +40,8 @@ outputStreamSocketAdapter::outputStreamSocketAdapter(net::socket& sok)
}
-void outputStreamSocketAdapter::write
- (const value_type* const data, const size_type count)
+void outputStreamSocketAdapter::writeImpl
+ (const byte_t* const data, const size_t count)
{
m_socket.sendRaw(data, count);
}
@@ -53,7 +53,7 @@ void outputStreamSocketAdapter::flush()
}
-stream::size_type outputStreamSocketAdapter::getBlockSize()
+size_t outputStreamSocketAdapter::getBlockSize()
{
return m_socket.getBlockSize();
}
diff --git a/src/utility/outputStreamStringAdapter.cpp b/src/utility/outputStreamStringAdapter.cpp
index ee064202..7105480c 100644
--- a/src/utility/outputStreamStringAdapter.cpp
+++ b/src/utility/outputStreamStringAdapter.cpp
@@ -23,6 +23,8 @@
#include "vmime/utility/outputStreamStringAdapter.hpp"
+#include "vmime/utility/stringUtils.hpp"
+
namespace vmime {
namespace utility {
@@ -34,9 +36,10 @@ outputStreamStringAdapter::outputStreamStringAdapter(string& buffer)
}
-void outputStreamStringAdapter::write(const value_type* const data, const size_type count)
+void outputStreamStringAdapter::writeImpl
+ (const byte_t* const data, const size_t count)
{
- m_buffer.append(data, count);
+ vmime::utility::stringUtils::appendBytesToString(m_buffer, data, count);
}
diff --git a/src/utility/parserInputStreamAdapter.cpp b/src/utility/parserInputStreamAdapter.cpp
index fd10a586..5ab26ef0 100644
--- a/src/utility/parserInputStreamAdapter.cpp
+++ b/src/utility/parserInputStreamAdapter.cpp
@@ -46,8 +46,8 @@ void parserInputStreamAdapter::reset()
}
-stream::size_type parserInputStreamAdapter::read
- (value_type* const data, const size_type count)
+size_t parserInputStreamAdapter::read
+ (byte_t* const data, const size_t count)
{
return m_stream->read(data, count);
}
@@ -59,17 +59,19 @@ shared_ptr <seekableInputStream> parserInputStreamAdapter::getUnderlyingStream()
}
-const string parserInputStreamAdapter::extract(const size_type begin, const size_type end) const
+const string parserInputStreamAdapter::extract(const size_t begin, const size_t end) const
{
- const size_type initialPos = m_stream->getPosition();
+ const size_t initialPos = m_stream->getPosition();
+
+ byte_t *buffer = NULL;
try
{
- value_type *buffer = new value_type[end - begin + 1];
+ buffer = new byte_t[end - begin + 1];
m_stream->seek(begin);
- const size_type readBytes = m_stream->read(buffer, end - begin);
+ const size_t readBytes = m_stream->read(buffer, end - begin);
buffer[readBytes] = '\0';
m_stream->seek(initialPos);
@@ -81,14 +83,16 @@ const string parserInputStreamAdapter::extract(const size_type begin, const size
}
catch (...)
{
+ delete [] buffer;
+
m_stream->seek(initialPos);
throw;
}
}
-stream::size_type parserInputStreamAdapter::findNext
- (const string& token, const size_type startPosition)
+size_t parserInputStreamAdapter::findNext
+ (const string& token, const size_t startPosition)
{
static const unsigned int BUFFER_SIZE = 4096;
@@ -96,28 +100,28 @@ stream::size_type parserInputStreamAdapter::findNext
if (token.empty() || token.length() > BUFFER_SIZE / 2)
return npos;
- const size_type initialPos = getPosition();
+ const size_t initialPos = getPosition();
seek(startPosition);
try
{
- value_type findBuffer[BUFFER_SIZE];
- value_type* findBuffer1 = findBuffer;
- value_type* findBuffer2 = findBuffer + (BUFFER_SIZE / 2) * sizeof(value_type);
+ byte_t findBuffer[BUFFER_SIZE];
+ byte_t* findBuffer1 = findBuffer;
+ byte_t* findBuffer2 = findBuffer + (BUFFER_SIZE / 2);
- size_type findBufferLen = 0;
- size_type findBufferOffset = 0;
+ size_t findBufferLen = 0;
+ size_t findBufferOffset = 0;
bool isEOF = false;
// Fill in initial buffer
- findBufferLen = read(findBuffer, BUFFER_SIZE * sizeof(value_type));
+ findBufferLen = read(findBuffer, BUFFER_SIZE);
while (findBufferLen != 0)
{
// Find token
- for (value_type *begin = findBuffer, *end = findBuffer + findBufferLen - token.length() ;
+ for (byte_t *begin = findBuffer, *end = findBuffer + findBufferLen - token.length() ;
begin <= end ; ++begin)
{
if (begin[0] == token[0] &&
@@ -132,7 +136,7 @@ stream::size_type parserInputStreamAdapter::findNext
}
// Rotate buffer
- memcpy(findBuffer1, findBuffer2, (BUFFER_SIZE / 2) * sizeof(value_type));
+ memcpy(findBuffer1, findBuffer2, (BUFFER_SIZE / 2));
// Read more bytes
if (findBufferLen < BUFFER_SIZE && (eof() || isEOF))
@@ -141,7 +145,7 @@ stream::size_type parserInputStreamAdapter::findNext
}
else
{
- const size_type bytesRead = read(findBuffer2, (BUFFER_SIZE / 2) * sizeof(value_type));
+ const size_t bytesRead = read(findBuffer2, BUFFER_SIZE / 2);
if (bytesRead == 0)
{
diff --git a/src/utility/progressListener.cpp b/src/utility/progressListener.cpp
index 4d54174f..cef074e5 100644
--- a/src/utility/progressListener.cpp
+++ b/src/utility/progressListener.cpp
@@ -31,7 +31,7 @@ namespace utility {
// progressListenerSizeAdapter
progressListenerSizeAdapter::progressListenerSizeAdapter
- (progressListener* list, const long total)
+ (progressListener* list, const size_t total)
: m_wrapped(list), m_total(total)
{
}
@@ -43,14 +43,14 @@ bool progressListenerSizeAdapter::cancel() const
}
-void progressListenerSizeAdapter::start(const long predictedTotal)
+void progressListenerSizeAdapter::start(const size_t predictedTotal)
{
if (m_wrapped)
m_wrapped->start(predictedTotal);
}
-void progressListenerSizeAdapter::progress(const long current, const long currentTotal)
+void progressListenerSizeAdapter::progress(const size_t current, const size_t currentTotal)
{
if (m_wrapped)
{
@@ -62,7 +62,7 @@ void progressListenerSizeAdapter::progress(const long current, const long curren
}
-void progressListenerSizeAdapter::stop(const long total)
+void progressListenerSizeAdapter::stop(const size_t total)
{
if (m_wrapped)
{
diff --git a/src/utility/random.cpp b/src/utility/random.cpp
index 40b27b57..97d12ddc 100644
--- a/src/utility/random.cpp
+++ b/src/utility/random.cpp
@@ -66,13 +66,13 @@ unsigned int random::getProcess()
}
-const string random::getString(const string::size_type length, const string& randomChars)
+const string random::getString(const size_t length, const string& randomChars)
{
string res;
res.resize(length);
const unsigned int x = static_cast <unsigned int>(randomChars.length());
- string::size_type c = 0;
+ size_t c = 0;
while (c < length)
{
diff --git a/src/utility/seekableInputStreamRegionAdapter.cpp b/src/utility/seekableInputStreamRegionAdapter.cpp
index 753d81a5..cede1ba9 100644
--- a/src/utility/seekableInputStreamRegionAdapter.cpp
+++ b/src/utility/seekableInputStreamRegionAdapter.cpp
@@ -29,7 +29,7 @@ namespace utility {
seekableInputStreamRegionAdapter::seekableInputStreamRegionAdapter
- (shared_ptr <seekableInputStream> stream, const size_type begin, const size_type length)
+ (shared_ptr <seekableInputStream> stream, const size_t begin, const size_t length)
: m_stream(stream), m_begin(begin), m_length(length), m_position(0)
{
}
@@ -47,16 +47,16 @@ void seekableInputStreamRegionAdapter::reset()
}
-stream::size_type seekableInputStreamRegionAdapter::read
- (value_type* const data, const size_type count)
+size_t seekableInputStreamRegionAdapter::read
+ (byte_t* const data, const size_t count)
{
m_stream->seek(m_begin + m_position);
- size_type readBytes = 0;
+ size_t readBytes = 0;
if (m_position + count >= m_length)
{
- const size_type remaining = m_length - m_position;
+ const size_t remaining = m_length - m_position;
readBytes = m_stream->read(data, remaining);
}
else
@@ -70,11 +70,11 @@ stream::size_type seekableInputStreamRegionAdapter::read
}
-stream::size_type seekableInputStreamRegionAdapter::skip(const size_type count)
+size_t seekableInputStreamRegionAdapter::skip(const size_t count)
{
if (m_position + count >= m_length)
{
- const size_type remaining = m_length - m_position;
+ const size_t remaining = m_length - m_position;
m_position += remaining;
return remaining;
}
@@ -86,13 +86,13 @@ stream::size_type seekableInputStreamRegionAdapter::skip(const size_type count)
}
-stream::size_type seekableInputStreamRegionAdapter::getPosition() const
+size_t seekableInputStreamRegionAdapter::getPosition() const
{
return m_position;
}
-void seekableInputStreamRegionAdapter::seek(const size_type pos)
+void seekableInputStreamRegionAdapter::seek(const size_t pos)
{
if (pos > m_length)
m_position = m_length;
diff --git a/src/utility/stream.cpp b/src/utility/stream.cpp
index 3e7b5822..232b23c7 100644
--- a/src/utility/stream.cpp
+++ b/src/utility/stream.cpp
@@ -29,10 +29,7 @@ namespace vmime {
namespace utility {
-const stream::size_type stream::npos = static_cast <size_type>(vmime::string::npos);
-
-
-stream::size_type stream::getBlockSize()
+size_t stream::getBlockSize()
{
return 32768; // 32 KB
}
diff --git a/src/utility/streamUtils.cpp b/src/utility/streamUtils.cpp
index 06ea17a1..f3cc69ef 100644
--- a/src/utility/streamUtils.cpp
+++ b/src/utility/streamUtils.cpp
@@ -32,7 +32,7 @@ namespace vmime {
namespace utility {
-outputStream& operator<<(outputStream& os, const stream::value_type c)
+outputStream& operator<<(outputStream& os, const byte_t c)
{
os.write(&c, 1);
return (os);
@@ -46,29 +46,29 @@ outputStream& operator<<(outputStream& os, const string& str)
}
-stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os)
+size_t bufferedStreamCopy(inputStream& is, outputStream& os)
{
return bufferedStreamCopy(is, os, 0, NULL);
}
-stream::size_type bufferedStreamCopyRange(inputStream& is, outputStream& os,
- const stream::size_type start, const stream::size_type length)
+size_t bufferedStreamCopyRange(inputStream& is, outputStream& os,
+ const size_t start, const size_t length)
{
- const stream::size_type blockSize =
+ const size_t blockSize =
std::min(is.getBlockSize(), os.getBlockSize());
is.skip(start);
- std::vector <stream::value_type> vbuffer(blockSize);
+ std::vector <byte_t> vbuffer(blockSize);
- stream::value_type* buffer = &vbuffer.front();
- stream::size_type total = 0;
+ byte_t* buffer = &vbuffer.front();
+ size_t total = 0;
while (!is.eof() && total < length)
{
- const stream::size_type remaining = std::min(length - total, blockSize);
- const stream::size_type read = is.read(buffer, remaining);
+ const size_t remaining = std::min(length - total, blockSize);
+ const size_t read = is.read(buffer, remaining);
if (read != 0)
{
@@ -81,23 +81,23 @@ stream::size_type bufferedStreamCopyRange(inputStream& is, outputStream& os,
}
-stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
- const stream::size_type length, progressListener* progress)
+size_t bufferedStreamCopy(inputStream& is, outputStream& os,
+ const size_t length, progressListener* progress)
{
- const stream::size_type blockSize =
+ const size_t blockSize =
std::min(is.getBlockSize(), os.getBlockSize());
- std::vector <stream::value_type> vbuffer(blockSize);
+ std::vector <byte_t> vbuffer(blockSize);
- stream::value_type* buffer = &vbuffer.front();
- stream::size_type total = 0;
+ byte_t* buffer = &vbuffer.front();
+ size_t total = 0;
if (progress != NULL)
progress->start(length);
while (!is.eof())
{
- const stream::size_type read = is.read(buffer, blockSize);
+ const size_t read = is.read(buffer, blockSize);
if (read != 0)
{
diff --git a/src/utility/stringProxy.cpp b/src/utility/stringProxy.cpp
index 3320affb..67c96816 100644
--- a/src/utility/stringProxy.cpp
+++ b/src/utility/stringProxy.cpp
@@ -45,19 +45,19 @@ stringProxy::stringProxy(const stringProxy& s)
}
-stringProxy::stringProxy(const string_type& s, const size_type start, const size_type end)
+stringProxy::stringProxy(const string& s, const size_t start, const size_t end)
: m_buffer(s), m_start(start),
- m_end(end == std::numeric_limits <size_type>::max() ? s.length() : end)
+ m_end(end == std::numeric_limits <size_t>::max() ? s.length() : end)
{
}
-void stringProxy::set(const string_type& s, const size_type start, const size_type end)
+void stringProxy::set(const string& s, const size_t start, const size_t end)
{
m_buffer = s;
m_start = start;
- if (end == std::numeric_limits <size_type>::max())
+ if (end == std::numeric_limits <size_t>::max())
m_end = s.length();
else
m_end = end;
@@ -81,7 +81,7 @@ stringProxy& stringProxy::operator=(const stringProxy& s)
}
-stringProxy& stringProxy::operator=(const string_type& s)
+stringProxy& stringProxy::operator=(const string& s)
{
m_buffer = s;
m_start = 0;
@@ -91,12 +91,12 @@ stringProxy& stringProxy::operator=(const string_type& s)
}
-void stringProxy::extract(outputStream& os, const size_type start, const size_type end,
+void stringProxy::extract(outputStream& os, const size_t start, const size_t end,
utility::progressListener* progress) const
{
- size_type len = 0;
+ size_t len = 0;
- if (end == std::numeric_limits <size_type>::max())
+ if (end == std::numeric_limits <size_t>::max())
len = m_end - start - m_start;
else if (end > start)
len = end - start;
@@ -114,19 +114,19 @@ void stringProxy::extract(outputStream& os, const size_type start, const size_ty
}
-stringProxy::size_type stringProxy::length() const
+size_t stringProxy::length() const
{
return (m_end - m_start);
}
-stringProxy::size_type stringProxy::start() const
+size_t stringProxy::start() const
{
return (m_start);
}
-stringProxy::size_type stringProxy::end() const
+size_t stringProxy::end() const
{
return (m_end);
}
diff --git a/src/utility/stringUtils.cpp b/src/utility/stringUtils.cpp
index 8e5f7205..dd99d845 100644
--- a/src/utility/stringUtils.cpp
+++ b/src/utility/stringUtils.cpp
@@ -30,7 +30,7 @@ namespace utility {
bool stringUtils::isStringEqualNoCase
- (const string& s1, const char* s2, const string::size_type n)
+ (const string& s1, const char* s2, const size_t n)
{
// 'n' is the number of characters to compare
// 's2' must be in lowercase letters only
@@ -42,7 +42,7 @@ bool stringUtils::isStringEqualNoCase
bool equal = true;
- for (string::size_type i = 0 ; equal && i < n ; ++i)
+ for (size_t i = 0 ; equal && i < n ; ++i)
equal = (fac.tolower(static_cast <unsigned char>(s1[i])) == s2[i]);
return (equal);
@@ -69,9 +69,9 @@ bool stringUtils::isStringEqualNoCase(const string& s1, const string& s2)
bool stringUtils::isStringEqualNoCase
(const string::const_iterator begin, const string::const_iterator end,
- const char* s, const string::size_type n)
+ const char* s, const size_t n)
{
- if (static_cast <string::size_type>(end - begin) < n)
+ if (static_cast <size_t>(end - begin) < n)
return (false);
const std::ctype <char>& fac =
@@ -79,7 +79,7 @@ bool stringUtils::isStringEqualNoCase
bool equal = true;
char* c = const_cast<char*>(s);
- string::size_type r = n;
+ size_t r = n;
for (string::const_iterator i = begin ; equal && r && *c ; ++i, ++c, --r)
equal = (fac.tolower(static_cast <unsigned char>(*i)) == static_cast <unsigned char>(*c));
@@ -96,7 +96,7 @@ const string stringUtils::toLower(const string& str)
string out;
out.resize(str.size());
- for (string::size_type i = 0, len = str.length() ; i < len ; ++i)
+ for (size_t i = 0, len = str.length() ; i < len ; ++i)
out[i] = fac.tolower(static_cast <unsigned char>(str[i]));
return out;
@@ -111,7 +111,7 @@ const string stringUtils::toUpper(const string& str)
string out;
out.resize(str.size());
- for (string::size_type i = 0, len = str.length() ; i < len ; ++i)
+ for (size_t i = 0, len = str.length() ; i < len ; ++i)
out[i] = fac.toupper(static_cast <unsigned char>(str[i]));
return out;
@@ -133,10 +133,10 @@ const string stringUtils::trim(const string& str)
}
-string::size_type stringUtils::countASCIIchars
+size_t stringUtils::countASCIIchars
(const string::const_iterator begin, const string::const_iterator end)
{
- string::size_type count = 0;
+ size_t count = 0;
for (string::const_iterator i = begin ; i != end ; ++i)
{
@@ -157,10 +157,10 @@ bool stringUtils::is7bit(const string& str)
}
-string::size_type stringUtils::findFirstNonASCIIchar
+size_t stringUtils::findFirstNonASCIIchar
(const string::const_iterator begin, const string::const_iterator end)
{
- string::size_type pos = string::npos;
+ size_t pos = string::npos;
for (string::const_iterator i = begin ; i != end ; ++i)
{
@@ -190,7 +190,7 @@ const string stringUtils::unquote(const string& str)
for (string::const_iterator it = str.begin() + 1, end = str.end() - 1 ; it != end ; ++it)
{
- const string::value_type c = *it;
+ const char c = *it;
if (escaped)
{
@@ -221,7 +221,7 @@ string stringUtils::quote
(const string& str, const string& escapeSpecialChars, const string& escapeChar)
{
std::ostringstream oss;
- string::size_type lastPos = 0, pos = 0;
+ size_t lastPos = 0, pos = 0;
while ((pos = str.find_first_of(escapeSpecialChars, lastPos)) != string::npos)
{
diff --git a/src/utility/url.cpp b/src/utility/url.cpp
index f9157d64..ce0dc39a 100644
--- a/src/utility/url.cpp
+++ b/src/utility/url.cpp
@@ -157,17 +157,17 @@ const string url::build() const
void url::parse(const string& str)
{
// Protocol
- const string::size_type protoEnd = str.find("://");
+ const size_t protoEnd = str.find("://");
if (protoEnd == string::npos) throw exceptions::malformed_url("No protocol separator");
const string proto =
utility::stringUtils::toLower(string(str.begin(), str.begin() + protoEnd));
// Username/password
- string::size_type slashPos = str.find('/', protoEnd + 3);
+ size_t slashPos = str.find('/', protoEnd + 3);
if (slashPos == string::npos) slashPos = str.length();
- string::size_type atPos = str.rfind('@', slashPos);
+ size_t atPos = str.rfind('@', slashPos);
string hostPart;
string username;
@@ -183,7 +183,7 @@ void url::parse(const string& str)
if (atPos != string::npos && atPos < slashPos)
{
const string userPart(str.begin() + protoEnd + 3, str.begin() + atPos);
- const string::size_type colonPos = userPart.find(':');
+ const size_t colonPos = userPart.find(':');
if (colonPos == string::npos)
{
@@ -204,7 +204,7 @@ void url::parse(const string& str)
}
// Host/port
- const string::size_type colonPos = hostPart.find(':');
+ const size_t colonPos = hostPart.find(':');
string host;
string port;
@@ -223,7 +223,7 @@ void url::parse(const string& str)
string path = utility::stringUtils::trim(string(str.begin() + slashPos, str.end()));
string params;
- string::size_type paramSep = path.find_first_of('?');
+ size_t paramSep = path.find_first_of('?');
if (paramSep != string::npos)
{
@@ -268,16 +268,16 @@ void url::parse(const string& str)
if (!params.empty())
{
- string::size_type pos = 0;
+ size_t pos = 0;
do
{
- const string::size_type start = pos;
+ const size_t start = pos;
pos = params.find_first_of('&', pos);
- const string::size_type equal = params.find_first_of('=', start);
- const string::size_type end =
+ const size_t equal = params.find_first_of('=', start);
+ const size_t end =
(pos == string::npos ? params.length() : pos);
string name;
diff --git a/src/utility/urlUtils.cpp b/src/utility/urlUtils.cpp
index 3a6836b7..20818764 100644
--- a/src/utility/urlUtils.cpp
+++ b/src/utility/urlUtils.cpp
@@ -40,7 +40,7 @@ const string urlUtils::encode(const string& s)
for (string::const_iterator it = s.begin() ; it != s.end() ; ++it)
{
- const string::value_type c = *it;
+ const char c = *it;
if (parserHelpers::isPrint(c) && !parserHelpers::isSpace(c) &&
static_cast <unsigned char>(c) <= 127 &&
@@ -73,7 +73,7 @@ const string urlUtils::decode(const string& s)
for (string::const_iterator it = s.begin() ; it != s.end() ; )
{
- const string::value_type c = *it;
+ const char c = *it;
switch (c)
{
@@ -114,7 +114,7 @@ const string urlUtils::decode(const string& s)
}
}
- result += static_cast <string::value_type>(r);
+ result += static_cast <char>(r);
break;
}
default: