-------------------------------------------------------------------------*\ * Accumulate characters until we are sure about how to deal with them. * Once we are sure, output to the buffer, in the correct form. \*-------------------------------------------------------------------------*/
| 517 | * Once we are sure, output to the buffer, in the correct form. |
| 518 | \*-------------------------------------------------------------------------*/ |
| 519 | static size_t qpencode(UC c, UC *input, size_t size, |
| 520 | const char *marker, luaL_Buffer *buffer) |
| 521 | { |
| 522 | input[size++] = c; |
| 523 | /* deal with all characters we can have */ |
| 524 | while (size > 0) { |
| 525 | switch (qpclass[input[0]]) { |
| 526 | /* might be the CR of a CRLF sequence */ |
| 527 | case QP_CR: |
| 528 | if (size < 2) return size; |
| 529 | if (input[1] == '\n') { |
| 530 | luaL_addstring(buffer, marker); |
| 531 | return 0; |
| 532 | } else qpquote(input[0], buffer); |
| 533 | break; |
| 534 | /* might be a space and that has to be quoted if last in line */ |
| 535 | case QP_IF_LAST: |
| 536 | if (size < 3) return size; |
| 537 | /* if it is the last, quote it and we are done */ |
| 538 | if (input[1] == '\r' && input[2] == '\n') { |
| 539 | qpquote(input[0], buffer); |
| 540 | luaL_addstring(buffer, marker); |
| 541 | return 0; |
| 542 | } else luaL_addchar(buffer, input[0]); |
| 543 | break; |
| 544 | /* might have to be quoted always */ |
| 545 | case QP_QUOTED: |
| 546 | qpquote(input[0], buffer); |
| 547 | break; |
| 548 | /* might never have to be quoted */ |
| 549 | default: |
| 550 | luaL_addchar(buffer, input[0]); |
| 551 | break; |
| 552 | } |
| 553 | input[0] = input[1]; input[1] = input[2]; |
| 554 | size--; |
| 555 | } |
| 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | /*-------------------------------------------------------------------------*\ |
| 560 | * Deal with the final characters |
no test coverage detected