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

Function mime_global_qp

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

-------------------------------------------------------------------------*\ * Incrementally converts a string to quoted-printable * A, B = qp(C, D, marker) * Marker is the text to be used to replace CRLF sequences found in A. * A is the encoded version of the largest prefix of C .. D that * can be encoded without doubts. * B has the remaining bytes of C .. D, *without* encoding. \*----------------

Source from the content-addressed store, hash-verified

579* B has the remaining bytes of C .. D, *without* encoding.
580\*-------------------------------------------------------------------------*/
581static int mime_global_qp(lua_State *L)
582{
583 size_t asize = 0, isize = 0;
584 UC atom[3];
585 const UC *input = (const UC *) luaL_optlstring(L, 1, NULL, &isize);
586 const UC *last = input + isize;
587 const char *marker = luaL_optstring(L, 3, CRLF);
588 luaL_Buffer buffer;
589 /* end-of-input blackhole */
590 if (!input) {
591 lua_pushnil(L);
592 lua_pushnil(L);
593 return 2;
594 }
595 /* make sure we don't confuse buffer stuff with arguments */
596 lua_settop(L, 3);
597 /* process first part of input */
598 luaL_buffinit(L, &buffer);
599 while (input < last)
600 asize = qpencode(*input++, atom, asize, marker, &buffer);
601 input = (const UC *) luaL_optlstring(L, 2, NULL, &isize);
602 /* if second part is nil, we are done */
603 if (!input) {
604 asize = qppad(atom, asize, &buffer);
605 luaL_pushresult(&buffer);
606 if (!(*lua_tostring(L, -1))) lua_pushnil(L);
607 lua_pushnil(L);
608 return 2;
609 }
610 /* otherwise process rest of input */
611 last = input + isize;
612 while (input < last)
613 asize = qpencode(*input++, atom, asize, marker, &buffer);
614 luaL_pushresult(&buffer);
615 lua_pushlstring(L, (char *) atom, asize);
616 return 2;
617}
618
619/*-------------------------------------------------------------------------*\
620* Accumulate characters until we are sure about how to deal with them.

Callers

nothing calls this directly

Calls 8

luaL_optlstringFunction · 0.85
lua_pushnilFunction · 0.85
lua_settopFunction · 0.85
luaL_buffinitFunction · 0.85
qpencodeFunction · 0.85
qppadFunction · 0.85
luaL_pushresultFunction · 0.85
lua_pushlstringFunction · 0.85

Tested by

no test coverage detected