use bool instead of WSBool in strreplace default tip

Tue, 03 Feb 2026 19:09:53 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 03 Feb 2026 19:09:53 +0100
changeset 661
a4e1ba59b733
parent 660
f00d03835dd9

use bool instead of WSBool in strreplace

src/server/daemon/rewrite.c file | annotate | diff | comparison | revisions
src/server/test/strreplace.c file | annotate | diff | comparison | revisions
src/server/util/strreplace.c file | annotate | diff | comparison | revisions
src/server/util/strreplace.h file | annotate | diff | comparison | revisions
--- a/src/server/daemon/rewrite.c	Tue Jan 13 18:09:20 2026 +0100
+++ b/src/server/daemon/rewrite.c	Tue Feb 03 19:09:53 2026 +0100
@@ -66,7 +66,7 @@
         const CxAllocator *a,
         StringTemplateSegment *seg,
         RVar *vardata,
-        WSBool *free_str)
+        bool *free_str)
 {
     if(seg->type != STRING_SEGMENT_NUM_PLACEHOLDER || seg->num < 0 || seg->num >= vardata->nmatch) {
         return (cxmutstr){NULL, 0};
--- a/src/server/test/strreplace.c	Tue Jan 13 18:09:20 2026 +0100
+++ b/src/server/test/strreplace.c	Tue Feb 03 19:09:53 2026 +0100
@@ -201,9 +201,9 @@
     // TODO
 }
 
-static cxmutstr get_var(const CxAllocator *a, StringTemplateSegment *seg, void *userdata, WSBool *free_str) {
+static cxmutstr get_var(const CxAllocator *a, StringTemplateSegment *seg, void *userdata, bool *free_str) {
     cxmutstr var_value = cx_strcat_a(a, CX_NULLSTR, 3, cx_str("var("), seg->str, cx_str(")"));
-    *free_str = TRUE;
+    *free_str = true;
     return var_value;
 }
 
--- a/src/server/util/strreplace.c	Tue Jan 13 18:09:20 2026 +0100
+++ b/src/server/util/strreplace.c	Tue Feb 03 19:09:53 2026 +0100
@@ -30,6 +30,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <ctype.h>
 
 #include <cx/buffer.h>
@@ -38,8 +39,8 @@
 
 StringTemplate* string_template_compile(const CxAllocator *a, cxstring tpl) {
     StringTemplateSegment *end = NULL; // segment list end
-    int var = FALSE;
-    int error = FALSE;
+    int var = false;
+    int error = false;
     
     CxBuffer buf; // tmp buffer
     if(cxBufferInit(&buf, NULL, NULL, 128, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS)) {
@@ -58,8 +59,8 @@
     
     for(size_t i=0;i<tpl.length;i++) {
         char c = tpl.ptr[i];
-        int add_char = FALSE; // add current char to the buffer
-        int finish_seg = FALSE; // copy buffer to segment string and start new segment
+        int add_char = false; // add current char to the buffer
+        int finish_seg = false; // copy buffer to segment string and start new segment
         
         if(!seg) {
             // start new segment
@@ -77,7 +78,7 @@
                 }
                 end = seg;
             } else {
-                error = TRUE;
+                error = true;
                 break;
             }
         }
@@ -85,48 +86,48 @@
         if(var) {
             // current segment is a var
             if(c == '}') {
-                var = FALSE;
-                finish_seg = TRUE;
+                var = false;
+                finish_seg = true;
             } else if(c == '{') {
                 // noop
             } else if(!isalnum(c)) {
-                var = FALSE;
-                finish_seg = TRUE;
+                var = false;
+                finish_seg = true;
                 i--;
             } else {
-                add_char = TRUE;
+                add_char = true;
             }
         } else {
             if(c == '$') {
                 if(i+1<tpl.length && tpl.ptr[i+1] == '$') {
                     // $$ -> $
                     i++;
-                    add_char = TRUE;
+                    add_char = true;
                 } else {
-                    var = TRUE;
+                    var = true;
                     if(buf.pos == 0) {
                         // reuse current segment
                         seg->type = STRING_SEGMENT_VAR_PLACEHOLDER;
                     } else {
                         // create new segment
-                        finish_seg = TRUE;
+                        finish_seg = true;
                     }
                 }
             } else {
-                add_char = TRUE;
+                add_char = true;
             }
         }
         
         if(add_char) {
             if(cxBufferPut(&buf, c) != c) {
-                error = TRUE;
+                error = true;
                 break;
             }
         } else if(finish_seg) {
             // copy buffer content
             cxmutstr seg_str = cx_strdup_a(a, cx_strn(buf.space, buf.pos));
             if(!seg_str.ptr) {
-                error = TRUE;
+                error = true;
                 break;
             }
             seg->str = seg_str;
@@ -145,7 +146,7 @@
     if(seg) {
         cxmutstr seg_str = cx_strdup_a(a, cx_strn(buf.space, buf.pos));
         if(!seg_str.ptr) {
-            error = TRUE;
+            error = true;
         } else {
             seg->str = seg_str;
             if(seg->type == STRING_SEGMENT_VAR_PLACEHOLDER) {
@@ -196,7 +197,7 @@
             }
         } else if(varfunc) {
             // convert var segment to value
-            WSBool free_str = FALSE;
+            bool free_str = false;
             cxmutstr str = varfunc(a, seg, userdata, &free_str);
             if(str.length > 0) {
                 size_t r = writef(str.ptr, 1, str.length, stream);
--- a/src/server/util/strreplace.h	Tue Jan 13 18:09:20 2026 +0100
+++ b/src/server/util/strreplace.h	Tue Feb 03 19:09:53 2026 +0100
@@ -29,8 +29,7 @@
 #ifndef STRINGREPLACE_H
 #define STRINGREPLACE_H
 
-#include "../public/nsapi.h"
-
+#include <stdbool.h>
 #include <cx/string.h>
 #include <cx/buffer.h>
 
@@ -94,7 +93,7 @@
  * free_str: If set to true, the returned string pointer will be freed
  *           using the allocator's free function.
  */
-typedef cxmutstr (*strtpl_var_func)(const CxAllocator *a, StringTemplateSegment *seg, void *userdata, WSBool *free_str);
+typedef cxmutstr (*strtpl_var_func)(const CxAllocator *a, StringTemplateSegment *seg, void *userdata, bool *free_str);
 
 /*
  * Compiles a string template

mercurial