DCL 3.7.4
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 33 of file TransferEncoding.cpp.

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

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