MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / Encode

Method Encode

src/tripwire/mailmessage.cpp:322–377  ·  view source on GitHub ↗

TODO:BAM -- line breaks TODO:BAM -- ToEncoding( const std::string& sIn, int maxLineLen = -1, int maxLen = -1 )

Source from the content-addressed store, hash-verified

320// TODO:BAM -- line breaks
321// TODO:BAM -- ToEncoding( const std::string& sIn, int maxLineLen = -1, int maxLen = -1 )
322std::string cQuotedPrintableEncoding::Encode(const std::string& sIn, int maxLineLen, int maxLen)
323{
324 static const size_t _CHAR_AS_HEX_LEN = 2;
325 static const size_t _ENCODED_CHAR_LEN = _CHAR_AS_HEX_LEN + sizeof('=');
326
327 std::string sOut;
328 sOut.resize(sIn.size() * _ENCODED_CHAR_LEN); // optimize. one char can turn into 3
329
330 std::string::const_iterator at;
331 std::string::size_type i = 0;
332 std::string::size_type lineLen = 0;
333 for (at = sIn.begin(); at != sIn.end(); ++at, lineLen += _ENCODED_CHAR_LEN)
334 {
335 if (NeedsEncoding(*at))
336 {
337 ASSERT((unsigned char)*at <= 0xFF);
338
339 std::string sTmp = EncodeChar(*at);
340 ASSERT(sTmp.length() == _CHAR_AS_HEX_LEN);
341
342 sOut[i++] = '=';
343
344 std::copy(&sTmp[0], &sTmp[_CHAR_AS_HEX_LEN], &sOut[i]);
345 ASSERT(_CHAR_AS_HEX_LEN > 0);
346 i += _CHAR_AS_HEX_LEN;
347 }
348 else
349 {
350 sOut[i++] = *at;
351 }
352
353 //
354 // if string is too long, just quit
355 //
356 if (maxLen != -1 && i >= maxLen - _ENCODED_CHAR_LEN)
357 {
358 break;
359 }
360
361 //
362 // check line len
363 //
364 if (maxLineLen != -1 && lineLen >= maxLineLen - _ENCODED_CHAR_LEN)
365 {
366 // append EOL
367 sOut[i++] = '=';
368 sOut[i++] = '\r';
369 sOut[i++] = '\n';
370 lineLen = 0;
371 }
372 }
373
374 sOut.resize(i);
375
376 return sOut;
377}
378
379std::string cMailMessageUtil::CreateEncodedText(const std::string& text)

Callers 9

util_EncodeFunction · 0.45
util_EncodeFunction · 0.45
yylexMethod · 0.45
MailMessageMethod · 0.45
SendMethod · 0.45
CreateEncodedTextMethod · 0.45
OutputStringFunction · 0.45
util_TestUnprintableFunction · 0.45
TestQuoteAndBackSlashFunction · 0.45

Calls 7

NeedsEncodingFunction · 0.85
EncodeCharFunction · 0.85
beginMethod · 0.80
endMethod · 0.80
resizeMethod · 0.45
sizeMethod · 0.45
lengthMethod · 0.45

Tested by 1

TestQuoteAndBackSlashFunction · 0.36