MCPcopy Create free account
hub / github.com/Tencent/UnLua / qpdecode

Function qpdecode

Plugins/UnLuaExtensions/LuaSocket/Source/src/mime.cpp:623–648  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Accumulate characters until we are sure about how to deal with them. * Once we are sure, output the to the buffer, in the correct form. \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

621* Once we are sure, output the to the buffer, in the correct form.
622\*-------------------------------------------------------------------------*/
623static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
624 int d;
625 input[size++] = c;
626 /* deal with all characters we can deal */
627 switch (input[0]) {
628 /* if we have an escape character */
629 case '=':
630 if (size < 3) return size;
631 /* eliminate soft line break */
632 if (input[1] == '\r' && input[2] == '\n') return 0;
633 /* decode quoted representation */
634 c = qpunbase[input[1]]; d = qpunbase[input[2]];
635 /* if it is an invalid, do not decode */
636 if (c > 15 || d > 15) luaL_addlstring(buffer, (char *)input, 3);
637 else luaL_addchar(buffer, (char) ((c << 4) + d));
638 return 0;
639 case '\r':
640 if (size < 2) return size;
641 if (input[1] == '\n') luaL_addlstring(buffer, (char *)input, 2);
642 return 0;
643 default:
644 if (input[0] == '\t' || (input[0] > 31 && input[0] < 127))
645 luaL_addchar(buffer, input[0]);
646 return 0;
647 }
648}
649
650/*-------------------------------------------------------------------------*\
651* Incrementally decodes a string in quoted-printable

Callers 1

mime_global_unqpFunction · 0.85

Calls 1

luaL_addlstringFunction · 0.85

Tested by

no test coverage detected