DCL 4.0
Loading...
Searching...
No Matches
QuotedPrintableEncoder Class Reference

#include <TransferEncoding.h>

Static Public Member Functions

static ByteString encode (const ByteString &_str)

Detailed Description

Definition at line 24 of file TransferEncoding.h.

Member Function Documentation

◆ encode()

ByteString QuotedPrintableEncoder::encode ( const ByteString & _str)
static

Definition at line 32 of file TransferEncoding.cpp.

33{
34 __DCL_ASSERT(_str.length() > 0);
35
36 static const char aHex[] = "0123456789ABCDEF";
37 const byte_t* src = (const byte_t*)_str.data();
38 size_t len = _str.length();
39
40 ByteBuffer* buf = ByteBuffer::create(
41 3 * len + (6 * len) / MAX_LINE_LENGTH + 3);
42 byte_t* dest = (byte_t*) buf->data();
43 int lineCount = 0;
44 while(len--)
45 {
46 byte_t c = *src++;
47 if ((c == CR) && (*src == LF) && len)
48 {
49 // hard line break
50 *dest++ = CR;
51 *dest++ = *src++;
52 len--;
53 lineCount = 0; // reset line count
54 }
55 else
56 { // not hard line break
57 if (//iscntrl(c)
58// ((0x00 <= c) && (c <= 0x1f)) // 0x00 ~ 0x1f
59 (c <= 0x1f)
60 || (c == 0x7f)
61 || (c & 0x80) // 0x80 ~
62 || (c == '=')
63 || ((c == ' ') && (*src == CR)))
64 {
65 // quoting required
66 if ((lineCount + 3) > MAX_LINE_LENGTH)
67 {
68 // soft line break
69 *dest++ = '=';
70 *dest++ = CR;
71 *dest++ = LF;
72 lineCount = 0; // reset
73 }
74
75 *dest++ = '=';
76 *dest++ = aHex[c >> 4];
77 *dest++ = aHex[c & 0x0f];
78 lineCount += 3;
79 }
80 else
81 {
82 // ordinary character
83 if ((lineCount + 1) > MAX_LINE_LENGTH)
84 {
85 // soft line break
86 *dest++ = '=';
87 *dest++ = CR;
88 *dest++ = LF;
89 lineCount = 0; // reset
90 }
91
92 *dest++ = c;
93 lineCount++;
94 }
95 }
96 }
97 *dest = __T('\0');
98 __DCL_ASSERT(buf->data() <= (char*) dest);
99 buf->__dataLength = (char*) dest - buf->data();
100 __DCL_ASSERT(buf->__dataLength <= buf->__allocLength);
101
102 ByteString r = buf;
103 buf->release();
104 return r;
105}
unsigned char byte_t
Definition Config.h:274
#define LF
#define CR
#define __DCL_ASSERT(expr)
Definition Object.h:371
#define __T(str)
Definition Object.h:44
ByteString r
size_t len
ByteBuffer * buf
#define MAX_LINE_LENGTH

The documentation for this class was generated from the following files: