MCPcopy Create free account
hub / github.com/creatale/node-dv / reformatPacked64

Function reformatPacked64

deps/leptonica/src/encoding.c:586–649  ·  view source on GitHub ↗

-------------------------------------------------------------* * String reformatting for base 64 encoded data * *-------------------------------------------------------------*/ ! * \brief reformatPacked64() * * \param[in] inarray base64 encoded string with newlines * \param[in] insize number of bytes in input array * \param[in] leadspace number of spaces in each li

Source from the content-addressed store, hash-verified

584 * </pre>
585 */
586char *
587reformatPacked64(char *inarray,
588 l_int32 insize,
589 l_int32 leadspace,
590 l_int32 linechars,
591 l_int32 addquotes,
592 l_int32 *poutsize)
593{
594char *flata, *outa;
595l_int32 i, j, flatindex, flatsize, outindex, nlines, linewithpad, linecount;
596
597 PROCNAME("reformatPacked64");
598
599 if (!poutsize)
600 return (char *)ERROR_PTR("&outsize not defined", procName, NULL);
601 *poutsize = 0;
602 if (!inarray)
603 return (char *)ERROR_PTR("inarray not defined", procName, NULL);
604 if (insize <= 0)
605 return (char *)ERROR_PTR("insize not > 0", procName, NULL);
606 if (leadspace < 0)
607 return (char *)ERROR_PTR("leadspace must be >= 0", procName, NULL);
608 if (linechars % 4)
609 return (char *)ERROR_PTR("linechars % 4 must be 0", procName, NULL);
610
611 /* Remove all white space */
612 if ((flata = (char *)LEPT_CALLOC(insize, sizeof(char))) == NULL)
613 return (char *)ERROR_PTR("flata not made", procName, NULL);
614 for (i = 0, flatindex = 0; i < insize; i++) {
615 if (isBase64(inarray[i]) || inarray[i] == '=')
616 flata[flatindex++] = inarray[i];
617 }
618
619 /* Generate output string */
620 flatsize = flatindex;
621 nlines = (flatsize + linechars - 1) / linechars;
622 linewithpad = leadspace + linechars + 1; /* including newline */
623 if (addquotes) linewithpad += 2;
624 if ((outa = (char *)LEPT_CALLOC(nlines * linewithpad, sizeof(char)))
625 == NULL) {
626 LEPT_FREE(flata);
627 return (char *)ERROR_PTR("outa not made", procName, NULL);
628 }
629 for (j = 0, outindex = 0; j < leadspace; j++)
630 outa[outindex++] = ' ';
631 if (addquotes) outa[outindex++] = '"';
632 for (i = 0, linecount = 0; i < flatsize; i++) {
633 if (linecount == linechars) {
634 if (addquotes) outa[outindex++] = '"';
635 outa[outindex++] = '\n';
636 for (j = 0; j < leadspace; j++)
637 outa[outindex++] = ' ';
638 if (addquotes) outa[outindex++] = '"';
639 linecount = 0;
640 }
641 outa[outindex++] = flata[i];
642 linecount++;
643 }

Callers 1

l_genDataStringFunction · 0.85

Calls 1

isBase64Function · 0.85

Tested by

no test coverage detected