- Timestamp:
- May 8, 2020 1:05:56 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/base64.cpp
r82968 r84210 83 83 static const char g_szValToChar[64+1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 84 84 85 /** The end-of-line lengths (indexed by style flag value). */ 86 static const size_t g_acchEolStyles[RTBASE64_FLAGS_EOL_STYLE_MASK + 1] = 87 { 88 /*[RTBASE64_FLAGS_EOL_NATIVE ]:*/ RTBASE64_EOL_SIZE, 89 /*[RTBASE64_FLAGS_NO_LINE_BREAKS]:*/ 0, 90 /*[RTBASE64_FLAGS_EOL_LF ]:*/ 1, 91 /*[RTBASE64_FLAGS_EOL_CRLF ]:*/ 2 92 }; 93 94 /** The end-of-line characters (zero, one or two). */ 95 static const char g_aachEolStyles[RTBASE64_FLAGS_EOL_STYLE_MASK + 1][2] = 96 { 97 /*[RTBASE64_FLAGS_EOL_NATIVE ]:*/ { RTBASE64_EOL_SIZE == 1 ? '\n' : '\n', RTBASE64_EOL_SIZE == 1 ? '\n' : '\0', }, 98 /*[RTBASE64_FLAGS_NO_LINE_BREAKS]:*/ { '\0', '\0' }, 99 /*[RTBASE64_FLAGS_EOL_LF ]:*/ { '\n', '\0' }, 100 /*[RTBASE64_FLAGS_EOL_CRLF ]:*/ { '\r', '\n' }, 101 }; 102 103 85 104 86 105 #ifdef RT_STRICT … … 421 440 RTDECL(size_t) RTBase64EncodedLengthEx(size_t cbData, uint32_t fFlags) 422 441 { 442 size_t const cchEol = g_acchEolStyles[fFlags & RTBASE64_FLAGS_EOL_STYLE_MASK]; 443 423 444 if (cbData * 8 / 8 != cbData) 424 445 { … … 428 449 cch += 8; 429 450 cch /= 6; 430 431 if ((fFlags & RTBASE64_FLAGS_NO_LINE_BREAKS) == 0) /* add EOLs? */ 432 cch += ((cch - 1) / RTBASE64_LINE_LEN) * RTBASE64_EOL_SIZE; 451 cch += ((cch - 1) / RTBASE64_LINE_LEN) * cchEol; 433 452 return cch; 434 453 } … … 438 457 cch += 8; 439 458 cch /= 6; 440 441 if ((fFlags & RTBASE64_FLAGS_NO_LINE_BREAKS) == 0) /* add EOLs? */ 442 cch += ((cch - 1) / RTBASE64_LINE_LEN) * RTBASE64_EOL_SIZE; 459 cch += ((cch - 1) / RTBASE64_LINE_LEN) * cchEol; 443 460 return cch; 444 461 } … … 486 503 char *pszBuf, size_t cbBuf, size_t *pcchActual) 487 504 { 505 /* Expand the EOL style flags: */ 506 size_t const cchEol = g_acchEolStyles[fFlags & RTBASE64_FLAGS_EOL_STYLE_MASK]; 507 char const chEol0 = g_aachEolStyles[fFlags & RTBASE64_FLAGS_EOL_STYLE_MASK][0]; 508 char const chEol1 = g_aachEolStyles[fFlags & RTBASE64_FLAGS_EOL_STYLE_MASK][1]; 509 488 510 /* 489 511 * Process whole "trios" of input data. … … 515 537 pbSrc += 3; 516 538 517 if ( (fFlags & RTBASE64_FLAGS_NO_LINE_BREAKS) == 0) /* add EOLs? */539 if (cchEol > 0) 518 540 { 519 541 /* deal out end-of-line */ 520 542 if (cbBuf == cbLineFeed && cbData) 521 543 { 522 if (cbBuf < RTBASE64_EOL_SIZE+ 1)544 if (cbBuf < cchEol + 1) 523 545 return VERR_BUFFER_OVERFLOW; 524 cbBuf -= RTBASE64_EOL_SIZE;525 if (RTBASE64_EOL_SIZE == 2)526 *pchDst++ = '\r';527 *pchDst++ = '\n';546 cbBuf -= cchEol; 547 *pchDst++ = chEol0; 548 if (chEol1) 549 *pchDst++ = chEol1; 528 550 cbLineFeed = cbBuf - RTBASE64_LINE_LEN; 529 551 }
Note:
See TracChangeset
for help on using the changeset viewer.