diff options
| author | Vincent Richard <[email protected]> | 2013-04-16 12:03:13 +0200 |
|---|---|---|
| committer | Vincent Richard <[email protected]> | 2013-04-16 12:03:13 +0200 |
| commit | 462311e382834bc893df9433b916f28ae9830090 (patch) | |
| tree | bd06919a108eeff55ef8e0a7031885fcb573b60c /src/utility | |
| parent | Issue #4: set envelope sender. (diff) | |
| download | vmime-462311e382834bc893df9433b916f28ae9830090.tar.gz vmime-462311e382834bc893df9433b916f28ae9830090.zip | |
Added filtered output stream to transform LFs to CRLFs.
Diffstat (limited to 'src/utility')
| -rw-r--r-- | src/utility/filteredStream.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/utility/filteredStream.cpp b/src/utility/filteredStream.cpp index 9af7b32a..294a7a94 100644 --- a/src/utility/filteredStream.cpp +++ b/src/utility/filteredStream.cpp @@ -286,6 +286,77 @@ void CRLFToLFFilteredOutputStream::flush() } +// LFToCRLFFilteredOutputStream + +LFToCRLFFilteredOutputStream::LFToCRLFFilteredOutputStream(outputStream& os) + : m_stream(os), m_previousChar('\0') +{ +} + + +outputStream& LFToCRLFFilteredOutputStream::getNextOutputStream() +{ + return (m_stream); +} + + +void LFToCRLFFilteredOutputStream::write + (const value_type* const data, const size_type count) +{ + if (count == 0) + return; + + std::string buffer; + buffer.reserve(count); + + const value_type* pos = data; + const value_type* end = data + count; + + value_type previousChar = m_previousChar; + + while (pos < end) + { + switch (*pos) + { + case '\r': + + buffer.append(1, '\r'); + buffer.append(1, '\n'); + + break; + + case '\n': + + if (previousChar != '\r') + { + buffer.append(1, '\r'); + buffer.append(1, '\n'); + } + + break; + + default: + + buffer.append(1, *pos); + break; + } + + previousChar = *pos; + ++pos; + } + + m_stream.write(&buffer[0], buffer.length()); + + m_previousChar = previousChar; +} + + +void LFToCRLFFilteredOutputStream::flush() +{ + m_stream.flush(); +} + + // stopSequenceFilteredInputStream <1> template <> |
