-------------------------------------------------------------------------*\ * Accumulate characters until we are sure about how to deal with them. * Once we are sure, output to the buffer, in the correct form. \*-------------------------------------------------------------------------*/
| 391 | * Once we are sure, output to the buffer, in the correct form. |
| 392 | \*-------------------------------------------------------------------------*/ |
| 393 | static size_t qpencode(UC c, UC *input, size_t size, |
| 394 | const char *marker, luaL_Buffer *buffer) |
| 395 | { |
| 396 | input[size++] = c; |
| 397 | /* deal with all characters we can have */ |
| 398 | while (size > 0) { |
| 399 | switch (qpclass[input[0]]) { |
| 400 | /* might be the CR of a CRLF sequence */ |
| 401 | case QP_CR: |
| 402 | if (size < 2) return size; |
| 403 | if (input[1] == '\n') { |
| 404 | luaL_addstring(buffer, marker); |
| 405 | return 0; |
| 406 | } else qpquote(input[0], buffer); |
| 407 | break; |
| 408 | /* might be a space and that has to be quoted if last in line */ |
| 409 | case QP_IF_LAST: |
| 410 | if (size < 3) return size; |
| 411 | /* if it is the last, quote it and we are done */ |
| 412 | if (input[1] == '\r' && input[2] == '\n') { |
| 413 | qpquote(input[0], buffer); |
| 414 | luaL_addstring(buffer, marker); |
| 415 | return 0; |
| 416 | } else luaL_addchar(buffer, input[0]); |
| 417 | break; |
| 418 | /* might have to be quoted always */ |
| 419 | case QP_QUOTED: |
| 420 | qpquote(input[0], buffer); |
| 421 | break; |
| 422 | /* might never have to be quoted */ |
| 423 | default: |
| 424 | luaL_addchar(buffer, input[0]); |
| 425 | break; |
| 426 | } |
| 427 | input[0] = input[1]; input[1] = input[2]; |
| 428 | size--; |
| 429 | } |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | /*-------------------------------------------------------------------------*\ |
| 434 | * Deal with the final characters |
no test coverage detected