src/c2html.c

changeset 88
15fe9c1d7f1a
parent 86
c41ab60fd27a
--- a/src/c2html.c	Sat Feb 15 23:21:29 2025 +0100
+++ b/src/c2html.c	Sat Feb 15 23:26:08 2025 +0100
@@ -99,16 +99,28 @@
         c2html_highlighter_func highlighter,
         int showln
 ) {
+    size_t insize = strlen(inputbuffer);
+    return c2html_bformat(inputbuffer, insize,
+        outbuf, wfnc, highlighter, showln);
+}
+
+size_t c2html_bformat(
+        char const *inbuf,
+        size_t insize,
+        void *outbuf,
+        cx_write_func wfnc,
+        c2html_highlighter_func highlighter,
+        int showln
+) {
     /* a rough estimate for the number of lines */
-    size_t inputbuflen = strlen(inputbuffer);
-    size_t est_cap = 16 + inputbuflen / 40;
+    size_t est_cap = 16 + insize / 40;
 
     /* create the line pointer array */
     CxList *lines = cxArrayListCreateSimple(CX_STORE_POINTERS, est_cap);
-    cxListAdd(lines, inputbuffer);
-    for (size_t i = 0; i < inputbuflen; i++) {
-        if (inputbuffer[i] == '\n' && i + 1 < inputbuflen) {
-            cxListAdd(lines, inputbuffer + i + 1);
+    cxListAdd(lines, inbuf);
+    for (size_t i = 0; i < insize; i++) {
+        if (inbuf[i] == '\n' && i + 1 < insize) {
+            cxListAdd(lines, inbuf + i + 1);
         }
     }
 

mercurial