]> uap-core.de Git - note.git/commitdiff
implement note selection
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 23 Feb 2025 13:22:45 +0000 (14:22 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 23 Feb 2025 13:22:45 +0000 (14:22 +0100)
63 files changed:
application/Makefile
application/application.h
application/note.c [new file with mode: 0644]
application/note.h [new file with mode: 0644]
application/notebook.c
application/notebook.h
application/types.c
application/types.h
application/window.c
application/window.h
configure
libidav/config.c
libidav/davqlexec.c
libidav/methods.c
libidav/pwdstore.c
libidav/resource.c
libidav/session.c
libidav/utils.c
libidav/webdav.c
make/project.xml
ucx/allocator.c
ucx/array_list.c
ucx/buffer.c
ucx/cx/allocator.h
ucx/cx/array_list.h
ucx/cx/buffer.h
ucx/cx/collection.h
ucx/cx/common.h
ucx/cx/compare.h
ucx/cx/hash_key.h
ucx/cx/hash_map.h
ucx/cx/iterator.h
ucx/cx/json.h
ucx/cx/linked_list.h
ucx/cx/list.h
ucx/cx/map.h
ucx/cx/mempool.h
ucx/cx/printf.h
ucx/cx/properties.h
ucx/cx/streams.h
ucx/cx/string.h
ucx/cx/tree.h
ucx/hash_map.c
ucx/json.c
ucx/linked_list.c
ucx/list.c
ucx/map.c
ucx/properties.c
ucx/string.c
ucx/tree.c
ucx/utils.c [deleted file]
ui/cocoa/window.m
ui/common/context.c
ui/common/document.c
ui/common/types.c
ui/common/ucx_properties.c
ui/gtk/container.c
ui/gtk/webview.c
ui/gtk/webview.h
ui/gtk/window.c
ui/motif/window.c
ui/ui/webview.h
ui/winui/window.cpp

index 2df7deb86e9f6bef9d6167f07a1378b2ac35d8c5..63a742b2eba8ef6a000b651585bee77b4d35f019 100644 (file)
@@ -39,6 +39,7 @@ SRC += types.c
 SRC += store.c
 SRC += store_sqlite.c
 SRC += notebook.c
+SRC += note.c
 
 OBJ = $(SRC:%.c=../build/application/%.$(OBJ_EXT))
        
index e2889a8f994951d9010f80d44f5d1f31a5d59ef4..895b7868ae2d3792d8742ab0e01b10084ffc0a3c 100644 (file)
@@ -40,8 +40,7 @@ extern "C" {
 
 #define APP_STATE_NOTE_SELECTED 100
  
-    
-typedef struct NotebookModel NotebookModel;
+// typedefs for NotebookModel and NoteModel are in types.h
     
 typedef struct MainWindow {
     UiObject *obj;
@@ -91,11 +90,25 @@ struct NotebookModel {
      */
     UiList *notes;
     
+    /*
+     * currently attached note
+     */
+    Note *current_note;
+    
     /*
      * The mempool used to allocate the current list of notes
      */
     CxMempool *current_notes_pool;
 };
+
+struct NoteModel {
+    UiContext *ctx;
+    
+    UiInteger *type;
+    UiString *title;
+    UiText *text;
+    UiGeneric *html;
+};
    
 
 void application_init();
diff --git a/application/note.c b/application/note.c
new file mode 100644 (file)
index 0000000..7ac8e4f
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "note.h"
+
+NoteModel* notemodel_create() {
+    NoteModel *model = ui_document_new(sizeof(NoteModel));
+    model->ctx = ui_document_context(model);
+    
+    model->type = ui_int_new(model->ctx, "note_type");
+    model->title = ui_string_new(model->ctx, "note_title");
+    model->text = ui_text_new(model->ctx, "note_text");
+    model->html = ui_generic_new(model->ctx, "note_html");
+    
+    ui_set(model->type, 1);
+    //ui_set_group(model->ctx, APP_STATE_NOTE_SELECTED);
+    
+    return model;
+}
+
+void notemodel_set_note(NoteModel *model, Note *note) {
+    note->model = model;
+    
+    ui_set(model->title, note->title);
+    
+    if(note->content_loaded) {
+        // TODO: when multiple note types are implemented, chec contenttype
+        //       and set model->text, model->html or something else
+        if(!note->contenttype) {
+            ui_set(model->text, note->content.ptr);
+        }
+    }
+}
diff --git a/application/note.h b/application/note.h
new file mode 100644 (file)
index 0000000..a5beafb
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NOTE_H
+#define NOTE_H
+
+#include "application.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+NoteModel* notemodel_create();
+void notemodel_set_note(NoteModel *model, Note *note);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* NOTE_H */
+
index 9863a24586aa82708d6f54097da81d95e2630771..50d3a9df1eb0e8ba1d6a7fb9525cee3e0121f4f1 100644 (file)
@@ -29,6 +29,7 @@
 #include "notebook.h"
 
 #include "store.h"
+#include "note.h"
 
 NotebookModel* notebookmodel_create() {
     NotebookModel *model = ui_document_new(sizeof(NotebookModel));
@@ -80,3 +81,33 @@ static void notebook_loaded(UiEvent *event, AsyncListResult *result, void *data)
 void notebookmodel_reload(UiObject *obj, NotebookModel *model) {
     note_store_get_notes_async(obj, model->collection_id, notebook_loaded, model);
 }
+
+
+void notebookmodel_attach_note(NotebookModel *model, Note *note) {
+    if(model->current_note == note) {
+        return; // NOOP
+    }
+    
+    if(note && !note->model) {
+        NoteModel *notemodel = notemodel_create();
+        notemodel_set_note(notemodel, note);
+    }
+    
+    notebookmodel_detach_current_note(model);
+    ui_attach_document(model->window->obj->ctx, note->model);
+    // TODO: this is only a workaround and should be removed when
+    //       sub-document groups are supported
+    ui_set_group(model->window->obj->ctx, APP_STATE_NOTE_SELECTED);
+    model->current_note = note;
+    
+    if(!note->content_loaded) {
+        // TODO: load content
+    }
+}
+
+void notebookmodel_detach_current_note(NotebookModel *model) {
+    if(model->current_note && model->current_note->model) {
+        ui_detach_document2(model->window->obj->ctx, model->current_note->model);
+        model->current_note = NULL;
+    }
+}
index 4d9a5d4d535c9ba2fecbf04fb0fd729ca30b5417..084d909ed7c9fcd07a1747ea7669ca50584c73f1 100644 (file)
@@ -46,6 +46,9 @@ void notebookmodel_set_collection(NotebookModel *model, Collection *collection);
 
 void notebookmodel_reload(UiObject *obj, NotebookModel *model);
 
+void notebookmodel_attach_note(NotebookModel *model, Note *note);
+void notebookmodel_detach_current_note(NotebookModel *model);
+
 
 #ifdef __cplusplus
 }
index 3d3cd8698b2905948e9334d6f254cc421d404a7c..23d1273f5c3527cd6cd4fb5d968fdf979cebf5fb 100644 (file)
@@ -68,4 +68,5 @@ void register_types() {
     dbuClassAdd(notes_class, Note, content);
     dbuClassAdd(notes_class, Note, bin_content);
     dbuClassAdd(notes_class, Note, created_by);
+    dbuClassAdd(notes_class, Note, content_loaded);
 }
\ No newline at end of file
index 48e064a13bc07be11e681ebf6c54a1ad5d48bd3f..ad4ea21945958999449c4e7f213de8ff4b24b222 100644 (file)
 #ifdef __cplusplus
 extern "C" {
 #endif
+    
+    
+typedef struct NotebookModel NotebookModel;
+typedef struct NoteModel     NoteModel;
+    
 
 typedef struct UserSettings UserSettings;
 typedef struct Repository   Repository;
@@ -84,6 +89,18 @@ struct Note {
     cxmutstr   content;
     cxmutstr   bin_content;
     char       *created_by;
+    
+    /*
+     * indicates, whether content or bin_content was queried
+     * content_loaded is not a column in the Notes table, however it can be
+     * included in a Notes query result
+     */
+    bool       content_loaded;
+    
+    /*
+     * non-db member, UI model
+     */
+    NoteModel  *model;
 };
 
 extern DBUClass *usersettings_class;
index 8b1bdc57b5718768753b9217006e0bffc5bd8c4f..c1870747ba61d1b6475ef6648f6cdb4f9b126cc9 100644 (file)
@@ -57,15 +57,23 @@ void window_create() {
         UiModel* model = ui_model(obj->ctx, UI_STRING, "Name", UI_STRING_FREE, "Last Modified", -1);
         model->columnsize[0] = -1;
         model->getvalue = window_notelist_getvalue;
-        ui_table(obj, .model = model, .varname = "notes",);
+        ui_table(obj, .model = model, .varname = "notes", .onactivate = action_note_selected);
         
         // splitpane right: content
-        ui_grid(obj, .columnspacing = 10, .rowspacing = 10, .def_vfill = TRUE) {
-            ui_label(obj, .label = "Title", .vfill = TRUE);
-            ui_textfield(obj, .varname = "note_title", .hexpand = TRUE, .groups = UI_GROUPS(APP_STATE_NOTE_SELECTED));
-            ui_newline(obj);
-            
-            ui_textarea(obj, .varname = "note_content", .vfill = TRUE, .hfill = TRUE, .hexpand = TRUE, .vexpand = TRUE, .colspan = 2, .groups = UI_GROUPS(APP_STATE_NOTE_SELECTED));
+        ui_tabview(obj, .tabview = UI_TABVIEW_INVISIBLE, .varname = "note_type") {
+            ui_tab(obj, "empty") {
+                
+            }
+            ui_tab(obj, "textnote") {
+                ui_vbox0(obj) {
+                    ui_grid(obj, .margin = 10, .columnspacing = 10, .rowspacing = 10, .def_vfill = TRUE, .fill = UI_OFF) {
+                        ui_label(obj, .label = "Title", .vfill = TRUE);
+                        ui_textfield(obj, .varname = "note_title", .hexpand = TRUE, .groups = UI_GROUPS(APP_STATE_NOTE_SELECTED));
+                        ui_newline(obj);
+                    }
+                    ui_textarea(obj, .varname = "note_content", .vfill = TRUE, .hfill = TRUE, .hexpand = TRUE, .vexpand = TRUE, .colspan = 2, .groups = UI_GROUPS(APP_STATE_NOTE_SELECTED), .fill = UI_ON);
+                } 
+            }
         }
     }
     
@@ -190,3 +198,20 @@ void action_notebook_selected(UiEvent *event, void *userdata) {
     }
     notebookmodel_attach(window, notebook);
 }
+
+void action_note_selected(UiEvent *event, void *userdata) {
+    UiListSelection *sel = event->eventdata;
+    MainWindow *window = event->window;
+    NotebookModel *notebook = window->current_notebook;
+    
+    if(!notebook) {
+        return; // should not happen
+    }
+    
+    if(sel->count == 0) {
+        return; // should not happen
+    }
+    
+    Note *note = ui_list_get(notebook->notes, sel->rows[0]);
+    notebookmodel_attach_note(notebook, note);
+}
index cd6ae982394d86ceb7a859534585ddd81120c230..bf9b2155e0fe5fb6d13ee7a78510f86ee5b56055 100644 (file)
@@ -47,6 +47,7 @@ void update_sublists(UiContext *ctx, UiList *sublists);
 void* window_notelist_getvalue(void *data, int col);
 
 void action_notebook_selected(UiEvent *event, void *userdata);
+void action_note_selected(UiEvent *event, void *userdata);
 
 
 #ifdef __cplusplus
index 27e4652a55f9b873916ccc47d771c5703a80e96e..27c5b605a9577f31eeeeab12e5ad322f576d21c9 100755 (executable)
--- a/configure
+++ b/configure
@@ -273,32 +273,6 @@ print_check_msg()
     fi
 }
 
-dependency_error_gtk2legacy()
-{
-    print_check_msg "$dep_checked_gtk2legacy" "checking for gtk2legacy... "
-    # dependency gtk2legacy
-    while true
-    do
-        if [ -z "$PKG_CONFIG" ]; then
-            break
-        fi
-        if test_pkg_config "gtk+-2.0" "" "" "" ; then
-            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags gtk+-2.0`"
-            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs gtk+-2.0`"
-        else
-            break
-        fi
-        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_GTK2 -DUI_GTK2LEGACY"
-        TEMP_LDFLAGS="$TEMP_LDFLAGS -lpthread"
-        print_check_msg "$dep_checked_gtk2legacy" "yes\n"
-        dep_checked_gtk2legacy=1
-        return 1
-    done
-
-    print_check_msg "$dep_checked_gtk2legacy" "no\n"
-    dep_checked_gtk2legacy=1
-    return 0
-}
 dependency_error_curl()
 {
     print_check_msg "$dep_checked_curl" "checking for curl... "
@@ -427,9 +401,9 @@ dependency_error_gtk3()
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if test_pkg_config "gtk+-3.0" "" "" "" ; then
-            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags gtk+-3.0`"
-            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs gtk+-3.0`"
+        if test_pkg_config "gtk3" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags gtk3`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs gtk3`"
         else
             break
         fi
@@ -470,123 +444,37 @@ dependency_error_gtk4()
     dep_checked_gtk4=1
     return 0
 }
-dependency_error_openssl()
-{
-    print_check_msg "$dep_checked_openssl" "checking for openssl... "
-    # dependency openssl platform="windows"
-    while true
-    do
-        if notisplatform "windows"; then
-            break
-        fi
-        TEMP_LDFLAGS="$TEMP_LDFLAGS -lssl -lcrypto"
-        print_check_msg "$dep_checked_openssl" "yes\n"
-        dep_checked_openssl=1
-        return 1
-    done
-
-    # dependency openssl platform="macos"
-    while true
-    do
-        if notisplatform "macos"; then
-            break
-        fi
-        TEMP_LDFLAGS="$TEMP_LDFLAGS -framework CoreFoundation"
-        print_check_msg "$dep_checked_openssl" "yes\n"
-        dep_checked_openssl=1
-        return 1
-    done
-
-    # dependency openssl platform="bsd"
-    while true
-    do
-        if notisplatform "bsd"; then
-            break
-        fi
-        if isplatform "macos" || istoolchain "macos"; then
-            break
-        fi
-        TEMP_LDFLAGS="$TEMP_LDFLAGS -lssl -lcrypto"
-        print_check_msg "$dep_checked_openssl" "yes\n"
-        dep_checked_openssl=1
-        return 1
-    done
-
-    # dependency openssl
-    while true
-    do
-        if [ -z "$PKG_CONFIG" ]; then
-            break
-        fi
-        if test_pkg_config "openssl" "" "" "" ; then
-            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags openssl`"
-            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs openssl`"
-        else
-            break
-        fi
-        print_check_msg "$dep_checked_openssl" "yes\n"
-        dep_checked_openssl=1
-        return 1
-    done
-
-    print_check_msg "$dep_checked_openssl" "no\n"
-    dep_checked_openssl=1
-    return 0
-}
-dependency_error_libadwaita()
+dependency_error_webkitgtk6()
 {
-    print_check_msg "$dep_checked_libadwaita" "checking for libadwaita... "
-    # dependency libadwaita
+    print_check_msg "$dep_checked_webkitgtk6" "checking for webkitgtk6... "
+    # dependency webkitgtk6
     while true
     do
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if test_pkg_config "libadwaita-1" "" "" "" ; then
-            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libadwaita-1`"
-            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libadwaita-1`"
+        if test_pkg_config "webkitgtk-6.0" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags webkitgtk-6.0`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs webkitgtk-6.0`"
         else
             break
         fi
-        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_GTK4 -DUI_LIBADWAITA"
-        TEMP_LDFLAGS="$TEMP_LDFLAGS -lpthread"
-        print_check_msg "$dep_checked_libadwaita" "yes\n"
-        dep_checked_libadwaita=1
+        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_WEBVIEW"
+        print_check_msg "$dep_checked_webkitgtk6" "yes\n"
+        dep_checked_webkitgtk6=1
         return 1
     done
 
-    print_check_msg "$dep_checked_libadwaita" "no\n"
-    dep_checked_libadwaita=1
-    return 0
-}
-dependency_error_motif()
-{
-    print_check_msg "$dep_checked_motif" "checking for motif... "
-    # dependency motif platform="bsd"
+    # dependency webkitgtk6
     while true
     do
-        if notisplatform "bsd"; then
-            break
-        fi
-        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_MOTIF -I/usr/local/include/X11"
-        TEMP_LDFLAGS="$TEMP_LDFLAGS -lXm -lXt -lX11 -lpthread"
-        print_check_msg "$dep_checked_motif" "yes\n"
-        dep_checked_motif=1
+        print_check_msg "$dep_checked_webkitgtk6" "yes\n"
+        dep_checked_webkitgtk6=1
         return 1
     done
 
-    # dependency motif
-    while true
-    do
-        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_MOTIF"
-        TEMP_LDFLAGS="$TEMP_LDFLAGS -lXm -lXt -lX11 -lpthread"
-        print_check_msg "$dep_checked_motif" "yes\n"
-        dep_checked_motif=1
-        return 1
-    done
-
-    print_check_msg "$dep_checked_motif" "no\n"
-    dep_checked_motif=1
+    print_check_msg "$dep_checked_webkitgtk6" "no\n"
+    dep_checked_webkitgtk6=1
     return 0
 }
 dependency_error_libxml2()
@@ -673,6 +561,57 @@ dependency_error_libxml2()
     dep_checked_libxml2=1
     return 0
 }
+dependency_error_webkit2gtk4()
+{
+    print_check_msg "$dep_checked_webkit2gtk4" "checking for webkit2gtk4... "
+    # dependency webkit2gtk4
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "webkit2gtk-4.1" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags webkit2gtk-4.1`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs webkit2gtk-4.1`"
+        else
+            break
+        fi
+        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_WEBVIEW"
+        print_check_msg "$dep_checked_webkit2gtk4" "yes\n"
+        dep_checked_webkit2gtk4=1
+        return 1
+    done
+
+    # dependency webkit2gtk4
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "webkit2gtk-4.0" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags webkit2gtk-4.0`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs webkit2gtk-4.0`"
+        else
+            break
+        fi
+        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_WEBVIEW"
+        print_check_msg "$dep_checked_webkit2gtk4" "yes\n"
+        dep_checked_webkit2gtk4=1
+        return 1
+    done
+
+    # dependency webkit2gtk4
+    while true
+    do
+        print_check_msg "$dep_checked_webkit2gtk4" "yes\n"
+        dep_checked_webkit2gtk4=1
+        return 1
+    done
+
+    print_check_msg "$dep_checked_webkit2gtk4" "no\n"
+    dep_checked_webkit2gtk4=1
+    return 0
+}
 dependency_error_cocoa()
 {
     print_check_msg "$dep_checked_cocoa" "checking for cocoa... "
@@ -712,6 +651,151 @@ dependency_error_winui()
     dep_checked_winui=1
     return 0
 }
+dependency_error_gtk2legacy()
+{
+    print_check_msg "$dep_checked_gtk2legacy" "checking for gtk2legacy... "
+    # dependency gtk2legacy
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "gtk+-2.0" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags gtk+-2.0`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs gtk+-2.0`"
+        else
+            break
+        fi
+        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_GTK2 -DUI_GTK2LEGACY"
+        TEMP_LDFLAGS="$TEMP_LDFLAGS -lpthread"
+        print_check_msg "$dep_checked_gtk2legacy" "yes\n"
+        dep_checked_gtk2legacy=1
+        return 1
+    done
+
+    print_check_msg "$dep_checked_gtk2legacy" "no\n"
+    dep_checked_gtk2legacy=1
+    return 0
+}
+dependency_error_openssl()
+{
+    print_check_msg "$dep_checked_openssl" "checking for openssl... "
+    # dependency openssl platform="windows"
+    while true
+    do
+        if notisplatform "windows"; then
+            break
+        fi
+        TEMP_LDFLAGS="$TEMP_LDFLAGS -lssl -lcrypto"
+        print_check_msg "$dep_checked_openssl" "yes\n"
+        dep_checked_openssl=1
+        return 1
+    done
+
+    # dependency openssl platform="macos"
+    while true
+    do
+        if notisplatform "macos"; then
+            break
+        fi
+        TEMP_LDFLAGS="$TEMP_LDFLAGS -framework CoreFoundation"
+        print_check_msg "$dep_checked_openssl" "yes\n"
+        dep_checked_openssl=1
+        return 1
+    done
+
+    # dependency openssl platform="bsd"
+    while true
+    do
+        if notisplatform "bsd"; then
+            break
+        fi
+        if isplatform "macos" || istoolchain "macos"; then
+            break
+        fi
+        TEMP_LDFLAGS="$TEMP_LDFLAGS -lssl -lcrypto"
+        print_check_msg "$dep_checked_openssl" "yes\n"
+        dep_checked_openssl=1
+        return 1
+    done
+
+    # dependency openssl
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "openssl" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags openssl`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs openssl`"
+        else
+            break
+        fi
+        print_check_msg "$dep_checked_openssl" "yes\n"
+        dep_checked_openssl=1
+        return 1
+    done
+
+    print_check_msg "$dep_checked_openssl" "no\n"
+    dep_checked_openssl=1
+    return 0
+}
+dependency_error_libadwaita()
+{
+    print_check_msg "$dep_checked_libadwaita" "checking for libadwaita... "
+    # dependency libadwaita
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "libadwaita-1" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libadwaita-1`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libadwaita-1`"
+        else
+            break
+        fi
+        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_GTK4 -DUI_LIBADWAITA"
+        TEMP_LDFLAGS="$TEMP_LDFLAGS -lpthread"
+        print_check_msg "$dep_checked_libadwaita" "yes\n"
+        dep_checked_libadwaita=1
+        return 1
+    done
+
+    print_check_msg "$dep_checked_libadwaita" "no\n"
+    dep_checked_libadwaita=1
+    return 0
+}
+dependency_error_motif()
+{
+    print_check_msg "$dep_checked_motif" "checking for motif... "
+    # dependency motif platform="bsd"
+    while true
+    do
+        if notisplatform "bsd"; then
+            break
+        fi
+        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_MOTIF -I/usr/local/include/X11"
+        TEMP_LDFLAGS="$TEMP_LDFLAGS -lXm -lXt -lX11 -lpthread"
+        print_check_msg "$dep_checked_motif" "yes\n"
+        dep_checked_motif=1
+        return 1
+    done
+
+    # dependency motif
+    while true
+    do
+        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_MOTIF"
+        TEMP_LDFLAGS="$TEMP_LDFLAGS -lXm -lXt -lX11 -lpthread"
+        print_check_msg "$dep_checked_motif" "yes\n"
+        dep_checked_motif=1
+        return 1
+    done
+
+    print_check_msg "$dep_checked_motif" "no\n"
+    dep_checked_motif=1
+    return 0
+}
 
 # start collecting dependency information
 echo > "$TEMP_DIR/flags.mk"
@@ -808,6 +892,9 @@ checkopt_toolkit_libadwaita()
     if dependency_error_libadwaita ; then
         VERR=1
     fi
+    if dependency_error_webkitgtk6 ; then
+        VERR=1
+    fi
     if [ $VERR -ne 0 ]; then
         return 1
     fi
@@ -823,6 +910,9 @@ checkopt_toolkit_gtk4()
     if dependency_error_gtk4 ; then
         VERR=1
     fi
+    if dependency_error_webkitgtk6 ; then
+        VERR=1
+    fi
     if [ $VERR -ne 0 ]; then
         return 1
     fi
@@ -838,6 +928,9 @@ checkopt_toolkit_gtk3()
     if dependency_error_gtk3 ; then
         VERR=1
     fi
+    if dependency_error_webkit2gtk4 ; then
+        VERR=1
+    fi
     if [ $VERR -ne 0 ]; then
         return 1
     fi
index 7b0abbc62abb3564f073f50334ff4d17977d72d0..9c295bbe9de2e19291d8bbda2ed9ceae40bbf23f 100644 (file)
@@ -1002,7 +1002,7 @@ const char* dav_config_keytype_str(DavCfgKeyType type) {
 
 int dav_config_register_keys(DavConfig *config, DavContext *ctx, dav_loadkeyfile_func loadkey) {
     for(DavCfgKey *key=config->keys;key;key=key->next) {
-        char *file = cx_strdup_m(key->file.value).ptr;
+        char *file = cx_strdup_a(cxDefaultAllocator, key->file.value).ptr;
         cxmutstr keycontent = loadkey(file);
         free(file);
         
@@ -1013,7 +1013,7 @@ int dav_config_register_keys(DavConfig *config, DavContext *ctx, dav_loadkeyfile
         }
         
         DavKey *davkey = calloc(1, sizeof(DavKey));
-        davkey->name = cx_strdup_m(key->name.value).ptr;
+        davkey->name = cx_strdup_a(cxDefaultAllocator, key->name.value).ptr;
         davkey->type = dav_config_keytype(key->type);
         davkey->data = keycontent.ptr;
         davkey->length = keycontent.length;
index 4af5816cabf4611eb552e44007b8edbfdc072b3d..83cf7202eb55265af5ff1bea4cdd3f79a6a4badb 100644 (file)
@@ -302,9 +302,9 @@ static CxBuffer* fieldlist2propfindrequest(DavSession *sn, const CxAllocator *a,
         }
     }
     
-    i = cxMapIteratorValues(properties);
+    CxMapIterator mi = cxMapIteratorValues(properties);
     CxList *list = cxLinkedListCreateSimple(CX_STORE_POINTERS);
-    cx_foreach(DavProperty*, value, i) {
+    cx_foreach(DavProperty*, value, mi) {
         cxListAdd(list, value);
     }
     
@@ -464,7 +464,7 @@ static int reset_properties(DavSession *sn, DavResult *result, DavResource *res,
  * execute a davql select statement
  */
 DavResult dav_exec_select(DavSession *sn, DavQLStatement *st, va_list ap) {
-    CxMempool *mp = cxBasicMempoolCreate(128);
+    CxMempool *mp = cxMempoolCreateSimple(128);
     DavResult result;
     result.result = NULL;
     result.status = 1;
index a4fe63d2285e036cbe3058de79b9e43e480f2d18..7c425db900706578061a0825c9339ec17f71cf9e 100644 (file)
@@ -200,7 +200,7 @@ CxBuffer* create_propfind_request(DavSession *sn, CxList *properties, char *root
     // write root element and namespaces
     cx_bprintf(buf, "<D:%s xmlns:D=\"DAV:\"", rootelm);
     
-    CxIterator mapi = cxMapIteratorValues(namespaces);
+    CxMapIterator mapi = cxMapIteratorValues(namespaces);
     cx_foreach(DavNamespace*, ns, mapi) {
         s = CX_STR(" xmlns:");
         cxBufferWrite(s.ptr, 1, s.length, buf);
@@ -862,7 +862,7 @@ CxBuffer* create_proppatch_request(DavResourceData *data) {
     // write root element and namespaces
     s = CX_STR("<D:propertyupdate xmlns:D=\"DAV:\"");
     cxBufferWrite(s.ptr, 1, s.length, buf);
-    CxIterator mapi = cxMapIterator(namespaces);
+    CxMapIterator mapi = cxMapIterator(namespaces);
     cx_foreach(CxMapEntry*, entry, mapi) {
         s = CX_STR(" xmlns:");
         cxBufferWrite(s.ptr, 1, s.length, buf);
index 5832ddbd9041065f1e33457fd0f04f0bda163a04..ba97c09928d5cd92d03cce06efe74da18502619b 100644 (file)
@@ -137,7 +137,7 @@ PwdStore* pwdstore_clone(PwdStore *p) {
     newp->encoffset = p->encoffset;
     newp->isdecrypted = p->isdecrypted;
     
-    CxIterator i = cxMapIterator(p->ids);
+    CxMapIterator i = cxMapIterator(p->ids);
     cx_foreach(CxMapEntry *, e, i) {
         PwdEntry *entry = e->value;
         pwdstore_put(newp, entry->id, entry->user, entry->password);
@@ -489,8 +489,8 @@ int pwdstore_store(PwdStore *p, const char *file) {
         write_index_entry(index, e);
     }
     
-    i = cxMapIteratorValues(p->ids);
-    cx_foreach(PwdEntry*, value, i) {
+    CxMapIterator mi = cxMapIteratorValues(p->ids);
+    cx_foreach(PwdEntry*, value, mi) {
         if(!value->id || !value->user || !value->password) {
             continue;
         }
index 7808bc37282c48539be98b5ea103524125bf4f92..91efa901868fcbb01d5e815f3314bb7a7622f867 100644 (file)
@@ -126,7 +126,7 @@ DavResource* dav_resource_new_full(DavSession *sn, const char *parent_path, cons
 void resource_free_properties(DavSession *sn, CxMap *properties) {
     if(!properties) return;
     
-    CxIterator i = cxMapIteratorValues(properties);
+    CxMapIterator i = cxMapIteratorValues(properties);
     cx_foreach(DavProperty*, property, i) {
         // TODO: free everything
         dav_session_free(sn, property);
@@ -741,7 +741,7 @@ DavPropName* dav_get_property_names(DavResource *res, size_t *count) {
             sizeof(DavPropName));
     
     
-    CxIterator i = cxMapIteratorValues(data->properties);
+    CxMapIterator i = cxMapIteratorValues(data->properties);
     cx_foreach(DavProperty*, value, i) {
         DavPropName *name = &names[i.index];
         name->ns = value->ns->name;
@@ -1515,7 +1515,7 @@ DavXmlNode* create_crypto_prop(DavSession *sn, CxMap *properties) {
     cxBufferPutString(content, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
     cxBufferPutString(content, "<D:prop xmlns:D=\"DAV:\">\n");
     
-    CxIterator i = cxMapIteratorValues(properties);
+    CxMapIterator i = cxMapIteratorValues(properties);
     cx_foreach(DavProperty*, prop, i) {
         DavXmlNode pnode;
         pnode.type = DAV_XML_ELEMENT;
index 13ec76d722dbc0116c2a687789f3c2bf72ce1d27..e7b983f7aab8faa955e1fb4b792f0b2d6ed02aff 100644 (file)
@@ -49,7 +49,7 @@ DavSession* dav_session_new(DavContext *context, char *base_url) {
     }
     DavSession *sn = malloc(sizeof(DavSession));
     memset(sn, 0, sizeof(DavSession));
-    sn->mp = cxBasicMempoolCreate(DAV_SESSION_MEMPOOL_SIZE);
+    sn->mp = cxMempoolCreateSimple(DAV_SESSION_MEMPOOL_SIZE);
     sn->pathcache = cxHashMapCreate(sn->mp->allocator, CX_STORE_POINTERS, DAV_PATH_CACHE_SIZE);
     sn->key = NULL;
     sn->errorstr = NULL;
@@ -118,7 +118,7 @@ DavSession* dav_session_clone(DavSession *sn) {
 
     DavSession *newsn = malloc(sizeof(DavSession));
     memset(newsn, 0, sizeof(DavSession));
-    newsn->mp = cxBasicMempoolCreate(DAV_SESSION_MEMPOOL_SIZE);
+    newsn->mp = cxMempoolCreateSimple(DAV_SESSION_MEMPOOL_SIZE);
     newsn->pathcache = cxHashMapCreate(newsn->mp->allocator, CX_STORE_POINTERS, DAV_PATH_CACHE_SIZE);
     newsn->key = sn->key;
     newsn->errorstr = NULL;
index d1f3776b04b1bf0b89563cb9f398e2c5ad390a46..9b195e3337b290f3535506f3192271bf7d63c0d0 100644 (file)
@@ -385,7 +385,9 @@ static size_t util_header_callback(char *buffer, size_t size,
     value.ptr++; value.length--;
     
     cxmutstr key_cp = cx_strdup(cx_strtrim(key));
-    cx_strlower(key_cp);
+    for(int i=0;i<key_cp.length;i++) {
+        key_cp.ptr[i] = tolower(key_cp.ptr[i]);
+    }
     cxmutstr value_cp = cx_strdup(cx_strtrim(value));
         
     cxMapPut(map, cx_hash_key(key_cp.ptr, key_cp.length), value_cp.ptr);
index 97affd78f04e3aa96ecf9b4252d48c5a18b67875..262e15c532555b08b4dfb07dfb5c3920ea8aedfa 100644 (file)
@@ -112,7 +112,7 @@ void dav_context_destroy(DavContext *ctx) {
     }
     
     if(ctx->namespaces) {
-        CxIterator i = cxMapIteratorValues(ctx->namespaces);
+        CxMapIterator i = cxMapIteratorValues(ctx->namespaces);
         cx_foreach(DavNamespace*, ns, i) {
             if(!ns) continue;
             if(ns->prefix) {
@@ -129,7 +129,7 @@ void dav_context_destroy(DavContext *ctx) {
         // TODO: implement
     }
     if(ctx->keys) {
-        CxIterator i = cxMapIteratorValues(ctx->keys);
+        CxMapIterator i = cxMapIteratorValues(ctx->keys);
         cx_foreach(DavKey*, key, i) {
             if(!key) continue;
             if(key->name) {
index 606f29dd4b27ddb4bddae91f7c3311c0ef1f106e..24ca8443b92f6cb5bcc81110cc179e63ed187e3f 100644 (file)
@@ -61,7 +61,7 @@
                <ldflags>-lpthread</ldflags>
        </dependency>
        <dependency name="gtk3">
-               <pkgconfig>gtk+-3.0</pkgconfig>
+               <pkgconfig>gtk3</pkgconfig>
                <cflags>-DUI_GTK3</cflags>
                <ldflags>-lpthread</ldflags>
        </dependency>
                <cflags>-DUI_WINUI</cflags>
        </dependency>
        
+       <dependency name="webkitgtk6">
+               <pkgconfig>webkitgtk-6.0</pkgconfig>
+               <cflags>-DUI_WEBVIEW</cflags>
+       </dependency>
+       <dependency name="webkitgtk6">
+               <!-- webview unsupported -->
+       </dependency>
+       <dependency name="webkit2gtk4">
+               <pkgconfig>webkit2gtk-4.1</pkgconfig>
+               <cflags>-DUI_WEBVIEW</cflags>
+       </dependency>
+       <dependency name="webkit2gtk4">
+               <pkgconfig>webkit2gtk-4.0</pkgconfig>
+               <cflags>-DUI_WEBVIEW</cflags>
+       </dependency>
+       <dependency name="webkit2gtk4">
+               <!-- webview unsupported -->
+       </dependency>
+       
        <!--
        <dependency name="qt4">
                <test>which qmake-qt4</test>
        <target name="tk">
                <option arg="toolkit">
                        <value str="libadwaita">
-                               <dependencies>libadwaita</dependencies>
+                               <dependencies>libadwaita,webkitgtk6</dependencies>
                                <make>TOOLKIT = gtk</make>
                                <make>GTKOBJ = draw_cairo.o</make>
                        </value>
                        <value str="gtk4">
-                               <dependencies>gtk4</dependencies>
+                               <dependencies>gtk4,webkitgtk6</dependencies>
                                <make>TOOLKIT = gtk</make>
                                <make>GTKOBJ = draw_cairo.o</make>
                        </value>
                        <value str="gtk3">
-                               <dependencies>gtk3</dependencies>
+                               <dependencies>gtk3,webkit2gtk4</dependencies>
                                <make>TOOLKIT = gtk</make>
                                <make>GTKOBJ = draw_cairo.o</make>
                        </value>
index e3a967e555d6b8627b78f003fb0ed3f1315e050f..f6f20c85b4887606fd71b8675ba9f110727f80d1 100644 (file)
@@ -47,10 +47,10 @@ static void *cx_realloc_stdlib(
 
 static void *cx_calloc_stdlib(
         cx_attr_unused void *d,
-        size_t nelem,
-        size_t n
+        size_t nmemb,
+        size_t size
 ) {
-    return calloc(nelem, n);
+    return calloc(nmemb, size);
 }
 
 static void cx_free_stdlib(
@@ -71,10 +71,9 @@ struct cx_allocator_s cx_default_allocator = {
         &cx_default_allocator_class,
         NULL
 };
-CxAllocator *cxDefaultAllocator = &cx_default_allocator;
+const CxAllocator * const cxDefaultAllocator = &cx_default_allocator;
 
-#undef cx_reallocate
-int cx_reallocate(
+int cx_reallocate_(
         void **mem,
         size_t n
 ) {
@@ -87,8 +86,7 @@ int cx_reallocate(
     }
 }
 
-#undef cx_reallocatearray
-int cx_reallocatearray(
+int cx_reallocatearray_(
         void **mem,
         size_t nmemb,
         size_t size
@@ -140,8 +138,7 @@ void *cxReallocArray(
     }
 }
 
-#undef cxReallocate
-int cxReallocate(
+int cxReallocate_(
         const CxAllocator *allocator,
         void **mem,
         size_t n
@@ -155,8 +152,7 @@ int cxReallocate(
     }
 }
 
-#undef cxReallocateArray
-int cxReallocateArray(
+int cxReallocateArray_(
         const CxAllocator *allocator,
         void **mem,
         size_t nmemb,
@@ -173,10 +169,10 @@ int cxReallocateArray(
 
 void *cxCalloc(
         const CxAllocator *allocator,
-        size_t nelem,
-        size_t n
+        size_t nmemb,
+        size_t size
 ) {
-    return allocator->cl->calloc(allocator->data, nelem, n);
+    return allocator->cl->calloc(allocator->data, nmemb, size);
 }
 
 void cxFree(
index 96b514fb93764e9854e0393ddd0f685d91a8b470..5387bfb8f7cd7cc82aedc9a030e7d3a825af1006 100644 (file)
@@ -856,32 +856,42 @@ static void *cx_arl_at(
     }
 }
 
-static ssize_t cx_arl_find_remove(
+static size_t cx_arl_find_remove(
         struct cx_list_s *list,
         const void *elem,
         bool remove
 ) {
+    assert(list != NULL);
     assert(list->collection.cmpfunc != NULL);
-    assert(list->collection.size < SIZE_MAX / 2);
+    if (list->collection.size == 0) return 0;
     char *cur = ((const cx_array_list *) list)->data;
 
-    for (ssize_t i = 0; i < (ssize_t) list->collection.size; i++) {
+    // optimize with binary search, when sorted
+    if (list->collection.sorted) {
+        size_t i = cx_array_binary_search(
+            cur,
+            list->collection.size,
+            list->collection.elem_size,
+            elem,
+            list->collection.cmpfunc
+        );
+        if (remove && i < list->collection.size) {
+            cx_arl_remove(list, i, 1, NULL);
+        }
+        return i;
+    }
+
+    // fallback: linear search
+    for (size_t i = 0; i < list->collection.size; i++) {
         if (0 == list->collection.cmpfunc(elem, cur)) {
             if (remove) {
-                if (1 == cx_arl_remove(list, i, 1, NULL)) {
-                    return i;
-                } else {
-                    // should be unreachable
-                    return -1;  // LCOV_EXCL_LINE
-                }
-            } else {
-                return i;
+                cx_arl_remove(list, i, 1, NULL);
             }
+            return i;
         }
         cur += list->collection.elem_size;
     }
-
-    return -1;
+    return list->collection.size;
 }
 
 static void cx_arl_sort(struct cx_list_s *list) {
@@ -1013,22 +1023,13 @@ CxList *cxArrayListCreate(
 
     cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list));
     if (list == NULL) return NULL;
-
-    list->base.cl = &cx_array_list_class;
-    list->base.collection.allocator = allocator;
+    cx_list_init((CxList*)list, &cx_array_list_class,
+        allocator, comparator, elem_size);
     list->capacity = initial_capacity;
 
-    if (elem_size > 0) {
-        list->base.collection.elem_size = elem_size;
-        list->base.collection.cmpfunc = comparator;
-    } else {
-        elem_size = sizeof(void *);
-        list->base.collection.cmpfunc = comparator == NULL ? cx_cmp_ptr : comparator;
-        cxListStorePointers((CxList *) list);
-    }
-
     // allocate the array after the real elem_size is known
-    list->data = cxCalloc(allocator, initial_capacity, elem_size);
+    list->data = cxCalloc(allocator, initial_capacity,
+        list->base.collection.elem_size);
     if (list->data == NULL) { // LCOV_EXCL_START
         cxFree(allocator, list);
         return NULL;
index ec67feb4d4a1b788c6dafd1df8e42d81d6b80191..1a7713eec5b298f4bed8ef1ab69c54cf5234720a 100644 (file)
@@ -205,8 +205,8 @@ int cxBufferMinimumCapacity(
 
 static size_t cx_buffer_flush_helper(
         const CxBuffer *buffer,
-        size_t size,
         const unsigned char *src,
+        size_t size,
         size_t nitems
 ) {
     // flush data from an arbitrary source
@@ -236,7 +236,7 @@ static size_t cx_buffer_flush_impl(CxBuffer *buffer, size_t size) {
     unsigned char *space = buffer->bytes;
     size_t remaining = buffer->pos / size;
     size_t flushed_total = cx_buffer_flush_helper(
-        buffer, size, space, remaining);
+        buffer, space, size, remaining);
 
     // shift the buffer left after flushing
     // IMPORTANT: up to this point, copy on write must have been
@@ -268,17 +268,18 @@ size_t cxBufferWrite(
         return nitems;
     }
 
-    size_t len;
+    size_t len, total_flushed = 0;
+cx_buffer_write_retry:
     if (cx_szmul(size, nitems, &len)) {
         errno = EOVERFLOW;
-        return 0;
+        return total_flushed;
     }
     if (buffer->pos > SIZE_MAX - len) {
         errno = EOVERFLOW;
-        return 0;
+        return total_flushed;
     }
-    size_t required = buffer->pos + len;
 
+    size_t required = buffer->pos + len;
     bool perform_flush = false;
     if (required > buffer->capacity) {
         if (buffer->flags & CX_BUFFER_AUTO_EXTEND) {
@@ -286,7 +287,7 @@ size_t cxBufferWrite(
                 perform_flush = true;
             } else {
                 if (cxBufferMinimumCapacity(buffer, required)) {
-                    return 0; // LCOV_EXCL_LINE
+                    return total_flushed; // LCOV_EXCL_LINE
                 }
             }
         } else {
@@ -305,7 +306,7 @@ size_t cxBufferWrite(
 
     // check here and not above because of possible truncation
     if (len == 0) {
-        return 0;
+        return total_flushed;
     }
 
     // check if we need to copy
@@ -313,26 +314,43 @@ size_t cxBufferWrite(
 
     // perform the operation
     if (perform_flush) {
-        size_t items_flush;
+        size_t items_flushed;
         if (buffer->pos == 0) {
             // if we don't have data in the buffer, but are instructed
             // to flush, it means that we are supposed to relay the data
-            items_flush = cx_buffer_flush_helper(buffer, size, ptr, nitems);
-            if (items_flush == 0) {
-                // we needed to flush, but could not flush anything
-                // give up and avoid endless trying
+            items_flushed = cx_buffer_flush_helper(buffer, ptr, size, nitems);
+            if (items_flushed == 0) {
+                // we needed to relay data, but could not flush anything
+                // i.e. we have to give up to avoid endless trying
                 return 0;
             }
-            size_t ritems = nitems - items_flush;
-            const unsigned char *rest = ptr;
-            rest += items_flush * size;
-            return items_flush + cxBufferWrite(rest, size, ritems, buffer);
+            nitems -= items_flushed;
+            total_flushed += items_flushed;
+            if (nitems > 0) {
+                ptr = ((unsigned char*)ptr) + items_flushed * size;
+                goto cx_buffer_write_retry;
+            }
+            return total_flushed;
         } else {
-            items_flush = cx_buffer_flush_impl(buffer, size);
-            if (items_flush == 0) {
-                return 0;
+            items_flushed = cx_buffer_flush_impl(buffer, size);
+            if (items_flushed == 0) {
+                // flush target is full, let's try to truncate
+                size_t remaining_space;
+                if (buffer->flags & CX_BUFFER_AUTO_EXTEND) {
+                    remaining_space = buffer->flush->threshold > buffer->pos
+                                          ? buffer->flush->threshold - buffer->pos
+                                          : 0;
+                } else {
+                    remaining_space = buffer->capacity > buffer->pos
+                                          ? buffer->capacity - buffer->pos
+                                          : 0;
+                }
+                nitems = remaining_space / size;
+                if (nitems == 0) {
+                    return total_flushed;
+                }
             }
-            return cxBufferWrite(ptr, size, nitems, buffer);
+            goto cx_buffer_write_retry;
         }
     } else {
         memcpy(buffer->bytes + buffer->pos, ptr, len);
@@ -340,9 +358,8 @@ size_t cxBufferWrite(
         if (buffer->pos > buffer->size) {
             buffer->size = buffer->pos;
         }
-        return nitems;
+        return total_flushed + nitems;
     }
-
 }
 
 size_t cxBufferAppend(
@@ -352,9 +369,19 @@ size_t cxBufferAppend(
         CxBuffer *buffer
 ) {
     size_t pos = buffer->pos;
-    buffer->pos = buffer->size;
+    size_t append_pos = buffer->size;
+    buffer->pos = append_pos;    
     size_t written = cxBufferWrite(ptr, size, nitems, buffer);
-    buffer->pos = pos;
+    // the buffer might have been flushed
+    // we must compute a possible delta for the position
+    // expected: pos = append_pos + written
+    // -> if this is not the case, there is a delta
+    size_t delta = append_pos + written*size - buffer->pos;
+    if (delta > pos) {
+        buffer->pos = 0;
+    } else {
+        buffer->pos = pos - delta;
+    }
     return written;
 }
 
index ed6a31805dbf8d230b76a3e3f44587f909ae0076..8f16774326df5d0c50483a7fa30cd9eb870d9de6 100644 (file)
@@ -65,8 +65,8 @@ typedef struct {
      */
     void *(*calloc)(
             void *data,
-            size_t nelem,
-            size_t n
+            size_t nmemb,
+            size_t size
     );
 
     /**
@@ -100,7 +100,8 @@ typedef struct cx_allocator_s CxAllocator;
 /**
  * A default allocator using standard library malloc() etc.
  */
-extern CxAllocator *cxDefaultAllocator;
+cx_attr_export
+extern const CxAllocator * const cxDefaultAllocator;
 
 /**
  * Function pointer type for destructor functions.
@@ -131,7 +132,7 @@ typedef void (*cx_destructor_func2)(
 );
 
 /**
- * Re-allocate a previously allocated block and changes the pointer in-place,
+ * Reallocate a previously allocated block and changes the pointer in-place,
  * if necessary.
  *
  * @par Error handling
@@ -145,13 +146,14 @@ typedef void (*cx_destructor_func2)(
  */
 cx_attr_nonnull
 cx_attr_nodiscard
-int cx_reallocate(
+cx_attr_export
+int cx_reallocate_(
         void **mem,
         size_t n
 );
 
 /**
- * Re-allocate a previously allocated block and changes the pointer in-place,
+ * Reallocate a previously allocated block and changes the pointer in-place,
  * if necessary.
  *
  * The size is calculated by multiplying @p nemb and @p size.
@@ -169,14 +171,15 @@ int cx_reallocate(
  */
 cx_attr_nonnull
 cx_attr_nodiscard
-int cx_reallocatearray(
+cx_attr_export
+int cx_reallocatearray_(
         void **mem,
         size_t nmemb,
         size_t size
 );
 
 /**
- * Re-allocate a previously allocated block and changes the pointer in-place,
+ * Reallocate a previously allocated block and changes the pointer in-place,
  * if necessary.
  *
  * @par Error handling
@@ -188,10 +191,10 @@ int cx_reallocatearray(
  * @retval non-zero failure
  * @see cx_reallocatearray()
  */
-#define cx_reallocate(mem, n) cx_reallocate((void**)(mem), n)
+#define cx_reallocate(mem, n) cx_reallocate_((void**)(mem), n)
 
 /**
- * Re-allocate a previously allocated block and changes the pointer in-place,
+ * Reallocate a previously allocated block and changes the pointer in-place,
  * if necessary.
  *
  * The size is calculated by multiplying @p nemb and @p size.
@@ -207,7 +210,7 @@ int cx_reallocatearray(
  * @retval non-zero failure
  */
 #define cx_reallocatearray(mem, nmemb, size) \
-    cx_reallocatearray((void**)(mem), nmemb, size)
+    cx_reallocatearray_((void**)(mem), nmemb, size)
 
 /**
  * Free a block allocated by this allocator.
@@ -218,6 +221,7 @@ int cx_reallocatearray(
  * @param mem a pointer to the block to free
  */
 cx_attr_nonnull_arg(1)
+cx_attr_export
 void cxFree(
         const CxAllocator *allocator,
         void *mem
@@ -235,13 +239,14 @@ cx_attr_nonnull
 cx_attr_malloc
 cx_attr_dealloc_ucx
 cx_attr_allocsize(2)
+cx_attr_export
 void *cxMalloc(
         const CxAllocator *allocator,
         size_t n
 );
 
 /**
- * Re-allocate the previously allocated block in @p mem, making the new block
+ * Reallocate the previously allocated block in @p mem, making the new block
  * @p n bytes long.
  * This function may return the same pointer that was passed to it, if moving
  * the memory was not necessary.
@@ -251,12 +256,13 @@ void *cxMalloc(
  * @param allocator the allocator
  * @param mem pointer to the previously allocated block
  * @param n the new size in bytes
- * @return a pointer to the re-allocated memory
+ * @return a pointer to the reallocated memory
  */
 cx_attr_nodiscard
 cx_attr_nonnull_arg(1)
 cx_attr_dealloc_ucx
 cx_attr_allocsize(3)
+cx_attr_export
 void *cxRealloc(
         const CxAllocator *allocator,
         void *mem,
@@ -264,7 +270,7 @@ void *cxRealloc(
 );
 
 /**
- * Re-allocate the previously allocated block in @p mem, making the new block
+ * Reallocate the previously allocated block in @p mem, making the new block
  * @p n bytes long.
  * This function may return the same pointer that was passed to it, if moving
  * the memory was not necessary.
@@ -279,12 +285,13 @@ void *cxRealloc(
  * @param mem pointer to the previously allocated block
  * @param nmemb the number of elements
  * @param size the size of each element
- * @return a pointer to the re-allocated memory
+ * @return a pointer to the reallocated memory
  */
 cx_attr_nodiscard
 cx_attr_nonnull_arg(1)
 cx_attr_dealloc_ucx
 cx_attr_allocsize(3, 4)
+cx_attr_export
 void *cxReallocArray(
         const CxAllocator *allocator,
         void *mem,
@@ -293,7 +300,7 @@ void *cxReallocArray(
 );
 
 /**
- * Re-allocate a previously allocated block and changes the pointer in-place,
+ * Reallocate a previously allocated block and changes the pointer in-place,
  * if necessary.
  * This function acts like cxRealloc() using the pointer pointed to by @p mem.
  *
@@ -310,14 +317,15 @@ void *cxReallocArray(
  */
 cx_attr_nodiscard
 cx_attr_nonnull
-int cxReallocate(
+cx_attr_export
+int cxReallocate_(
         const CxAllocator *allocator,
         void **mem,
         size_t n
 );
 
 /**
- * Re-allocate a previously allocated block and changes the pointer in-place,
+ * Reallocate a previously allocated block and changes the pointer in-place,
  * if necessary.
  * This function acts like cxRealloc() using the pointer pointed to by @p mem.
  *
@@ -333,10 +341,10 @@ int cxReallocate(
  * @retval non-zero failure
  */
 #define cxReallocate(allocator, mem, n) \
-    cxReallocate(allocator, (void**)(mem), n)
+    cxReallocate_(allocator, (void**)(mem), n)
 
 /**
- * Re-allocate a previously allocated block and changes the pointer in-place,
+ * Reallocate a previously allocated block and changes the pointer in-place,
  * if necessary.
  * This function acts like cxReallocArray() using the pointer pointed to
  * by @p mem.
@@ -356,7 +364,8 @@ int cxReallocate(
  */
 cx_attr_nodiscard
 cx_attr_nonnull
-int cxReallocateArray(
+cx_attr_export
+int cxReallocateArray_(
         const CxAllocator *allocator,
         void **mem,
         size_t nmemb,
@@ -364,7 +373,7 @@ int cxReallocateArray(
 );
 
 /**
- * Re-allocate a previously allocated block and changes the pointer in-place,
+ * Reallocate a previously allocated block and changes the pointer in-place,
  * if necessary.
  * This function acts like cxReallocArray() using the pointer pointed to
  * by @p mem.
@@ -383,14 +392,14 @@ int cxReallocateArray(
  * @retval non-zero failure
  */
 #define cxReallocateArray(allocator, mem, nmemb, size) \
-        cxReallocateArray(allocator, (void**) (mem), nmemb, size)
+        cxReallocateArray_(allocator, (void**) (mem), nmemb, size)
 
 /**
- * Allocate @p nelem elements of @p n bytes each, all initialized to zero.
+ * Allocate @p nmemb elements of @p n bytes each, all initialized to zero.
  *
  * @param allocator the allocator
- * @param nelem the number of elements
- * @param n the size of each element in bytes
+ * @param nmemb the number of elements
+ * @param size the size of each element in bytes
  * @return a pointer to the allocated memory
  */
 cx_attr_nonnull_arg(1)
@@ -398,10 +407,11 @@ cx_attr_nodiscard
 cx_attr_malloc
 cx_attr_dealloc_ucx
 cx_attr_allocsize(2, 3)
+cx_attr_export
 void *cxCalloc(
         const CxAllocator *allocator,
-        size_t nelem,
-        size_t n
+        size_t nmemb,
+        size_t size
 );
 
 #ifdef __cplusplus
index a2b3d5981dd02f7cc4e6e85c5e2d560a1e97038b..198407f85ffe750a3e5d462bcedc9e7941b45902 100644 (file)
@@ -47,6 +47,7 @@ extern "C" {
  * The maximum item size in an array list that fits into stack buffer
  * when swapped.
  */
+cx_attr_export
 extern const unsigned cx_array_swap_sbo_size;
 
 /**
@@ -218,6 +219,7 @@ typedef struct cx_array_reallocator_s CxArrayReallocator;
 /**
  * A default stdlib-based array reallocator.
  */
+cx_attr_export
 extern CxArrayReallocator *cx_array_default_reallocator;
 
 /**
@@ -238,6 +240,7 @@ extern CxArrayReallocator *cx_array_default_reallocator;
  * on the stack or shall not reallocated in place
  * @return an array reallocator
  */
+cx_attr_export
 CxArrayReallocator cx_array_reallocator(
         const struct cx_allocator_s *allocator,
         const void *stackmem
@@ -274,6 +277,7 @@ CxArrayReallocator cx_array_reallocator(
  * @see cx_array_reallocator()
  */
 cx_attr_nonnull_arg(1, 2, 3)
+cx_attr_export
 int cx_array_reserve(
         void **array,
         void *size,
@@ -317,6 +321,7 @@ int cx_array_reserve(
  * @see cx_array_reallocator()
  */
 cx_attr_nonnull_arg(1, 2, 3, 6)
+cx_attr_export
 int cx_array_copy(
         void **target,
         void *size,
@@ -475,6 +480,7 @@ int cx_array_copy(
  * @retval non-zero failure
  */
 cx_attr_nonnull_arg(1, 2, 3, 5)
+cx_attr_export
 int cx_array_insert_sorted(
         void **target,
         size_t *size,
@@ -601,6 +607,7 @@ int cx_array_insert_sorted(
  * @see cx_array_binary_search()
  */
 cx_attr_nonnull
+cx_attr_export
 size_t cx_array_binary_search_inf(
         const void *arr,
         size_t size,
@@ -626,6 +633,7 @@ size_t cx_array_binary_search_inf(
  * @see cx_array_binary_search_sup()
  */
 cx_attr_nonnull
+cx_attr_export
 size_t cx_array_binary_search(
         const void *arr,
         size_t size,
@@ -657,6 +665,7 @@ size_t cx_array_binary_search(
  * @see cx_array_binary_search()
  */
 cx_attr_nonnull
+cx_attr_export
 size_t cx_array_binary_search_sup(
         const void *arr,
         size_t size,
@@ -674,6 +683,7 @@ size_t cx_array_binary_search_sup(
  * @param idx2 index of second element
  */
 cx_attr_nonnull
+cx_attr_export
 void cx_array_swap(
         void *arr,
         size_t elem_size,
@@ -684,9 +694,9 @@ void cx_array_swap(
 /**
  * Allocates an array list for storing elements with @p elem_size bytes each.
  *
- * If @p elem_size is CX_STORE_POINTERS, the created list will be created as if
- * cxListStorePointers() was called immediately after creation and the compare
- * function will be automatically set to cx_cmp_ptr(), if none is given.
+ * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of
+ * copies of the added elements and the compare function will be automatically set
+ * to cx_cmp_ptr(), if none is given.
  *
  * @param allocator the allocator for allocating the list memory
  * (if @c NULL, a default stdlib allocator will be used)
@@ -700,6 +710,7 @@ void cx_array_swap(
 cx_attr_nodiscard
 cx_attr_malloc
 cx_attr_dealloc(cxListFree, 1)
+cx_attr_export
 CxList *cxArrayListCreate(
         const CxAllocator *allocator,
         cx_compare_func comparator,
@@ -714,9 +725,9 @@ CxList *cxArrayListCreate(
  * If you want to call functions that need a compare function, you have to
  * set it immediately after creation or use cxArrayListCreate().
  *
- * If @p elem_size is CX_STORE_POINTERS, the created list will be created as if
- * cxListStorePointers() was called immediately after creation and the compare
- * function will be automatically set to cx_cmp_ptr().
+ * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of
+ * copies of the added elements and the compare function will be automatically set
+ * to cx_cmp_ptr(), if none is given.
  *
  * @param elem_size (@c size_t) the size of each element in bytes
  * @param initial_capacity (@c size_t) the initial number of elements the array can store
index 5ba27b04fa75cbcc6ae59442cde7d6ca0f04b2e3..e2868326bbb0cbe4dec92fd824706d92fe10e9f3 100644 (file)
@@ -88,6 +88,17 @@ extern "C" {
  */
 #define CX_BUFFER_COPY_ON_EXTEND 0x08
 
+/**
+ * Function pointer for cxBufferWrite that is compatible with cx_write_func.
+ * @see cx_write_func
+ */
+#define cxBufferWriteFunc  ((cx_write_func) cxBufferWrite)
+/**
+ * Function pointer for cxBufferRead that is compatible with cx_read_func.
+ * @see cx_read_func
+ */
+#define cxBufferReadFunc  ((cx_read_func) cxBufferRead)
+
 /**
  * Configuration for automatic flushing.
  */
@@ -128,7 +139,7 @@ struct cx_buffer_flush_config_s {
 };
 
 /**
- * Type alais for the flush configuration struct.
+ * Type alias for the flush configuration struct.
  *
  * @code
  * struct cx_buffer_flush_config_s {
@@ -162,7 +173,7 @@ struct cx_buffer_s {
      *
      * @see cxBufferEnableFlushing()
      */
-    CxBufferFlushConfigflush;
+    CxBufferFlushConfig *flush;
     /** Current position of the buffer. */
     size_t pos;
     /** Current capacity (i.e. maximum size) of the buffer. */
@@ -216,6 +227,7 @@ typedef struct cx_buffer_s CxBuffer;
  * @return zero on success, non-zero if a required allocation failed
  */
 cx_attr_nonnull_arg(1)
+cx_attr_export
 int cxBufferInit(
         CxBuffer *buffer,
         void *space,
@@ -239,6 +251,7 @@ int cxBufferInit(
  * @see cxBufferWrite()
  */
 cx_attr_nonnull
+cx_attr_export
 int cxBufferEnableFlushing(
     CxBuffer *buffer,
     CxBufferFlushConfig config
@@ -254,6 +267,7 @@ int cxBufferEnableFlushing(
  * @see cxBufferInit()
  */
 cx_attr_nonnull
+cx_attr_export
 void cxBufferDestroy(CxBuffer *buffer);
 
 /**
@@ -268,6 +282,7 @@ void cxBufferDestroy(CxBuffer *buffer);
  * @param buffer the buffer to deallocate
  * @see cxBufferCreate()
  */
+cx_attr_export
 void cxBufferFree(CxBuffer *buffer);
 
 /**
@@ -297,6 +312,7 @@ void cxBufferFree(CxBuffer *buffer);
 cx_attr_malloc
 cx_attr_dealloc(cxBufferFree, 1)
 cx_attr_nodiscard
+cx_attr_export
 CxBuffer *cxBufferCreate(
         void *space,
         size_t capacity,
@@ -341,6 +357,7 @@ CxBuffer *cxBufferCreate(
  * @see cxBufferShiftRight()
  */
 cx_attr_nonnull
+cx_attr_export
 int cxBufferShift(
         CxBuffer *buffer,
         off_t shift
@@ -357,6 +374,7 @@ int cxBufferShift(
  * @see cxBufferShift()
  */
 cx_attr_nonnull
+cx_attr_export
 int cxBufferShiftRight(
         CxBuffer *buffer,
         size_t shift
@@ -373,6 +391,7 @@ int cxBufferShiftRight(
  * @see cxBufferShift()
  */
 cx_attr_nonnull
+cx_attr_export
 int cxBufferShiftLeft(
         CxBuffer *buffer,
         size_t shift
@@ -400,6 +419,7 @@ int cxBufferShiftLeft(
  *
  */
 cx_attr_nonnull
+cx_attr_export
 int cxBufferSeek(
         CxBuffer *buffer,
         off_t offset,
@@ -419,6 +439,7 @@ int cxBufferSeek(
  * @see cxBufferReset()
  */
 cx_attr_nonnull
+cx_attr_export
 void cxBufferClear(CxBuffer *buffer);
 
 /**
@@ -431,6 +452,7 @@ void cxBufferClear(CxBuffer *buffer);
  * @see cxBufferClear()
  */
 cx_attr_nonnull
+cx_attr_export
 void cxBufferReset(CxBuffer *buffer);
 
 /**
@@ -443,6 +465,7 @@ void cxBufferReset(CxBuffer *buffer);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 bool cxBufferEof(const CxBuffer *buffer);
 
 
@@ -457,6 +480,7 @@ bool cxBufferEof(const CxBuffer *buffer);
  * @retval non-zero on allocation failure
  */
 cx_attr_nonnull
+cx_attr_export
 int cxBufferMinimumCapacity(
         CxBuffer *buffer,
         size_t capacity
@@ -473,14 +497,25 @@ int cxBufferMinimumCapacity(
  * the target until the target signals that it cannot take more data by
  * returning zero via the respective write function. In that case, the remaining
  * data in this buffer is shifted to the beginning of this buffer so that the
- * newly available space can be used to append as much data as possible. This
- * function only stops writing more elements, when the flush target and this
+ * newly available space can be used to append as much data as possible.
+ *
+ * This function only stops writing more elements, when the flush target and this
  * buffer are both incapable of taking more data or all data has been written.
- * If number of items that shall be written is larger than the buffer can hold,
- * the first items from @c ptr are directly relayed to the flush target, if
- * possible.
- * The number returned by this function is only the number of elements from
- * @c ptr that could be written to either the flush target or the buffer.
+ *
+ * If, after flushing, the number of items that shall be written still exceeds
+ * the capacity or flush threshold, this function tries to write all items directly
+ * to the flush target, if possible.
+ *
+ * The number returned by this function is the number of elements from
+ * @c ptr that could be written to either the flush target or the buffer
+ * (so it does not include the number of items that had been already in the buffer
+ * in were flushed during the process).
+ *
+ * @attention
+ * When @p size is larger than one and the contents of the buffer are not aligned
+ * with @p size, flushing stops after all complete items have been flushed, leaving
+ * the mis-aligned part in the buffer.
+ * Afterward, this function only writes as many items as possible to the buffer.
  *
  * @note The signature is compatible with the fwrite() family of functions.
  *
@@ -493,6 +528,7 @@ int cxBufferMinimumCapacity(
  * @see cxBufferRead()
  */
 cx_attr_nonnull
+cx_attr_export
 size_t cxBufferWrite(
         const void *ptr,
         size_t size,
@@ -520,6 +556,7 @@ size_t cxBufferWrite(
  * @see cxBufferRead()
  */
 cx_attr_nonnull
+cx_attr_export
 size_t cxBufferAppend(
         const void *ptr,
         size_t size,
@@ -581,6 +618,7 @@ size_t cxBufferAppend(
  * @see cxBufferEnableFlushing()
  */
 cx_attr_nonnull
+cx_attr_export
 size_t cxBufferFlush(CxBuffer *buffer);
 
 /**
@@ -599,6 +637,7 @@ size_t cxBufferFlush(CxBuffer *buffer);
  * @see cxBufferAppend()
  */
 cx_attr_nonnull
+cx_attr_export
 size_t cxBufferRead(
         void *ptr,
         size_t size,
@@ -626,6 +665,7 @@ size_t cxBufferRead(
  * @see cxBufferTerminate()
  */
 cx_attr_nonnull
+cx_attr_export
 int cxBufferPut(
         CxBuffer *buffer,
         int c
@@ -644,6 +684,7 @@ int cxBufferPut(
  * @return zero, if the terminator could be written, non-zero otherwise
  */
 cx_attr_nonnull
+cx_attr_export
 int cxBufferTerminate(CxBuffer *buffer);
 
 /**
@@ -657,6 +698,7 @@ int cxBufferTerminate(CxBuffer *buffer);
  */
 cx_attr_nonnull
 cx_attr_cstr_arg(2)
+cx_attr_export
 size_t cxBufferPutString(
         CxBuffer *buffer,
         const char *str
@@ -671,6 +713,7 @@ size_t cxBufferPutString(
  * @return the character or @c EOF, if the end of the buffer is reached
  */
 cx_attr_nonnull
+cx_attr_export
 int cxBufferGet(CxBuffer *buffer);
 
 #ifdef __cplusplus
index 04dc487483fffef887caea175a5cf1425d681632..ba329dcb1fcc1a766dfd22fdd6868be9a5ac4325 100644 (file)
@@ -92,6 +92,11 @@ struct cx_collection_s {
      * instead of copies of the actual objects.
      */
     bool store_pointer;
+    /**
+     * Indicates if this collection is guaranteed to be sorted.
+     * Note that the elements can still be sorted, even when the collection is not aware of that.
+     */
+    bool sorted;
 };
 
 /**
@@ -107,6 +112,45 @@ struct cx_collection_s {
  */
 #define CX_COLLECTION_BASE struct cx_collection_s collection
 
+/**
+ * Returns the number of elements currently stored.
+ *
+ * @param c a pointer to a struct that contains #CX_COLLECTION_BASE
+ * @return (@c size_t) the number of currently stored elements
+ */
+#define cxCollectionSize(c) ((c)->collection.size)
+
+/**
+ * Returns the size of one element.
+ *
+ * If #cxCollectionStoresPointers() returns true, this is the size of a pointer.
+ *
+ * @param c a pointer to a struct that contains #CX_COLLECTION_BASE
+ * @return (@c size_t) the size of one element in bytes
+ */
+#define cxCollectionElementSize(c) ((c)->collection.elem_size)
+
+/**
+ * Indicates whether this collection only stores pointers instead of the actual data.
+ *
+ * @param c a pointer to a struct that contains #CX_COLLECTION_BASE
+ * @retval true if this collection stores only pointers to data
+ * @retval false if this collection stores the actual element's data
+ */
+#define cxCollectionStoresPointers(c) ((c)->collection.store_pointer)
+
+/**
+ * Indicates whether the collection can guarantee that the stored elements are currently sorted.
+ *
+ * This may return false even when the elements are sorted.
+ * It is totally up to the implementation of the collection whether it keeps track of the order of its elements.
+ *
+ * @param c a pointer to a struct that contains #CX_COLLECTION_BASE
+ * @retval true if the elements are currently sorted wrt. the collection's compare function
+ * @retval false if the order of elements is unknown
+ */
+#define cxCollectionSorted(c) ((c)->collection.sorted)
+
 /**
  * Sets a simple destructor function for this collection.
  *
index 8cb23393a5ce2546668340eb43a78f8bc93f753c..604ca5f617c1ac68eff676929468986806ce7b16 100644 (file)
 #error Unknown pointer size or missing size macros!
 #endif
 
-// ---------------------------------------------------------------------------
-//       Missing Defines
-// ---------------------------------------------------------------------------
-
-#ifndef SSIZE_MAX // not defined in glibc since C23 and MSVC
-#if CX_WORDSIZE == 64
-/**
- * The maximum representable value in ssize_t.
- */
-#define SSIZE_MAX 0x7fffffffffffffffll
-#else
-#define SSIZE_MAX 0x7fffffffl
-#endif
-#endif
-
-
 // ---------------------------------------------------------------------------
 //       Attribute definitions
 // ---------------------------------------------------------------------------
 
 #endif // __STDC_VERSION__
 
+
+// ---------------------------------------------------------------------------
+//       MSVC specifics
+// ---------------------------------------------------------------------------
+
+#ifdef _MSC_VER
+// fix missing _Thread_local support
+#define _Thread_local __declspec(thread)
+#endif // _MSC_VER
+
+#if defined(CX_WINDLL_EXPORT)
+#define cx_attr_export __declspec(dllexport)
+#elif defined(CX_WINDLL)
+#define cx_attr_export __declspec(dllimport)
+#else
+/** Only used for building Windows DLLs. */
+#define cx_attr_export
+#endif // CX_WINDLL / CX_WINDLL_EXPORT
+
 // ---------------------------------------------------------------------------
 //       Useful function pointers
 // ---------------------------------------------------------------------------
@@ -356,21 +359,9 @@ typedef size_t (*cx_read_func)(
 #if __cplusplus
 extern "C"
 #endif
-int cx_szmul_impl(size_t a, size_t b, size_t *result);
+cx_attr_export int cx_szmul_impl(size_t a, size_t b, size_t *result);
 #endif // cx_szmul
 
 
-// ---------------------------------------------------------------------------
-//       Fixes for MSVC incompatibilities
-// ---------------------------------------------------------------------------
-
-#ifdef _MSC_VER
-// fix missing ssize_t definition
-#include <BaseTsd.h>
-typedef SSIZE_T ssize_t;
-
-// fix missing _Thread_local support
-#define _Thread_local __declspec(thread)
-#endif // _MSC_VER
 
 #endif // UCX_COMMON_H
index 98a39ff55617b4d75372ca622884349c6cff59c5..cb4ddf17045181c9fd12071b0a5247b0f9be86d3 100644 (file)
@@ -56,6 +56,7 @@ extern "C" {
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 typedef int (*cx_compare_func)(
     const void *left,
     const void *right
@@ -75,10 +76,11 @@ typedef int (*cx_compare_func)(
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_int(const void *i1, const void *i2);
 
 /**
- * Compares two ints.
+ * Compares two integers of type int.
  *
  * @param i1 integer one
  * @param i2 integer two
@@ -87,6 +89,7 @@ int cx_cmp_int(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_int(int i1, int i2);
 
 /**
@@ -103,10 +106,11 @@ int cx_vcmp_int(int i1, int i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_longint(const void *i1, const void *i2);
 
 /**
- * Compares two long ints.
+ * Compares two integers of type long int.
  *
  * @param i1 long integer one
  * @param i2 long integer two
@@ -115,6 +119,7 @@ int cx_cmp_longint(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_longint(long int i1, long int i2);
 
 /**
@@ -131,10 +136,11 @@ int cx_vcmp_longint(long int i1, long int i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_longlong(const void *i1, const void *i2);
 
 /**
- * Compares twolong long ints.
+ * Compares two integers of type long long.
  *
  * @param i1 long long int one
  * @param i2 long long int two
@@ -143,6 +149,7 @@ int cx_cmp_longlong(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_longlong(long long int i1, long long int i2);
 
 /**
@@ -159,6 +166,7 @@ int cx_vcmp_longlong(long long int i1, long long int i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_int16(const void *i1, const void *i2);
 
 /**
@@ -171,6 +179,7 @@ int cx_cmp_int16(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_int16(int16_t i1, int16_t i2);
 
 /**
@@ -187,6 +196,7 @@ int cx_vcmp_int16(int16_t i1, int16_t i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_int32(const void *i1, const void *i2);
 
 /**
@@ -199,6 +209,7 @@ int cx_cmp_int32(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_int32(int32_t i1, int32_t i2);
 
 /**
@@ -215,6 +226,7 @@ int cx_vcmp_int32(int32_t i1, int32_t i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_int64(const void *i1, const void *i2);
 
 /**
@@ -227,6 +239,7 @@ int cx_cmp_int64(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_int64(int64_t i1, int64_t i2);
 
 /**
@@ -243,10 +256,11 @@ int cx_vcmp_int64(int64_t i1, int64_t i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_uint(const void *i1, const void *i2);
 
 /**
- * Compares two unsigned ints.
+ * Compares two integers of type unsigned int.
  *
  * @param i1 unsigned integer one
  * @param i2 unsigned integer two
@@ -255,6 +269,7 @@ int cx_cmp_uint(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_uint(unsigned int i1, unsigned int i2);
 
 /**
@@ -271,10 +286,11 @@ int cx_vcmp_uint(unsigned int i1, unsigned int i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_ulongint(const void *i1, const void *i2);
 
 /**
- * Compares two unsigned long ints.
+ * Compares two integers of type unsigned long int.
  *
  * @param i1 unsigned long integer one
  * @param i2 unsigned long integer two
@@ -283,6 +299,7 @@ int cx_cmp_ulongint(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_ulongint(unsigned long int i1, unsigned long int i2);
 
 /**
@@ -299,10 +316,11 @@ int cx_vcmp_ulongint(unsigned long int i1, unsigned long int i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_ulonglong(const void *i1, const void *i2);
 
 /**
- * Compares two unsigned long long ints.
+ * Compares two integers of type unsigned long long.
  *
  * @param i1 unsigned long long one
  * @param i2 unsigned long long two
@@ -311,6 +329,7 @@ int cx_cmp_ulonglong(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_ulonglong(unsigned long long int i1, unsigned long long int i2);
 
 /**
@@ -327,6 +346,7 @@ int cx_vcmp_ulonglong(unsigned long long int i1, unsigned long long int i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_uint16(const void *i1, const void *i2);
 
 /**
@@ -339,6 +359,7 @@ int cx_cmp_uint16(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_uint16(uint16_t i1, uint16_t i2);
 
 /**
@@ -355,6 +376,7 @@ int cx_vcmp_uint16(uint16_t i1, uint16_t i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_uint32(const void *i1, const void *i2);
 
 /**
@@ -367,6 +389,7 @@ int cx_cmp_uint32(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_uint32(uint32_t i1, uint32_t i2);
 
 /**
@@ -383,6 +406,7 @@ int cx_vcmp_uint32(uint32_t i1, uint32_t i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_uint64(const void *i1, const void *i2);
 
 /**
@@ -395,6 +419,7 @@ int cx_cmp_uint64(const void *i1, const void *i2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_uint64(uint64_t i1, uint64_t i2);
 
 /**
@@ -411,6 +436,7 @@ int cx_vcmp_uint64(uint64_t i1, uint64_t i2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_float(const void *f1, const void *f2);
 
 /**
@@ -423,6 +449,7 @@ int cx_cmp_float(const void *f1, const void *f2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_float(float f1, float f2);
 
 /**
@@ -439,10 +466,11 @@ int cx_vcmp_float(float f1, float f2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_double(const void *d1, const void *d2);
 
 /**
- * Convenience function
+ * Compares two real numbers of type double with precision 1e-14.
  *
  * @param d1 double one
  * @param d2 double two
@@ -451,6 +479,7 @@ int cx_cmp_double(const void *d1, const void *d2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_double(double d1, double d2);
 
 /**
@@ -467,6 +496,7 @@ int cx_vcmp_double(double d1, double d2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_intptr(const void *ptr1, const void *ptr2);
 
 /**
@@ -479,6 +509,7 @@ int cx_cmp_intptr(const void *ptr1, const void *ptr2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_intptr(intptr_t ptr1, intptr_t ptr2);
 
 /**
@@ -495,6 +526,7 @@ int cx_vcmp_intptr(intptr_t ptr1, intptr_t ptr2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_uintptr(const void *ptr1, const void *ptr2);
 
 /**
@@ -507,10 +539,11 @@ int cx_cmp_uintptr(const void *ptr1, const void *ptr2);
  * @retval 1 if the left argument is greater than the right argument
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_vcmp_uintptr(uintptr_t ptr1, uintptr_t ptr2);
 
 /**
- * Compares the pointers specified in the arguments without de-referencing.
+ * Compares the pointers specified in the arguments without dereferencing.
  *
  * @param ptr1 pointer one
  * @param ptr2 pointer two
@@ -520,6 +553,7 @@ int cx_vcmp_uintptr(uintptr_t ptr1, uintptr_t ptr2);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cx_cmp_ptr(const void *ptr1, const void *ptr2);
 
 #ifdef __cplusplus
index f22721e8b710d171a994be2eb1f6f5846eb6193d..cdf8864057e41032ddddc890945be0c409c7c58d 100644 (file)
@@ -76,6 +76,7 @@ typedef struct cx_hash_key_s CxHashKey;
  * @see cx_hash_key()
  */
 cx_attr_nonnull
+cx_attr_export
 void cx_hash_murmur(CxHashKey *key);
 
 /**
@@ -88,6 +89,7 @@ void cx_hash_murmur(CxHashKey *key);
  */
 cx_attr_nodiscard
 cx_attr_cstr_arg(1)
+cx_attr_export
 CxHashKey cx_hash_key_str(const char *str);
 
 /**
@@ -99,6 +101,7 @@ CxHashKey cx_hash_key_str(const char *str);
  */
 cx_attr_nodiscard
 cx_attr_access_r(1, 2)
+cx_attr_export
 CxHashKey cx_hash_key_bytes(
         const unsigned char *bytes,
         size_t len
@@ -117,6 +120,7 @@ CxHashKey cx_hash_key_bytes(
  */
 cx_attr_nodiscard
 cx_attr_access_r(1, 2)
+cx_attr_export
 CxHashKey cx_hash_key(
         const void *obj,
         size_t len
index 08d06a9353d9a20aa245e31d43d60c7813c5dd3c..07e115564a88c67eb38c52dc988ea97c15dc9e19 100644 (file)
@@ -69,8 +69,8 @@ struct cx_hash_map_s {
  *
  * If @p buckets is zero, an implementation defined default will be used.
  *
- * If @p elem_size is CX_STORE_POINTERS, the created map will be created as if
- * cxMapStorePointers() was called immediately after creation.
+ * If @p elem_size is #CX_STORE_POINTERS, the created map stores pointers instead of
+ * copies of the added elements.
  *
  * @note Iterators provided by this hash map implementation provide the remove operation.
  * The index value of an iterator is incremented when the iterator advanced without removal.
@@ -85,6 +85,7 @@ struct cx_hash_map_s {
 cx_attr_nodiscard
 cx_attr_malloc
 cx_attr_dealloc(cxMapFree, 1)
+cx_attr_export
 CxMap *cxHashMapCreate(
         const CxAllocator *allocator,
         size_t itemsize,
@@ -94,8 +95,8 @@ CxMap *cxHashMapCreate(
 /**
  * Creates a new hash map with a default number of buckets.
  *
- * If @p elem_size is CX_STORE_POINTERS, the created map will be created as if
- * cxMapStorePointers() was called immediately after creation.
+ * If @p elem_size is #CX_STORE_POINTERS, the created map stores pointers instead of
+ * copies of the added elements.
  *
  * @note Iterators provided by this hash map implementation provide the remove operation.
  * The index value of an iterator is incremented when the iterator advanced without removal.
@@ -126,6 +127,7 @@ CxMap *cxHashMapCreate(
  * @retval non-zero if a memory allocation error occurred
  */
 cx_attr_nonnull
+cx_attr_export
 int cxMapRehash(CxMap *map);
 
 
index 1b83b2637ac368a4ada59ed8e0b669dab334c0de..204c4df29790c5f48b86e8f01c00ba9671170f89 100644 (file)
@@ -47,9 +47,8 @@ extern "C" {
  */
 struct cx_iterator_base_s {
     /**
-     * True iff the iterator points to valid data.
+     * True if the iterator points to valid data.
      */
-    cx_attr_nonnull
     bool (*valid)(const void *);
 
     /**
@@ -57,15 +56,11 @@ struct cx_iterator_base_s {
      *
      * When valid returns false, the behavior of this function is undefined.
      */
-    cx_attr_nonnull
-    cx_attr_nodiscard
     void *(*current)(const void *);
 
     /**
      * Original implementation in case the function needs to be wrapped.
      */
-    cx_attr_nonnull
-    cx_attr_nodiscard
     void *(*current_impl)(const void *);
 
     /**
@@ -73,7 +68,6 @@ struct cx_iterator_base_s {
      *
      * When valid returns false, the behavior of this function is undefined.
      */
-    cx_attr_nonnull
     void (*next)(void *);
     /**
      * Indicates whether this iterator may remove elements.
@@ -85,6 +79,12 @@ struct cx_iterator_base_s {
     bool remove;
 };
 
+/**
+ * Convenience type definition for the base structure of an iterator.
+ * @see #CX_ITERATOR_BASE
+ */
+typedef struct cx_iterator_base_s CxIteratorBase;
+
 /**
  * Declares base attributes for an iterator.
  * Must be the first member of an iterator structure.
@@ -119,27 +119,6 @@ struct cx_iterator_s {
         const void *c;
     } src_handle;
 
-    /**
-     * Field for storing a key-value pair.
-     * May be used by iterators that iterate over k/v-collections.
-     */
-    struct {
-        /**
-         * A pointer to the key.
-         */
-        const void *key;
-        /**
-         * A pointer to the value.
-         */
-        void *value;
-    } kv_data;
-
-    /**
-     * Field for storing a slot number.
-     * May be used by iterators that iterate over multi-bucket collections.
-     */
-    size_t slot;
-
     /**
      * If the iterator is position-aware, contains the index of the element in the underlying collection.
      * Otherwise, this field is usually uninitialized.
@@ -174,8 +153,6 @@ typedef struct cx_iterator_s CxIterator;
 /**
  * Checks if the iterator points to valid data.
  *
- * This is especially false for past-the-end iterators.
- *
  * @param iter the iterator
  * @retval true if the iterator points to valid data
  * @retval false if the iterator already moved past the end
@@ -215,7 +192,7 @@ typedef struct cx_iterator_s CxIterator;
  * This is useful for APIs that expect some iterator as an argument.
  *
  * @param iter the iterator
- * @return (@c CxIterator*) a pointer to the iterator
+ * @return (@c struct @c cx_iterator_base_s*) a pointer to the iterator
  */
 #define cxIteratorRef(iter) &((iter).base)
 
@@ -248,6 +225,7 @@ for (type elem; cxIteratorValid(iter) && (elem = (type)cxIteratorCurrent(iter))
  * @see cxIteratorPtr()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxIterator cxIterator(
         const void *array,
         size_t elem_size,
@@ -278,6 +256,7 @@ CxIterator cxIterator(
  * @return an iterator for the specified array
  */
 cx_attr_nodiscard
+cx_attr_export
 CxIterator cxMutIterator(
         void *array,
         size_t elem_size,
@@ -299,6 +278,7 @@ CxIterator cxMutIterator(
  * @see cxIterator()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxIterator cxIteratorPtr(
         const void *array,
         size_t elem_count
@@ -319,6 +299,7 @@ CxIterator cxIteratorPtr(
  * @see cxIteratorPtr()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxIterator cxMutIteratorPtr(
         void *array,
         size_t elem_count,
index 7c97f233f84d54a8141053d4e9796fefebeeade2..ee09ec1d72cdeb8884334bc03a2fdcdd53635407 100644 (file)
@@ -309,7 +309,7 @@ struct cx_json_token_s {
      */
     CxJsonTokenType tokentype;
     /**
-     * True, iff the @c content must be passed to cx_strfree().
+     * True, if the @c content must be passed to cx_strfree().
      */
     bool allocated;
     /**
@@ -374,11 +374,6 @@ struct cx_json_s {
      * Internally reserved memory for the value buffer stack.
      */
     CxJsonValue* vbuf_internal[8];
-
-    /**
-     * Used internally.
-     */
-    bool tokenizer_escape; // TODO: check if it can be replaced with look-behind
 };
 
 /**
@@ -449,6 +444,8 @@ struct cx_json_writer_s {
     bool sort_members;
     /**
      * The maximum number of fractional digits in a number value.
+     * The default value is 6 and values larger than 15 are reduced to 15.
+     * Note, that the actual number of digits may be lower, depending on the concrete number.
      */
     uint8_t frac_max_digits;
     /**
@@ -461,6 +458,10 @@ struct cx_json_writer_s {
      * Indentation is only used in pretty output.
      */
     uint8_t indent;
+    /**
+     * Set true to enable escaping of the slash character (solidus).
+     */
+    bool escape_slash;
 };
 
 /**
@@ -474,6 +475,7 @@ typedef struct cx_json_writer_s CxJsonWriter;
  * @return new JSON writer settings
  */
 cx_attr_nodiscard
+cx_attr_export
 CxJsonWriter cxJsonWriterCompact(void);
 
 /**
@@ -483,13 +485,13 @@ CxJsonWriter cxJsonWriterCompact(void);
  * @return new JSON writer settings
  */
 cx_attr_nodiscard
+cx_attr_export
 CxJsonWriter cxJsonWriterPretty(bool use_spaces);
 
 /**
  * Writes a JSON value to a buffer or stream.
  *
- * This function blocks until all data is written or an error when trying
- * to write data occurs.
+ * This function blocks until either all data is written, or an error occurs.
  * The write operation is not atomic in the sense that it might happen
  * that the data is only partially written when an error occurs with no
  * way to indicate how much data was written.
@@ -506,6 +508,7 @@ CxJsonWriter cxJsonWriterPretty(bool use_spaces);
  * @retval non-zero when no or not all data could be written
  */
 cx_attr_nonnull_arg(1, 2, 3)
+cx_attr_export
 int cxJsonWrite(
     void* target,
     const CxJsonValue* value,
@@ -521,6 +524,7 @@ int cxJsonWrite(
  * @see cxJsonDestroy()
  */
 cx_attr_nonnull_arg(1)
+cx_attr_export
 void cxJsonInit(CxJson *json, const CxAllocator *allocator);
 
 /**
@@ -530,6 +534,7 @@ void cxJsonInit(CxJson *json, const CxAllocator *allocator);
  * @see cxJsonInit()
  */
 cx_attr_nonnull
+cx_attr_export
 void cxJsonDestroy(CxJson *json);
 
 /**
@@ -567,6 +572,7 @@ static inline void cxJsonReset(CxJson *json) {
  */
 cx_attr_nonnull
 cx_attr_access_r(2, 3)
+cx_attr_export
 int cxJsonFilln(CxJson *json, const char *buf, size_t len);
 
 #ifdef __cplusplus
@@ -667,6 +673,7 @@ static inline int cx_json_fill_str(
  * @see cxJsonArrAddValues()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxJsonValue* cxJsonCreateObj(const CxAllocator* allocator);
 
 /**
@@ -678,6 +685,7 @@ CxJsonValue* cxJsonCreateObj(const CxAllocator* allocator);
  * @see cxJsonArrAddValues()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxJsonValue* cxJsonCreateArr(const CxAllocator* allocator);
 
 /**
@@ -690,6 +698,7 @@ CxJsonValue* cxJsonCreateArr(const CxAllocator* allocator);
  * @see cxJsonArrAddNumbers()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num);
 
 /**
@@ -702,6 +711,7 @@ CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num);
  * @see cxJsonArrAddIntegers()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxJsonValue* cxJsonCreateInteger(const CxAllocator* allocator, int64_t num);
 
 /**
@@ -717,6 +727,7 @@ CxJsonValue* cxJsonCreateInteger(const CxAllocator* allocator, int64_t num);
 cx_attr_nodiscard
 cx_attr_nonnull_arg(2)
 cx_attr_cstr_arg(2)
+cx_attr_export
 CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, const char *str);
 
 /**
@@ -730,6 +741,7 @@ CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, const char *str);
  * @see cxJsonArrAddCxStrings()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxJsonValue* cxJsonCreateCxString(const CxAllocator* allocator, cxstring str);
 
 /**
@@ -742,6 +754,7 @@ CxJsonValue* cxJsonCreateCxString(const CxAllocator* allocator, cxstring str);
  * @see cxJsonArrAddLiterals()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxJsonValue* cxJsonCreateLiteral(const CxAllocator* allocator, CxJsonLiteral lit);
 
 /**
@@ -755,6 +768,7 @@ CxJsonValue* cxJsonCreateLiteral(const CxAllocator* allocator, CxJsonLiteral lit
  */
 cx_attr_nonnull
 cx_attr_access_r(2, 3)
+cx_attr_export
 int cxJsonArrAddNumbers(CxJsonValue* arr, const double* num, size_t count);
 
 /**
@@ -768,6 +782,7 @@ int cxJsonArrAddNumbers(CxJsonValue* arr, const double* num, size_t count);
  */
 cx_attr_nonnull
 cx_attr_access_r(2, 3)
+cx_attr_export
 int cxJsonArrAddIntegers(CxJsonValue* arr, const int64_t* num, size_t count);
 
 /**
@@ -784,6 +799,7 @@ int cxJsonArrAddIntegers(CxJsonValue* arr, const int64_t* num, size_t count);
  */
 cx_attr_nonnull
 cx_attr_access_r(2, 3)
+cx_attr_export
 int cxJsonArrAddStrings(CxJsonValue* arr, const char* const* str, size_t count);
 
 /**
@@ -800,6 +816,7 @@ int cxJsonArrAddStrings(CxJsonValue* arr, const char* const* str, size_t count);
  */
 cx_attr_nonnull
 cx_attr_access_r(2, 3)
+cx_attr_export
 int cxJsonArrAddCxStrings(CxJsonValue* arr, const cxstring* str, size_t count);
 
 /**
@@ -813,6 +830,7 @@ int cxJsonArrAddCxStrings(CxJsonValue* arr, const cxstring* str, size_t count);
  */
 cx_attr_nonnull
 cx_attr_access_r(2, 3)
+cx_attr_export
 int cxJsonArrAddLiterals(CxJsonValue* arr, const CxJsonLiteral* lit, size_t count);
 
 /**
@@ -829,6 +847,7 @@ int cxJsonArrAddLiterals(CxJsonValue* arr, const CxJsonLiteral* lit, size_t coun
  */
 cx_attr_nonnull
 cx_attr_access_r(2, 3)
+cx_attr_export
 int cxJsonArrAddValues(CxJsonValue* arr, CxJsonValue* const* val, size_t count);
 
 /**
@@ -846,6 +865,7 @@ int cxJsonArrAddValues(CxJsonValue* arr, CxJsonValue* const* val, size_t count);
  * @retval non-zero allocation failure
  */
 cx_attr_nonnull
+cx_attr_export
 int cxJsonObjPut(CxJsonValue* obj, cxstring name, CxJsonValue* child);
 
 /**
@@ -858,6 +878,7 @@ int cxJsonObjPut(CxJsonValue* obj, cxstring name, CxJsonValue* child);
  * @see cxJsonCreateObj()
  */
 cx_attr_nonnull
+cx_attr_export
 CxJsonValue* cxJsonObjPutObj(CxJsonValue* obj, cxstring name);
 
 /**
@@ -870,6 +891,7 @@ CxJsonValue* cxJsonObjPutObj(CxJsonValue* obj, cxstring name);
  * @see cxJsonCreateArr()
  */
 cx_attr_nonnull
+cx_attr_export
 CxJsonValue* cxJsonObjPutArr(CxJsonValue* obj, cxstring name);
 
 /**
@@ -883,6 +905,7 @@ CxJsonValue* cxJsonObjPutArr(CxJsonValue* obj, cxstring name);
  * @see cxJsonCreateNumber()
  */
 cx_attr_nonnull
+cx_attr_export
 CxJsonValue* cxJsonObjPutNumber(CxJsonValue* obj, cxstring name, double num);
 
 /**
@@ -896,6 +919,7 @@ CxJsonValue* cxJsonObjPutNumber(CxJsonValue* obj, cxstring name, double num);
  * @see cxJsonCreateInteger()
  */
 cx_attr_nonnull
+cx_attr_export
 CxJsonValue* cxJsonObjPutInteger(CxJsonValue* obj, cxstring name, int64_t num);
 
 /**
@@ -912,6 +936,7 @@ CxJsonValue* cxJsonObjPutInteger(CxJsonValue* obj, cxstring name, int64_t num);
  */
 cx_attr_nonnull
 cx_attr_cstr_arg(3)
+cx_attr_export
 CxJsonValue* cxJsonObjPutString(CxJsonValue* obj, cxstring name, const char* str);
 
 /**
@@ -927,6 +952,7 @@ CxJsonValue* cxJsonObjPutString(CxJsonValue* obj, cxstring name, const char* str
  * @see cxJsonCreateCxString()
  */
 cx_attr_nonnull
+cx_attr_export
 CxJsonValue* cxJsonObjPutCxString(CxJsonValue* obj, cxstring name, cxstring str);
 
 /**
@@ -940,6 +966,7 @@ CxJsonValue* cxJsonObjPutCxString(CxJsonValue* obj, cxstring name, cxstring str)
  * @see cxJsonCreateLiteral()
  */
 cx_attr_nonnull
+cx_attr_export
 CxJsonValue* cxJsonObjPutLiteral(CxJsonValue* obj, cxstring name, CxJsonLiteral lit);
 
 /**
@@ -953,6 +980,7 @@ CxJsonValue* cxJsonObjPutLiteral(CxJsonValue* obj, cxstring name, CxJsonLiteral
  *
  * @param value the value
  */
+cx_attr_export
 void cxJsonValueFree(CxJsonValue *value);
 
 /**
@@ -979,6 +1007,7 @@ void cxJsonValueFree(CxJsonValue *value);
  */
 cx_attr_nonnull
 cx_attr_access_w(2)
+cx_attr_export
 CxJsonStatus cxJsonNext(CxJson *json, CxJsonValue **value);
 
 /**
@@ -1251,6 +1280,7 @@ static inline size_t cxJsonArrSize(const CxJsonValue *value) {
  */
 cx_attr_nonnull
 cx_attr_returns_nonnull
+cx_attr_export
 CxJsonValue *cxJsonArrGet(const CxJsonValue *value, size_t index);
 
 /**
@@ -1266,6 +1296,7 @@ CxJsonValue *cxJsonArrGet(const CxJsonValue *value, size_t index);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 CxIterator cxJsonArrIter(const CxJsonValue *value);
 
 /**
@@ -1282,6 +1313,7 @@ CxIterator cxJsonArrIter(const CxJsonValue *value);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 CxIterator cxJsonObjIter(const CxJsonValue *value);
 
 /**
@@ -1289,20 +1321,21 @@ CxIterator cxJsonObjIter(const CxJsonValue *value);
  */
 cx_attr_nonnull
 cx_attr_returns_nonnull
+cx_attr_export
 CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name);
 
 #ifdef __cplusplus
 } // extern "C"
 
-CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxstring name) {
+static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxstring name) {
     return cx_json_obj_get_cxstr(value, name);
 }
 
-CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxmutstr name) {
+static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxmutstr name) {
     return cx_json_obj_get_cxstr(value, cx_strcast(name));
 }
 
-CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) {
+static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) {
     return cx_json_obj_get_cxstr(value, cx_str(name));
 }
 
index 95d623a6edccefdcbdefcd7137f8c3e11204f445..fcdae7490e69860c1b4597b529b9046ed602257b 100644 (file)
 extern "C" {
 #endif
 
-/**
- * The maximum item size that uses SBO swap instead of relinking.
- *
- */
-extern const unsigned cx_linked_list_swap_sbo_size;
-
 /**
  * Allocates a linked list for storing elements with @p elem_size bytes each.
  *
- * If @p elem_size is CX_STORE_POINTERS, the created list will be created as if
- * cxListStorePointers() was called immediately after creation and the compare
- * function will be automatically set to cx_cmp_ptr(), if none is given.
+ * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of
+ * copies of the added elements and the compare function will be automatically set
+ * to cx_cmp_ptr(), if none is given.
  *
  * @param allocator the allocator for allocating the list nodes
  * (if @c NULL, a default stdlib allocator will be used)
@@ -67,6 +61,7 @@ extern const unsigned cx_linked_list_swap_sbo_size;
 cx_attr_nodiscard
 cx_attr_malloc
 cx_attr_dealloc(cxListFree, 1)
+cx_attr_export
 CxList *cxLinkedListCreate(
         const CxAllocator *allocator,
         cx_compare_func comparator,
@@ -80,9 +75,9 @@ CxList *cxLinkedListCreate(
  * to call functions that need a comparator, you must either set one immediately
  * after list creation or use cxLinkedListCreate().
  *
- * If @p elem_size is CX_STORE_POINTERS, the created list will be created as if
- * cxListStorePointers() was called immediately after creation and the compare
- * function will be automatically set to cx_cmp_ptr().
+ * If @p elem_size is #CX_STORE_POINTERS, the created list stores pointers instead of
+ * copies of the added elements and the compare function will be automatically set
+ * to cx_cmp_ptr(), if none is given.
  *
  * @param elem_size (@c size_t) the size of each element in bytes
  * @return (@c CxList*) the created list
@@ -109,6 +104,7 @@ CxList *cxLinkedListCreate(
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 void *cx_linked_list_at(
         const void *start,
         size_t start_index,
@@ -116,45 +112,27 @@ void *cx_linked_list_at(
         size_t index
 );
 
-/**
- * Finds the index of an element within a linked list.
- *
- * @param start a pointer to the start node
- * @param loc_advance the location of the pointer to advance
- * @param loc_data the location of the @c data pointer within your node struct
- * @param cmp_func a compare function to compare @p elem against the node data
- * @param elem a pointer to the element to find
- * @return the index of the element or a negative value if it could not be found
- */
-cx_attr_nonnull
-ssize_t cx_linked_list_find(
-        const void *start,
-        ptrdiff_t loc_advance,
-        ptrdiff_t loc_data,
-        cx_compare_func cmp_func,
-        const void *elem
-);
-
 /**
  * Finds the node containing an element within a linked list.
  *
- * @param result a pointer to the memory where the node pointer (or @c NULL if the element
- * could not be found) shall be stored to
  * @param start a pointer to the start node
  * @param loc_advance the location of the pointer to advance
  * @param loc_data the location of the @c data pointer within your node struct
  * @param cmp_func a compare function to compare @p elem against the node data
  * @param elem a pointer to the element to find
- * @return the index of the element or a negative value if it could not be found
+ * @param found_index an optional pointer where the index of the found node
+ * (given that @p start has index 0) is stored
+ * @return the index of the element, if found - unspecified if not found
  */
-cx_attr_nonnull
-ssize_t cx_linked_list_find_node(
-        void **result,
+cx_attr_nonnull_arg(1, 4, 5)
+cx_attr_export
+void *cx_linked_list_find(
         const void *start,
         ptrdiff_t loc_advance,
         ptrdiff_t loc_data,
         cx_compare_func cmp_func,
-        const void *elem
+        const void *elem,
+        size_t *found_index
 );
 
 /**
@@ -170,6 +148,7 @@ ssize_t cx_linked_list_find_node(
  */
 cx_attr_nonnull
 cx_attr_returns_nonnull
+cx_attr_export
 void *cx_linked_list_first(
         const void *node,
         ptrdiff_t loc_prev
@@ -188,6 +167,7 @@ void *cx_linked_list_first(
  */
 cx_attr_nonnull
 cx_attr_returns_nonnull
+cx_attr_export
 void *cx_linked_list_last(
         const void *node,
         ptrdiff_t loc_next
@@ -204,6 +184,7 @@ void *cx_linked_list_last(
  * @return the node or @c NULL if @p node has no predecessor
  */
 cx_attr_nonnull
+cx_attr_export
 void *cx_linked_list_prev(
         const void *begin,
         ptrdiff_t loc_next,
@@ -223,6 +204,7 @@ void *cx_linked_list_prev(
  * @param new_node a pointer to the node that shall be appended
  */
 cx_attr_nonnull_arg(5)
+cx_attr_export
 void cx_linked_list_add(
         void **begin,
         void **end,
@@ -244,6 +226,7 @@ void cx_linked_list_add(
  * @param new_node a pointer to the node that shall be prepended
  */
 cx_attr_nonnull_arg(5)
+cx_attr_export
 void cx_linked_list_prepend(
         void **begin,
         void **end,
@@ -261,6 +244,7 @@ void cx_linked_list_prepend(
  * @param loc_next the location of a @c next pointer within your node struct (required)
  */
 cx_attr_nonnull
+cx_attr_export
 void cx_linked_list_link(
         void *left,
         void *right,
@@ -279,6 +263,7 @@ void cx_linked_list_link(
  * @param loc_next the location of a @c next pointer within your node struct (required)
  */
 cx_attr_nonnull
+cx_attr_export
 void cx_linked_list_unlink(
         void *left,
         void *right,
@@ -301,6 +286,7 @@ void cx_linked_list_unlink(
  * @param new_node a pointer to the node that shall be inserted
  */
 cx_attr_nonnull_arg(6)
+cx_attr_export
 void cx_linked_list_insert(
         void **begin,
         void **end,
@@ -331,6 +317,7 @@ void cx_linked_list_insert(
  * @param insert_end a pointer to the last node of the chain (or NULL if the last node shall be determined)
  */
 cx_attr_nonnull_arg(6)
+cx_attr_export
 void cx_linked_list_insert_chain(
         void **begin,
         void **end,
@@ -356,6 +343,7 @@ void cx_linked_list_insert_chain(
  * @param cmp_func a compare function that will receive the node pointers
  */
 cx_attr_nonnull_arg(1, 5, 6)
+cx_attr_export
 void cx_linked_list_insert_sorted(
         void **begin,
         void **end,
@@ -385,6 +373,7 @@ void cx_linked_list_insert_sorted(
  * @param cmp_func a compare function that will receive the node pointers
  */
 cx_attr_nonnull_arg(1, 5, 6)
+cx_attr_export
 void cx_linked_list_insert_sorted_chain(
         void **begin,
         void **end,
@@ -416,6 +405,7 @@ void cx_linked_list_insert_sorted_chain(
  * @return the actual number of nodes that were removed (can be less when the list did not have enough nodes)
  */
 cx_attr_nonnull_arg(5)
+cx_attr_export
 size_t cx_linked_list_remove_chain(
         void **begin,
         void **end,
@@ -462,6 +452,8 @@ static inline void cx_linked_list_remove(
  * @param loc_next the location of the @c next pointer within the node struct
  * @return the size of the list or zero if @p node is @c NULL
  */
+cx_attr_nodiscard
+cx_attr_export
 size_t cx_linked_list_size(
         const void *node,
         ptrdiff_t loc_next
@@ -490,6 +482,7 @@ size_t cx_linked_list_size(
  * @param cmp_func the compare function defining the sort order
  */
 cx_attr_nonnull_arg(1, 6)
+cx_attr_export
 void cx_linked_list_sort(
         void **begin,
         void **end,
@@ -514,6 +507,7 @@ void cx_linked_list_sort(
  * right list, positive if the left list is larger than the right list, zero if both lists are equal.
  */
 cx_attr_nonnull_arg(5)
+cx_attr_export
 int cx_linked_list_compare(
         const void *begin_left,
         const void *begin_right,
@@ -531,6 +525,7 @@ int cx_linked_list_compare(
  * @param loc_next the location of a @c next pointer within your node struct (required)
  */
 cx_attr_nonnull_arg(1)
+cx_attr_export
 void cx_linked_list_reverse(
         void **begin,
         void **end,
index 8f6c5395edf8fb16d8a994d2e794d93f7cb2419f..2df6c506002096f10066de8672c353e93f912a71 100644 (file)
@@ -80,7 +80,6 @@ struct cx_list_class_s {
 
     /**
      * Member function for inserting a single element.
-     * Implementors SHOULD see to performant implementations for corner cases.
      */
     int (*insert_element)(
             struct cx_list_s *list,
@@ -90,7 +89,6 @@ struct cx_list_class_s {
 
     /**
      * Member function for inserting multiple elements.
-     * Implementors SHOULD see to performant implementations for corner cases.
      *
      * @see cx_list_default_insert_array()
      */
@@ -165,7 +163,7 @@ struct cx_list_class_s {
     /**
      * Member function for finding and optionally removing an element.
      */
-    ssize_t (*find_remove)(
+    size_t (*find_remove)(
             struct cx_list_s *list,
             const void *elem,
             bool remove
@@ -219,6 +217,7 @@ struct cx_list_class_s {
  * @return the number of elements actually inserted
  */
 cx_attr_nonnull
+cx_attr_export
 size_t cx_list_default_insert_array(
         struct cx_list_s *list,
         size_t index,
@@ -243,6 +242,7 @@ size_t cx_list_default_insert_array(
  * @return the number of elements actually inserted
  */
 cx_attr_nonnull
+cx_attr_export
 size_t cx_list_default_insert_sorted(
         struct cx_list_s *list,
         const void *sorted_data,
@@ -261,6 +261,7 @@ size_t cx_list_default_insert_sorted(
  * @param list the list that shall be sorted
  */
 cx_attr_nonnull
+cx_attr_export
 void cx_list_default_sort(struct cx_list_s *list);
 
 /**
@@ -277,51 +278,67 @@ void cx_list_default_sort(struct cx_list_s *list);
  * allocation for the temporary buffer fails
  */
 cx_attr_nonnull
+cx_attr_export
 int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j);
 
 /**
- * Common type for all list implementations.
- */
-typedef struct cx_list_s CxList;
-
-/**
- * Advises the list to store copies of the objects (default mode of operation).
- *
- * Retrieving objects from this list will yield pointers to the copies stored
- * within this list.
- *
- * @param list the list
- * @see cxListStorePointers()
- */
-cx_attr_nonnull
-void cxListStoreObjects(CxList *list);
-
-/**
- * Advises the list to only store pointers to the objects.
- *
- * Retrieving objects from this list will yield the original pointers stored.
- *
- * @note This function forcibly sets the element size to the size of a pointer.
- * Invoking this function on a non-empty list that already stores copies of
- * objects is undefined.
- *
- * @param list the list
- * @see cxListStoreObjects()
- */
-cx_attr_nonnull
-void cxListStorePointers(CxList *list);
+ * Initializes a list struct.
+ *
+ * Only use this function if you are creating your own list implementation.
+ * The purpose of this function is to be called in the initialization code
+ * of your list, to set certain members correctly.
+ *
+ * This is particularly important when you want your list to support
+ * #CX_STORE_POINTERS as @p elem_size. This function will wrap the list
+ * class accordingly and make sure that you can implement your list as if
+ * it was only storing objects and the wrapper will automatically enable
+ * the feature of storing pointers.
+ *
+ * @par Example
+ *
+ * @code
+ * CxList *myCustomListCreate(
+ *         const CxAllocator *allocator,
+ *         cx_compare_func comparator,
+ *         size_t elem_size
+ * ) {
+ *     if (allocator == NULL) {
+ *         allocator = cxDefaultAllocator;
+ *     }
+ *
+ *     MyCustomList *list = cxCalloc(allocator, 1, sizeof(MyCustomList));
+ *     if (list == NULL) return NULL;
+ *
+ *     // initialize
+ *     cx_list_init((CxList*)list, &my_custom_list_class,
+ *             allocator, comparator, elem_size);
+ *
+ *     // ... some more custom stuff ...
+ *
+ *     return (CxList *) list;
+ * }
+ * @endcode
+ *
+ * @param list the list to initialize
+ * @param cl the list class
+ * @param allocator the allocator for the elements
+ * @param comparator a compare function for the elements
+ * @param elem_size the size of one element
+ */
+cx_attr_nonnull_arg(1, 2, 3)
+cx_attr_export
+void cx_list_init(
+    struct cx_list_s *list,
+    struct cx_list_class_s *cl,
+    const struct cx_allocator_s *allocator,
+    cx_compare_func comparator,
+    size_t elem_size
+);
 
 /**
- * Returns true, if this list is storing pointers instead of the actual data.
- *
- * @param list
- * @return true, if this list is storing pointers
- * @see cxListStorePointers()
+ * Common type for all list implementations.
  */
-cx_attr_nonnull
-static inline bool cxListIsStoringPointers(const CxList *list) {
-    return list->collection.store_pointer;
-}
+typedef struct cx_list_s CxList;
 
 /**
  * Returns the number of elements currently stored in the list.
@@ -348,6 +365,7 @@ static inline int cxListAdd(
         CxList *list,
         const void *elem
 ) {
+    list->collection.sorted = false;
     return list->cl->insert_element(list, list->collection.size, elem);
 }
 
@@ -373,6 +391,7 @@ static inline size_t cxListAddArray(
         const void *array,
         size_t n
 ) {
+    list->collection.sorted = false;
     return list->cl->insert_array(list, list->collection.size, array, n);
 }
 
@@ -395,12 +414,15 @@ static inline int cxListInsert(
         size_t index,
         const void *elem
 ) {
+    list->collection.sorted = false;
     return list->cl->insert_element(list, index, elem);
 }
 
 /**
  * Inserts an item into a sorted list.
  *
+ * If the list is not sorted already, the behavior is undefined.
+ *
  * @param list the list
  * @param elem a pointer to the element to add
  * @retval zero success
@@ -411,6 +433,7 @@ static inline int cxListInsertSorted(
         CxList *list,
         const void *elem
 ) {
+    list->collection.sorted = true; // guaranteed by definition
     const void *data = list->collection.store_pointer ? &elem : elem;
     return list->cl->insert_sorted(list, data, 1) == 0;
 }
@@ -441,6 +464,7 @@ static inline size_t cxListInsertArray(
         const void *array,
         size_t n
 ) {
+    list->collection.sorted = false;
     return list->cl->insert_array(list, index, array, n);
 }
 
@@ -456,6 +480,8 @@ static inline size_t cxListInsertArray(
  * If this list is storing pointers instead of objects @p array is expected to
  * be an array of pointers.
  *
+ * If the list is not sorted already, the behavior is undefined.
+ *
  * @param list the list
  * @param array a pointer to the elements to add
  * @param n the number of elements to add
@@ -467,6 +493,7 @@ static inline size_t cxListInsertSortedArray(
         const void *array,
         size_t n
 ) {
+    list->collection.sorted = true; // guaranteed by definition
     return list->cl->insert_sorted(list, array, n);
 }
 
@@ -491,7 +518,9 @@ static inline int cxListInsertAfter(
         CxIterator *iter,
         const void *elem
 ) {
-    return ((struct cx_list_s *) iter->src_handle.m)->cl->insert_iter(iter, elem, 0);
+    CxList* list = (CxList*)iter->src_handle.m;
+    list->collection.sorted = false;
+    return list->cl->insert_iter(iter, elem, 0);
 }
 
 /**
@@ -515,7 +544,9 @@ static inline int cxListInsertBefore(
         CxIterator *iter,
         const void *elem
 ) {
-    return ((struct cx_list_s *) iter->src_handle.m)->cl->insert_iter(iter, elem, 1);
+    CxList* list = (CxList*)iter->src_handle.m;
+    list->collection.sorted = false;
+    return list->cl->insert_iter(iter, elem, 1);
 }
 
 /**
@@ -616,6 +647,7 @@ static inline size_t cxListRemoveArrayAndGet(
  */
 cx_attr_nonnull
 static inline void cxListClear(CxList *list) {
+    list->collection.sorted = true; // empty lists are always sorted
     list->cl->clear(list);
 }
 
@@ -638,6 +670,7 @@ static inline int cxListSwap(
         size_t i,
         size_t j
 ) {
+    list->collection.sorted = false;
     return list->cl->swap(list, i, j);
 }
 
@@ -709,6 +742,7 @@ static inline CxIterator cxListBackwardsIteratorAt(
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 CxIterator cxListMutIteratorAt(
         CxList *list,
         size_t index
@@ -728,6 +762,7 @@ CxIterator cxListMutIteratorAt(
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 CxIterator cxListMutBackwardsIteratorAt(
         CxList *list,
         size_t index
@@ -805,18 +840,32 @@ static inline CxIterator cxListMutBackwardsIterator(CxList *list) {
  *
  * @param list the list
  * @param elem the element to find
- * @return the index of the element or a negative
- * value when the element is not found
+ * @return the index of the element or the size of the list when the element is not found
+ * @see cxListIndexValid()
  */
 cx_attr_nonnull
 cx_attr_nodiscard
-static inline ssize_t cxListFind(
+static inline size_t cxListFind(
         const CxList *list,
         const void *elem
 ) {
     return list->cl->find_remove((CxList*)list, elem, false);
 }
 
+/**
+ * Checks if the specified index is within bounds.
+ *
+ * @param list the list
+ * @param index the index
+ * @retval true if the index is within bounds
+ * @retval false if the index is out of bounds
+ */
+cx_attr_nonnull
+cx_attr_nodiscard
+static inline bool cxListIndexValid(const CxList *list, size_t index) {
+    return index < list->collection.size;
+}
+
 /**
  * Removes and returns the index of the first element that equals @p elem.
  *
@@ -824,11 +873,12 @@ static inline ssize_t cxListFind(
  *
  * @param list the list
  * @param elem the element to find and remove
- * @return the index of the now removed element or a negative
- * value when the element is not found or could not be removed
+ * @return the index of the now removed element or the list size
+ * when the element is not found or could not be removed
+ * @see cxListIndexValid()
  */
 cx_attr_nonnull
-static inline ssize_t cxListFindRemove(
+static inline size_t cxListFindRemove(
         CxList *list,
         const void *elem
 ) {
@@ -845,6 +895,7 @@ static inline ssize_t cxListFindRemove(
 cx_attr_nonnull
 static inline void cxListSort(CxList *list) {
     list->cl->sort(list);
+    list->collection.sorted = true;
 }
 
 /**
@@ -854,6 +905,8 @@ static inline void cxListSort(CxList *list) {
  */
 cx_attr_nonnull
 static inline void cxListReverse(CxList *list) {
+    // still sorted, but not according to the cmp_func
+    list->collection.sorted = false;
     list->cl->reverse(list);
 }
 
@@ -873,6 +926,7 @@ static inline void cxListReverse(CxList *list) {
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 int cxListCompare(
         const CxList *list,
         const CxList *other
@@ -885,6 +939,7 @@ int cxListCompare(
  *
  * @param list the list which shall be freed
  */
+cx_attr_export
 void cxListFree(CxList *list);
 
 /**
@@ -895,6 +950,7 @@ void cxListFree(CxList *list);
  * You can use this is a placeholder for initializing CxList pointers
  * for which you do not want to reserve memory right from the beginning.
  */
+cx_attr_export
 extern CxList *const cxEmptyList;
 
 
index 22a01e925f5b36017f578283d184a2a683cc18e3..36067d55e364f2a1bf975ead176cababb67a91ab 100644 (file)
@@ -51,6 +51,9 @@ typedef struct cx_map_s CxMap;
 /** Type for a map entry. */
 typedef struct cx_map_entry_s CxMapEntry;
 
+/** Type for a map iterator. */
+typedef struct cx_map_iterator_s CxMapIterator;
+
 /** Type for map class definitions. */
 typedef struct cx_map_class_s cx_map_class;
 
@@ -64,6 +67,20 @@ struct cx_map_s {
     cx_map_class *cl;
 };
 
+/**
+ * A map entry.
+ */
+struct cx_map_entry_s {
+    /**
+     * A pointer to the key.
+     */
+    const CxHashKey *key;
+    /**
+     * A pointer to the value.
+     */
+    void *value;
+};
+
 /**
  * The type of iterator for a map.
  */
@@ -82,6 +99,76 @@ enum cx_map_iterator_type {
     CX_MAP_ITERATOR_VALUES
 };
 
+/**
+ * Internal iterator struct - use CxMapIterator.
+ */
+struct cx_map_iterator_s {
+    /**
+     * Inherited common data for all iterators.
+     */
+    CX_ITERATOR_BASE;
+
+    /**
+     * Handle for the source map.
+     */
+    union {
+        /**
+         * Access for mutating iterators.
+         */
+        CxMap *m;
+        /**
+         * Access for normal iterators.
+         */
+        const CxMap *c;
+    } map;
+
+    /**
+     * Handle for the current element.
+     *
+     * @attention Depends on the map implementation, do not assume a type (better: do not use!).
+     */
+    void *elem;
+
+    /**
+     * Reserved memory for a map entry.
+     *
+     * If a map implementation uses an incompatible layout, the iterator needs something
+     * to point to during iteration which @em is compatible.
+     */
+    CxMapEntry entry;
+
+    /**
+     * Field for storing the current slot number.
+     *
+     * (Used internally)
+     */
+    size_t slot;
+
+    /**
+     * Counts the elements successfully.
+     * It usually does not denote a stable index within the map as it would be for arrays.
+     */
+    size_t index;
+
+    /**
+     * The size of a value stored in this map.
+     */
+    size_t elem_size;
+
+    /**
+     * May contain the total number of elements, if known.
+     * Set to @c SIZE_MAX when the total number is unknown during iteration.
+     *
+     * @remark The UCX implementations of #CxMap always know the number of elements they store.
+     */
+    size_t elem_count;
+
+    /**
+     * The type of this iterator.
+     */
+    enum cx_map_iterator_type type;
+};
+
 /**
  * The class definition for arbitrary maps.
  */
@@ -132,21 +219,7 @@ struct cx_map_class_s {
     /**
      * Creates an iterator for this map.
      */
-    CxIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type);
-};
-
-/**
- * A map entry.
- */
-struct cx_map_entry_s {
-    /**
-     * A pointer to the key.
-     */
-    const CxHashKey *key;
-    /**
-     * A pointer to the value.
-     */
-    void *value;
+    CxMapIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type);
 };
 
 /**
@@ -157,52 +230,9 @@ struct cx_map_entry_s {
  * You can use this is a placeholder for initializing CxMap pointers
  * for which you do not want to reserve memory right from the beginning.
  */
+cx_attr_export
 extern CxMap *const cxEmptyMap;
 
-/**
- * Advises the map to store copies of the objects (default mode of operation).
- *
- * Retrieving objects from this map will yield pointers to the copies stored
- * within this list.
- *
- * @param map the map
- * @see cxMapStorePointers()
- */
-cx_attr_nonnull
-static inline void cxMapStoreObjects(CxMap *map) {
-    map->collection.store_pointer = false;
-}
-
-/**
- * Advises the map to only store pointers to the objects.
- *
- * Retrieving objects from this list will yield the original pointers stored.
- *
- * @note This function forcibly sets the element size to the size of a pointer.
- * Invoking this function on a non-empty map that already stores copies of
- * objects is undefined.
- *
- * @param map the map
- * @see cxMapStoreObjects()
- */
-cx_attr_nonnull
-static inline void cxMapStorePointers(CxMap *map) {
-    map->collection.store_pointer = true;
-    map->collection.elem_size = sizeof(void *);
-}
-
-/**
- * Returns true, if this map is storing pointers instead of the actual data.
- *
- * @param map
- * @return true, if this map is storing pointers
- * @see cxMapStorePointers()
- */
-cx_attr_nonnull
-static inline bool cxMapIsStoringPointers(const CxMap *map) {
-    return map->collection.store_pointer;
-}
-
 /**
  * Deallocates the memory of the specified map.
  *
@@ -210,6 +240,7 @@ static inline bool cxMapIsStoringPointers(const CxMap *map) {
  *
  * @param map the map to be freed
  */
+cx_attr_export
 void cxMapFree(CxMap *map);
 
 
@@ -239,6 +270,10 @@ static inline size_t cxMapSize(const CxMap *map) {
 /**
  * Creates a value iterator for a map.
  *
+ * When the map is storing pointers, those pointers are returned.
+ * Otherwise, the iterator iterates over pointers to the memory within the map where the
+ * respective elements are stored.
+ *
  * @note An iterator iterates over all elements successively. Therefore, the order
  * highly depends on the map implementation and may change arbitrarily when the contents change.
  *
@@ -247,14 +282,15 @@ static inline size_t cxMapSize(const CxMap *map) {
  */
 cx_attr_nonnull
 cx_attr_nodiscard
-static inline CxIterator cxMapIteratorValues(const CxMap *map) {
+static inline CxMapIterator cxMapIteratorValues(const CxMap *map) {
     return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);
 }
 
 /**
  * Creates a key iterator for a map.
  *
- * The elements of the iterator are keys of type CxHashKey.
+ * The elements of the iterator are keys of type CxHashKey and the pointer returned
+ * during iterator shall be treated as @c const @c CxHashKey* .
  *
  * @note An iterator iterates over all elements successively. Therefore, the order
  * highly depends on the map implementation and may change arbitrarily when the contents change.
@@ -264,14 +300,15 @@ static inline CxIterator cxMapIteratorValues(const CxMap *map) {
  */
 cx_attr_nonnull
 cx_attr_nodiscard
-static inline CxIterator cxMapIteratorKeys(const CxMap *map) {
+static inline CxMapIterator cxMapIteratorKeys(const CxMap *map) {
     return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);
 }
 
 /**
  * Creates an iterator for a map.
  *
- * The elements of the iterator are key/value pairs of type CxMapEntry.
+ * The elements of the iterator are key/value pairs of type CxMapEntry and the pointer returned
+ * during iterator shall be treated as @c const @c CxMapEntry* .
  *
  * @note An iterator iterates over all elements successively. Therefore, the order
  * highly depends on the map implementation and may change arbitrarily when the contents change.
@@ -283,7 +320,7 @@ static inline CxIterator cxMapIteratorKeys(const CxMap *map) {
  */
 cx_attr_nonnull
 cx_attr_nodiscard
-static inline CxIterator cxMapIterator(const CxMap *map) {
+static inline CxMapIterator cxMapIterator(const CxMap *map) {
     return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);
 }
 
@@ -291,6 +328,10 @@ static inline CxIterator cxMapIterator(const CxMap *map) {
 /**
  * Creates a mutating iterator over the values of a map.
  *
+ * When the map is storing pointers, those pointers are returned.
+ * Otherwise, the iterator iterates over pointers to the memory within the map where the
+ * respective elements are stored.
+ *
  * @note An iterator iterates over all elements successively. Therefore, the order
  * highly depends on the map implementation and may change arbitrarily when the contents change.
  *
@@ -299,12 +340,14 @@ static inline CxIterator cxMapIterator(const CxMap *map) {
  */
 cx_attr_nonnull
 cx_attr_nodiscard
-CxIterator cxMapMutIteratorValues(CxMap *map);
+cx_attr_export
+CxMapIterator cxMapMutIteratorValues(CxMap *map);
 
 /**
  * Creates a mutating iterator over the keys of a map.
  *
- * The elements of the iterator are keys of type CxHashKey.
+ * The elements of the iterator are keys of type CxHashKey and the pointer returned
+ * during iterator shall be treated as @c const @c CxHashKey* .
  *
  * @note An iterator iterates over all elements successively. Therefore, the order
  * highly depends on the map implementation and may change arbitrarily when the contents change.
@@ -314,12 +357,14 @@ CxIterator cxMapMutIteratorValues(CxMap *map);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
-CxIterator cxMapMutIteratorKeys(CxMap *map);
+cx_attr_export
+CxMapIterator cxMapMutIteratorKeys(CxMap *map);
 
 /**
  * Creates a mutating iterator for a map.
  *
- * The elements of the iterator are key/value pairs of type CxMapEntry.
+ * The elements of the iterator are key/value pairs of type CxMapEntry and the pointer returned
+ * during iterator shall be treated as @c const @c CxMapEntry* .
  *
  * @note An iterator iterates over all elements successively. Therefore, the order
  * highly depends on the map implementation and may change arbitrarily when the contents change.
@@ -331,7 +376,8 @@ CxIterator cxMapMutIteratorKeys(CxMap *map);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
-CxIterator cxMapMutIterator(CxMap *map);
+cx_attr_export
+CxMapIterator cxMapMutIterator(CxMap *map);
 
 #ifdef __cplusplus
 } // end the extern "C" block here, because we want to start overloading
@@ -538,6 +584,8 @@ static inline int cx_map_put_str(
  * Puts a key/value-pair into the map.
  *
  * A possible existing value will be overwritten.
+ * If destructor functions are specified, they are called for
+ * the overwritten element.
  *
  * If this map is storing pointers, the @p value pointer is written
  * to the map. Otherwise, the memory is copied from @p value with
@@ -749,7 +797,7 @@ static inline int cx_map_remove_and_get_str(
  * Removes a key/value-pair from the map by using the key.
  *
  * This function will copy the contents of the removed element
- * to the target buffer must be guaranteed to be large enough
+ * to the target buffer, which must be guaranteed to be large enough
  * to hold the element (the map's element size).
  * The destructor functions, if any, will @em not be called.
  *
@@ -761,8 +809,7 @@ static inline int cx_map_remove_and_get_str(
  * @param targetbuf (@c void*) the buffer where the element shall be copied to
  * @retval zero success
  * @retval non-zero the key was not found
- * 
- * @see cxMapStorePointers()
+ *
  * @see cxMapRemove()
  */
 #define cxMapRemoveAndGet(map, key, targetbuf) _Generic((key), \
index fc4b66e55eafddd690d5413db2bdbfa713e2a26c..43b3b173a20c24d57e0d0184e811e9b387de94fd 100644 (file)
@@ -80,6 +80,7 @@ typedef struct cx_mempool_s CxMempool;
  *
  * @param pool the memory pool to free
  */
+cx_attr_export
 void cxMempoolFree(CxMempool *pool);
 
 /**
@@ -94,6 +95,7 @@ void cxMempoolFree(CxMempool *pool);
 cx_attr_nodiscard
 cx_attr_malloc
 cx_attr_dealloc(cxMempoolFree, 1)
+cx_attr_export
 CxMempool *cxMempoolCreate(size_t capacity, cx_destructor_func destr);
 
 /**
@@ -102,7 +104,7 @@ CxMempool *cxMempoolCreate(size_t capacity, cx_destructor_func destr);
  * @param capacity (@c size_t) the initial capacity of the pool
  * @return (@c CxMempool*) the created memory pool or @c NULL if allocation failed
  */
-#define cxBasicMempoolCreate(capacity) cxMempoolCreate(capacity, NULL)
+#define cxMempoolCreateSimple(capacity) cxMempoolCreate(capacity, NULL)
 
 /**
  * Sets the destructor function for a specific allocated memory object.
@@ -114,6 +116,7 @@ CxMempool *cxMempoolCreate(size_t capacity, cx_destructor_func destr);
  * @param fnc the destructor function
  */
 cx_attr_nonnull
+cx_attr_export
 void cxMempoolSetDestructor(
         void *memory,
         cx_destructor_func fnc
@@ -128,6 +131,7 @@ void cxMempoolSetDestructor(
  * @param memory the object allocated in the pool
  */
 cx_attr_nonnull
+cx_attr_export
 void cxMempoolRemoveDestructor(void *memory);
 
 /**
@@ -145,6 +149,7 @@ void cxMempoolRemoveDestructor(void *memory);
  * @retval non-zero failure
  */
 cx_attr_nonnull
+cx_attr_export
 int cxMempoolRegister(
         CxMempool *pool,
         void *memory,
index 722bb641ac8a75d20739f623c6dbe1c01847c843..f02a80fb9457d12b196c9b9175fe5c3f89c635a7 100644 (file)
@@ -56,6 +56,7 @@ extern "C" {
 /**
  * The maximum string length that fits into stack memory.
  */
+cx_attr_export
 extern const unsigned cx_printf_sbo_size;
 
 /**
@@ -71,6 +72,7 @@ extern const unsigned cx_printf_sbo_size;
 cx_attr_nonnull_arg(1, 2, 3)
 cx_attr_printf(3, 4)
 cx_attr_cstr_arg(3)
+cx_attr_export
 int cx_fprintf(
         void *stream,
         cx_write_func wfc,
@@ -91,6 +93,7 @@ int cx_fprintf(
  */
 cx_attr_nonnull
 cx_attr_cstr_arg(3)
+cx_attr_export
 int cx_vfprintf(
         void *stream,
         cx_write_func wfc,
@@ -115,6 +118,7 @@ int cx_vfprintf(
 cx_attr_nonnull_arg(1, 2)
 cx_attr_printf(2, 3)
 cx_attr_cstr_arg(2)
+cx_attr_export
 cxmutstr cx_asprintf_a(
         const CxAllocator *allocator,
         const char *fmt,
@@ -153,6 +157,7 @@ cxmutstr cx_asprintf_a(
  */
 cx_attr_nonnull
 cx_attr_cstr_arg(2)
+cx_attr_export
 cxmutstr cx_vasprintf_a(
         const CxAllocator *allocator,
         const char *fmt,
@@ -185,7 +190,7 @@ cxmutstr cx_vasprintf_a(
  * @see cxBufferWrite()
  */
 #define cx_bprintf(buffer, fmt, ...) cx_fprintf((void*)buffer, \
-    (cx_write_func) cxBufferWrite, fmt, __VA_ARGS__)
+    cxBufferWriteFunc, fmt, __VA_ARGS__)
 
 
 /**
@@ -222,6 +227,7 @@ cxmutstr cx_vasprintf_a(
 cx_attr_nonnull_arg(1, 2, 3, 4)
 cx_attr_printf(4, 5)
 cx_attr_cstr_arg(4)
+cx_attr_export
 int cx_sprintf_a(
         CxAllocator *alloc,
         char **str,
@@ -266,6 +272,7 @@ cx_attr_nonnull
 cx_attr_cstr_arg(4)
 cx_attr_access_rw(2)
 cx_attr_access_rw(3)
+cx_attr_export
 int cx_vsprintf_a(
         CxAllocator *alloc,
         char **str,
@@ -324,6 +331,7 @@ cx_attr_cstr_arg(5)
 cx_attr_access_rw(2)
 cx_attr_access_rw(3)
 cx_attr_access_rw(4)
+cx_attr_export
 int cx_sprintf_sa(
         CxAllocator *alloc,
         char *buf,
@@ -378,6 +386,7 @@ int cx_sprintf_sa(
  */
 cx_attr_nonnull
 cx_attr_cstr_arg(5)
+cx_attr_export
 int cx_vsprintf_sa(
         CxAllocator *alloc,
         char *buf,
index 128aceec55d4439614e738e38a54e0374722df8e..619229f906e37df086022dfe47be8f88e3e2d0ff 100644 (file)
@@ -58,12 +58,6 @@ struct cx_properties_config_s {
      */
     char delimiter;
 
-    /**
-     * The character, when appearing at the end of a line, continues that line.
-     * This is '\' by default.
-     */
-    // char continuation; // TODO: line continuation in properties
-
     /**
      * The first comment character.
      * This is '#' by default.
@@ -81,6 +75,15 @@ struct cx_properties_config_s {
      * This is not set by default.
      */
     char comment3;
+
+    /*
+     * The character, when appearing at the end of a line, continues that line.
+     * This is '\' by default.
+     */
+    /**
+     * Reserved for future use.
+     */
+    char continuation;
 };
 
 /**
@@ -91,6 +94,7 @@ typedef struct cx_properties_config_s CxPropertiesConfig;
 /**
  * Default properties configuration.
  */
+cx_attr_export
 extern const CxPropertiesConfig cx_properties_config_default;
 
 /**
@@ -327,6 +331,7 @@ struct cx_properties_source_s {
  * @see cxPropertiesInitDefault()
  */
 cx_attr_nonnull
+cx_attr_export
 void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config);
 
 /**
@@ -341,6 +346,7 @@ void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config);
  * @param prop the properties interface
  */
 cx_attr_nonnull
+cx_attr_export
 void cxPropertiesDestroy(CxProperties *prop);
 
 /**
@@ -390,6 +396,7 @@ static inline void cxPropertiesReset(CxProperties *prop) {
  */
 cx_attr_nonnull
 cx_attr_access_r(2, 3)
+cx_attr_export
 int cxPropertiesFilln(
         CxProperties *prop,
         const char *buf,
@@ -495,6 +502,7 @@ static inline int cx_properties_fill_str(
  * @param capacity the capacity of the stack memory
  */
 cx_attr_nonnull
+cx_attr_export
 void cxPropertiesUseStack(
         CxProperties *prop,
         char *buf,
@@ -533,6 +541,7 @@ void cxPropertiesUseStack(
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 CxPropertiesStatus cxPropertiesNext(
         CxProperties *prop,
         cxstring *key,
@@ -553,6 +562,7 @@ CxPropertiesStatus cxPropertiesNext(
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 CxPropertiesSink cxPropertiesMapSink(CxMap *map);
 
 /**
@@ -563,6 +573,7 @@ CxPropertiesSink cxPropertiesMapSink(CxMap *map);
  * @see cxPropertiesLoad()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxPropertiesSource cxPropertiesStringSource(cxstring str);
 
 /**
@@ -576,6 +587,7 @@ CxPropertiesSource cxPropertiesStringSource(cxstring str);
 cx_attr_nonnull
 cx_attr_nodiscard
 cx_attr_access_r(1, 2)
+cx_attr_export
 CxPropertiesSource cxPropertiesCstrnSource(const char *str, size_t len);
 
 /**
@@ -591,6 +603,7 @@ CxPropertiesSource cxPropertiesCstrnSource(const char *str, size_t len);
 cx_attr_nonnull
 cx_attr_nodiscard
 cx_attr_cstr_arg(1)
+cx_attr_export
 CxPropertiesSource cxPropertiesCstrSource(const char *str);
 
 /**
@@ -605,6 +618,7 @@ CxPropertiesSource cxPropertiesCstrSource(const char *str);
 cx_attr_nonnull
 cx_attr_nodiscard
 cx_attr_access_r(1)
+cx_attr_export
 CxPropertiesSource cxPropertiesFileSource(FILE *file, size_t chunk_size);
 
 
@@ -616,6 +630,11 @@ CxPropertiesSource cxPropertiesFileSource(FILE *file, size_t chunk_size);
  * the return value will be #CX_PROPERTIES_NO_ERROR.
  * When the source was consumed but no k/v-pairs were found, the return value
  * will be #CX_PROPERTIES_NO_DATA.
+ * In case the source data ends unexpectedly, the #CX_PROPERTIES_INCOMPLETE_DATA
+ * is returned. In that case you should call this function again with the same
+ * sink and either an updated source or the same source if the source is able to
+ * yield the missing data.
+ *
  * The other result codes apply, according to their description.
  *
  * @param prop the properties interface
@@ -626,11 +645,13 @@ CxPropertiesSource cxPropertiesFileSource(FILE *file, size_t chunk_size);
  * @retval CX_PROPERTIES_READ_FAILED reading from the source failed
  * @retval CX_PROPERTIES_SINK_FAILED sinking the properties into the sink failed
  * @retval CX_PROPERTIES_NO_DATA the source did not provide any key/value pairs
+ * @retval CX_PROPERTIES_INCOMPLETE_DATA the source did not provide enough data
  * @retval CX_PROPERTIES_INVALID_EMPTY_KEY the properties data contains an illegal empty key
  * @retval CX_PROPERTIES_INVALID_MISSING_DELIMITER the properties data contains a line without delimiter
  * @retval CX_PROPERTIES_BUFFER_ALLOC_FAILED an internal allocation was necessary but failed
  */
 cx_attr_nonnull
+cx_attr_export
 CxPropertiesStatus cxPropertiesLoad(
         CxProperties *prop,
         CxPropertiesSink sink,
index abb1e78d9d194f16adbaef883028a140b1ea4aed..3cc35faa17ce68360a22dec9abf351d9bdd7e4f6 100644 (file)
@@ -65,6 +65,7 @@ cx_attr_nonnull_arg(1, 2, 3, 4)
 cx_attr_access_r(1)
 cx_attr_access_w(2)
 cx_attr_access_w(5)
+cx_attr_export
 size_t cx_stream_bncopy(
         void *src,
         void *dest,
@@ -106,6 +107,7 @@ size_t cx_stream_bncopy(
 cx_attr_nonnull
 cx_attr_access_r(1)
 cx_attr_access_w(2)
+cx_attr_export
 size_t cx_stream_ncopy(
         void *src,
         void *dest,
index 5614425bb95dca982c5e9a330f34f644041cecb2..64c8dbaa0260f6f3f9756a8a079441c6df9a93c2 100644 (file)
@@ -42,6 +42,7 @@
 /**
  * The maximum length of the "needle" in cx_strstr() that can use SBO.
  */
+cx_attr_export
 extern const unsigned cx_strstr_sbo_size;
 
 /**
@@ -51,7 +52,6 @@ struct cx_mutstr_s {
     /**
      * A pointer to the string.
      * @note The string is not necessarily @c NULL terminated.
-     * Always use the length.
      */
     char *ptr;
     /** The length of the string */
@@ -70,7 +70,6 @@ struct cx_string_s {
     /**
      * A pointer to the immutable string.
      * @note The string is not necessarily @c NULL terminated.
-     * Always use the length.
      */
     const char *ptr;
     /** The length of the string */
@@ -175,6 +174,7 @@ extern "C" {
 cx_attr_nonnull
 cx_attr_nodiscard
 cx_attr_cstr_arg(1)
+cx_attr_export
 cxmutstr cx_mutstr(char *cstring);
 
 /**
@@ -195,6 +195,7 @@ cxmutstr cx_mutstr(char *cstring);
  */
 cx_attr_nodiscard
 cx_attr_access_rw(1, 2)
+cx_attr_export
 cxmutstr cx_mutstrn(
         char *cstring,
         size_t length
@@ -218,6 +219,7 @@ cxmutstr cx_mutstrn(
 cx_attr_nonnull
 cx_attr_nodiscard
 cx_attr_cstr_arg(1)
+cx_attr_export
 cxstring cx_str(const char *cstring);
 
 
@@ -239,6 +241,7 @@ cxstring cx_str(const char *cstring);
  */
 cx_attr_nodiscard
 cx_attr_access_r(1, 2)
+cx_attr_export
 cxstring cx_strn(
         const char *cstring,
         size_t length
@@ -298,7 +301,8 @@ static inline cxstring cx_strcast_c(cxstring str) {
 /**
  * Passes the pointer in this string to @c free().
  *
- * The pointer in the struct is set to @c NULL and the length is set to zero.
+ * The pointer in the struct is set to @c NULL and the length is set to zero
+ * which means that this function protects you against double-free.
  *
  * @note There is no implementation for cxstring, because it is unlikely that
  * you ever have a <code>const char*</code> you are really supposed to free.
@@ -306,12 +310,14 @@ static inline cxstring cx_strcast_c(cxstring str) {
  *
  * @param str the string to free
  */
+cx_attr_export
 void cx_strfree(cxmutstr *str);
 
 /**
  * Passes the pointer in this string to the allocators free function.
  *
- * The pointer in the struct is set to @c NULL and the length is set to zero.
+ * The pointer in the struct is set to @c NULL and the length is set to zero
+ * which means that this function protects you against double-free.
  *
  * @note There is no implementation for cxstring, because it is unlikely that
  * you ever have a <code>const char*</code> you are really supposed to free.
@@ -321,6 +327,7 @@ void cx_strfree(cxmutstr *str);
  * @param str the string to free
  */
 cx_attr_nonnull_arg(1)
+cx_attr_export
 void cx_strfree_a(
         const CxAllocator *alloc,
         cxmutstr *str
@@ -339,6 +346,7 @@ void cx_strfree_a(
  * @return the accumulated length of all strings
  */
 cx_attr_nodiscard
+cx_attr_export
 size_t cx_strlen(
         size_t count,
         ...
@@ -368,6 +376,7 @@ size_t cx_strlen(
  */
 cx_attr_nodiscard
 cx_attr_nonnull
+cx_attr_export
 cxmutstr cx_strcat_ma(
         const CxAllocator *alloc,
         cxmutstr str,
@@ -456,6 +465,7 @@ cx_strcat_ma(cxDefaultAllocator, str, count, __VA_ARGS__)
  * @see cx_strsubsl_m()
  */
 cx_attr_nodiscard
+cx_attr_export
 cxstring cx_strsubs(
         cxstring string,
         size_t start
@@ -481,6 +491,7 @@ cxstring cx_strsubs(
  * @see cx_strsubsl_m()
  */
 cx_attr_nodiscard
+cx_attr_export
 cxstring cx_strsubsl(
         cxstring string,
         size_t start,
@@ -503,6 +514,7 @@ cxstring cx_strsubsl(
  * @see cx_strsubsl()
  */
 cx_attr_nodiscard
+cx_attr_export
 cxmutstr cx_strsubs_m(
         cxmutstr string,
         size_t start
@@ -528,6 +540,7 @@ cxmutstr cx_strsubs_m(
  * @see cx_strsubsl()
  */
 cx_attr_nodiscard
+cx_attr_export
 cxmutstr cx_strsubsl_m(
         cxmutstr string,
         size_t start,
@@ -547,6 +560,7 @@ cxmutstr cx_strsubsl_m(
  * @see cx_strchr_m()
  */
 cx_attr_nodiscard
+cx_attr_export
 cxstring cx_strchr(
         cxstring string,
         int chr
@@ -565,6 +579,7 @@ cxstring cx_strchr(
  * @see cx_strchr()
  */
 cx_attr_nodiscard
+cx_attr_export
 cxmutstr cx_strchr_m(
         cxmutstr string,
         int chr
@@ -583,6 +598,7 @@ cxmutstr cx_strchr_m(
  * @see cx_strrchr_m()
  */
 cx_attr_nodiscard
+cx_attr_export
 cxstring cx_strrchr(
         cxstring string,
         int chr
@@ -601,6 +617,7 @@ cxstring cx_strrchr(
  * @see cx_strrchr()
  */
 cx_attr_nodiscard
+cx_attr_export
 cxmutstr cx_strrchr_m(
         cxmutstr string,
         int chr
@@ -623,6 +640,7 @@ cxmutstr cx_strrchr_m(
  * @see cx_strstr_m()
  */
 cx_attr_nodiscard
+cx_attr_export
 cxstring cx_strstr(
         cxstring haystack,
         cxstring needle
@@ -645,6 +663,7 @@ cxstring cx_strstr(
  * @see cx_strstr()
  */
 cx_attr_nodiscard
+cx_attr_export
 cxmutstr cx_strstr_m(
         cxmutstr haystack,
         cxstring needle
@@ -659,12 +678,13 @@ cxmutstr cx_strstr_m(
  * @param string the string to split
  * @param delim  the delimiter
  * @param limit the maximum number of split items
- * @param output a pre-allocated array of at least @p limit length
+ * @param output a preallocated array of at least @p limit length
  * @return the actual number of split items
  */
 cx_attr_nodiscard
 cx_attr_nonnull
 cx_attr_access_w(4, 3)
+cx_attr_export
 size_t cx_strsplit(
         cxstring string,
         cxstring delim,
@@ -694,6 +714,7 @@ size_t cx_strsplit(
 cx_attr_nodiscard
 cx_attr_nonnull
 cx_attr_access_w(5)
+cx_attr_export
 size_t cx_strsplit_a(
         const CxAllocator *allocator,
         cxstring string,
@@ -712,12 +733,13 @@ size_t cx_strsplit_a(
  * @param string the string to split
  * @param delim  the delimiter
  * @param limit the maximum number of split items
- * @param output a pre-allocated array of at least @p limit length
+ * @param output a preallocated array of at least @p limit length
  * @return the actual number of split items
  */
 cx_attr_nodiscard
 cx_attr_nonnull
 cx_attr_access_w(4, 3)
+cx_attr_export
 size_t cx_strsplit_m(
         cxmutstr string,
         cxstring delim,
@@ -747,6 +769,7 @@ size_t cx_strsplit_m(
 cx_attr_nodiscard
 cx_attr_nonnull
 cx_attr_access_w(5)
+cx_attr_export
 size_t cx_strsplit_ma(
         const CxAllocator *allocator,
         cxmutstr string,
@@ -764,6 +787,7 @@ size_t cx_strsplit_ma(
  * than @p s2, zero if both strings equal
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_strcmp(
         cxstring s1,
         cxstring s2
@@ -778,6 +802,7 @@ int cx_strcmp(
  * than @p s2, zero if both strings equal ignoring case
  */
 cx_attr_nodiscard
+cx_attr_export
 int cx_strcasecmp(
         cxstring s1,
         cxstring s2
@@ -795,6 +820,7 @@ int cx_strcasecmp(
  */
 cx_attr_nodiscard
 cx_attr_nonnull
+cx_attr_export
 int cx_strcmp_p(
         const void *s1,
         const void *s2
@@ -812,6 +838,7 @@ int cx_strcmp_p(
  */
 cx_attr_nodiscard
 cx_attr_nonnull
+cx_attr_export
 int cx_strcasecmp_p(
         const void *s1,
         const void *s2
@@ -832,26 +859,12 @@ int cx_strcasecmp_p(
  */
 cx_attr_nodiscard
 cx_attr_nonnull
-cxmutstr cx_strdup_a(
+cx_attr_export
+cxmutstr cx_strdup_a_(
         const CxAllocator *allocator,
         cxstring string
 );
 
-/**
- * Creates a duplicate of the specified string.
- *
- * The new string will contain a copy allocated by standard
- * @c malloc(). So developers @em must pass the return value to cx_strfree().
- *
- * @note The returned string is guaranteed to be zero-terminated.
- *
- * @param string (@c cxstring) the string to duplicate
- * @return (@c cxmutstr) a duplicate of the string
- * @see cx_strdup_a()
- */
-#define cx_strdup(string) cx_strdup_a(cxDefaultAllocator, string)
-
-
 /**
  * Creates a duplicate of the specified string.
  *
@@ -860,11 +873,13 @@ cxmutstr cx_strdup_a(
  * @note The returned string is guaranteed to be zero-terminated.
  *
  * @param allocator (@c CxAllocator*) the allocator to use
- * @param string (@c cxmutstr) the string to duplicate
+ * @param string the string to duplicate
  * @return (@c cxmutstr) a duplicate of the string
- * @see cx_strdup_m()
+ * @see cx_strdup()
+ * @see cx_strfree_a()
  */
-#define cx_strdup_ma(allocator, string) cx_strdup_a(allocator, cx_strcast(string))
+#define cx_strdup_a(allocator, string) \
+    cx_strdup_a_((allocator), cx_strcast((string)))
 
 /**
  * Creates a duplicate of the specified string.
@@ -874,11 +889,12 @@ cxmutstr cx_strdup_a(
  *
  * @note The returned string is guaranteed to be zero-terminated.
  *
- * @param string (@c cxmutstr) the string to duplicate
+ * @param string the string to duplicate
  * @return (@c cxmutstr) a duplicate of the string
- * @see cx_strdup_ma()
+ * @see cx_strdup_a()
+ * @see cx_strfree()
  */
-#define cx_strdup_m(string) cx_strdup_a(cxDefaultAllocator, cx_strcast(string))
+#define cx_strdup(string) cx_strdup_a_(cxDefaultAllocator, string)
 
 /**
  * Omits leading and trailing spaces.
@@ -890,6 +906,7 @@ cxmutstr cx_strdup_a(
  * @return the trimmed string
  */
 cx_attr_nodiscard
+cx_attr_export
 cxstring cx_strtrim(cxstring string);
 
 /**
@@ -902,6 +919,7 @@ cxstring cx_strtrim(cxstring string);
  * @return the trimmed string
  */
 cx_attr_nodiscard
+cx_attr_export
 cxmutstr cx_strtrim_m(cxmutstr string);
 
 /**
@@ -913,6 +931,7 @@ cxmutstr cx_strtrim_m(cxmutstr string);
  * @c false otherwise
  */
 cx_attr_nodiscard
+cx_attr_export
 bool cx_strprefix(
         cxstring string,
         cxstring prefix
@@ -927,6 +946,7 @@ bool cx_strprefix(
  * @c false otherwise
  */
 cx_attr_nodiscard
+cx_attr_export
 bool cx_strsuffix(
         cxstring string,
         cxstring suffix
@@ -941,6 +961,7 @@ bool cx_strsuffix(
  * @c false otherwise
  */
 cx_attr_nodiscard
+cx_attr_export
 bool cx_strcaseprefix(
         cxstring string,
         cxstring prefix
@@ -955,35 +976,15 @@ bool cx_strcaseprefix(
  * @c false otherwise
  */
 cx_attr_nodiscard
+cx_attr_export
 bool cx_strcasesuffix(
         cxstring string,
         cxstring suffix
 );
 
 /**
- * Converts the string to lower case.
- *
- * The change is made in-place. If you want a copy, use cx_strdup(), first.
- *
- * @param string the string to modify
- * @see cx_strdup()
- */
-void cx_strlower(cxmutstr string);
-
-/**
- * Converts the string to upper case.
- *
- * The change is made in-place. If you want a copy, use cx_strdup(), first.
- *
- * @param string the string to modify
- * @see cx_strdup()
- */
-void cx_strupper(cxmutstr string);
-
-/**
- * Replaces a pattern in a string with another string.
+ * Replaces a string with another string.
  *
- * The pattern is taken literally and is no regular expression.
  * Replaces at most @p replmax occurrences.
  *
  * The returned string will be allocated by @p allocator and is guaranteed
@@ -994,25 +995,25 @@ void cx_strupper(cxmutstr string);
  *
  * @param allocator the allocator to use
  * @param str the string where replacements should be applied
- * @param pattern the pattern to search for
+ * @param search the string to search for
  * @param replacement the replacement string
  * @param replmax maximum number of replacements
  * @return the resulting string after applying the replacements
  */
 cx_attr_nodiscard
 cx_attr_nonnull
+cx_attr_export
 cxmutstr cx_strreplacen_a(
         const CxAllocator *allocator,
         cxstring str,
-        cxstring pattern,
+        cxstring search,
         cxstring replacement,
         size_t replmax
 );
 
 /**
- * Replaces a pattern in a string with another string.
+ * Replaces a string with another string.
  *
- * The pattern is taken literally and is no regular expression.
  * Replaces at most @p replmax occurrences.
  *
  * The returned string will be allocated by @c malloc() and is guaranteed
@@ -1022,18 +1023,16 @@ cxmutstr cx_strreplacen_a(
  * the returned string will be empty.
  *
  * @param str (@c cxstring) the string where replacements should be applied
- * @param pattern (@c cxstring) the pattern to search for
+ * @param search (@c cxstring) the string to search for
  * @param replacement (@c cxstring) the replacement string
  * @param replmax (@c size_t) maximum number of replacements
  * @return (@c cxmutstr) the resulting string after applying the replacements
  */
-#define cx_strreplacen(str, pattern, replacement, replmax) \
-cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, replmax)
+#define cx_strreplacen(str, search, replacement, replmax) \
+cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, replmax)
 
 /**
- * Replaces a pattern in a string with another string.
- *
- * The pattern is taken literally and is no regular expression.
+ * Replaces a string with another string.
  *
  * The returned string will be allocated by @p allocator and is guaranteed
  * to be zero-terminated.
@@ -1043,18 +1042,15 @@ cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, replmax)
  *
  * @param allocator (@c CxAllocator*) the allocator to use
  * @param str (@c cxstring) the string where replacements should be applied
- * @param pattern (@c cxstring) the pattern to search for
+ * @param search (@c cxstring) the string to search for
  * @param replacement (@c cxstring) the replacement string
  * @return (@c cxmutstr) the resulting string after applying the replacements
  */
-#define cx_strreplace_a(allocator, str, pattern, replacement) \
-cx_strreplacen_a(allocator, str, pattern, replacement, SIZE_MAX)
+#define cx_strreplace_a(allocator, str, search, replacement) \
+cx_strreplacen_a(allocator, str, search, replacement, SIZE_MAX)
 
 /**
- * Replaces a pattern in a string with another string.
- *
- * The pattern is taken literally and is no regular expression.
- * Replaces at most @p replmax occurrences.
+ * Replaces a string with another string.
  *
  * The returned string will be allocated by @c malloc() and is guaranteed
  * to be zero-terminated.
@@ -1063,12 +1059,12 @@ cx_strreplacen_a(allocator, str, pattern, replacement, SIZE_MAX)
  * the returned string will be empty.
  *
  * @param str (@c cxstring) the string where replacements should be applied
- * @param pattern (@c cxstring) the pattern to search for
+ * @param search (@c cxstring) the string to search for
  * @param replacement (@c cxstring) the replacement string
  * @return (@c cxmutstr) the resulting string after applying the replacements
  */
-#define cx_strreplace(str, pattern, replacement) \
-cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, SIZE_MAX)
+#define cx_strreplace(str, search, replacement) \
+cx_strreplacen_a(cxDefaultAllocator, str, search, replacement, SIZE_MAX)
 
 /**
  * Creates a string tokenization context.
@@ -1079,26 +1075,23 @@ cx_strreplacen_a(cxDefaultAllocator, str, pattern, replacement, SIZE_MAX)
  * @return a new string tokenization context
  */
 cx_attr_nodiscard
-CxStrtokCtx cx_strtok(
+cx_attr_export
+CxStrtokCtx cx_strtok_(
         cxstring str,
         cxstring delim,
         size_t limit
 );
 
 /**
-* Creates a string tokenization context for a mutable string.
-*
-* @param str the string to tokenize
-* @param delim the delimiter (must not be empty)
-* @param limit the maximum number of tokens that shall be returned
-* @return a new string tokenization context
-*/
-cx_attr_nodiscard
-CxStrtokCtx cx_strtok_m(
-        cxmutstr str,
-        cxstring delim,
-        size_t limit
-);
+ * Creates a string tokenization context.
+ *
+ * @param str the string to tokenize
+ * @param delim the delimiter string (must not be empty)
+ * @param limit (@c size_t) the maximum number of tokens that shall be returned
+ * @return (@c CxStrtokCtx) a new string tokenization context
+ */
+#define cx_strtok(str, delim, limit) \
+    cx_strtok_(cx_strcast((str)), cx_strcast((delim)), (limit))
 
 /**
  * Returns the next token.
@@ -1113,6 +1106,7 @@ CxStrtokCtx cx_strtok_m(
 cx_attr_nonnull
 cx_attr_nodiscard
 cx_attr_access_w(2)
+cx_attr_export
 bool cx_strtok_next(
         CxStrtokCtx *ctx,
         cxstring *token
@@ -1122,6 +1116,8 @@ bool cx_strtok_next(
  * Returns the next token of a mutable string.
  *
  * The token will point to the source string.
+ *
+ * @attention
  * If the context was not initialized over a mutable string, modifying
  * the data of the returned token is undefined behavior.
  *
@@ -1133,6 +1129,7 @@ bool cx_strtok_next(
 cx_attr_nonnull
 cx_attr_nodiscard
 cx_attr_access_w(2)
+cx_attr_export
 bool cx_strtok_next_m(
         CxStrtokCtx *ctx,
         cxmutstr *token
@@ -1147,6 +1144,7 @@ bool cx_strtok_next_m(
  */
 cx_attr_nonnull
 cx_attr_access_r(2, 3)
+cx_attr_export
 void cx_strtok_delim(
         CxStrtokCtx *ctx,
         const cxstring *delim,
@@ -1158,90 +1156,21 @@ void cx_strtok_delim(
  * ------------------------------------------------------------------------- */
 
 /**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtoll_lc(cxstring str, long long *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtoull_lc(cxstring str, unsigned long long *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
- */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep);
-/**
- * @copydoc cx_strtouz_lc()
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
  */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep);
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep);
 
 /**
  * Converts a string to a number.
@@ -1257,120 +1186,43 @@ int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupse
  * @retval zero success
  * @retval non-zero conversion was not possible
  */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtouz_lc(cxstring str, size_t *output, int base, const char *groupsep);
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep);
 
 /**
- * Converts a string to a single precision floating point number.
+ * Converts a string to a number.
  *
  * The function returns non-zero when conversion is not possible.
- * In that case the function sets errno to EINVAL when the reason is an invalid character.
- * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
- *
- * The decimal separator is assumed to be a dot character.
- * The comma character is treated as group separator and ignored during parsing.
- * If you want to choose a different format, use cx_strtof_lc().
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
  *
  * @param str the string to convert
- * @param output a pointer to the float variable where the result shall be stored
- * @param decsep the decimal separator
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
  * @param groupsep each character in this string is treated as group separator and ignored during conversion
  * @retval zero success
  * @retval non-zero conversion was not possible
  */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtof_lc(cxstring str, float *output, char decsep, const char *groupsep);
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep);
 
 /**
- * Converts a string to a double precision floating point number.
+ * Converts a string to a number.
  *
  * The function returns non-zero when conversion is not possible.
- * In that case the function sets errno to EINVAL when the reason is an invalid character.
- * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
- *
- * The decimal separator is assumed to be a dot character.
- * The comma character is treated as group separator and ignored during parsing.
- * If you want to choose a different format, use cx_strtof_lc().
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
  *
  * @param str the string to convert
- * @param output a pointer to the float variable where the result shall be stored
- * @param decsep the decimal separator
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
  * @param groupsep each character in this string is treated as group separator and ignored during conversion
  * @retval zero success
  * @retval non-zero conversion was not possible
  */
-cx_attr_access_w(2) cx_attr_nonnull_arg(2)
-int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep);
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep);
 
-#ifndef CX_STR_IMPLEMENTATION
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc(cx_strcast(str), output, base, groupsep)
-/**
- * @copydoc cx_strtouz_lc()
- */
-#define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc(cx_strcast(str), output, base, groupsep)
 /**
  * Converts a string to a number.
  *
@@ -1385,76 +1237,26 @@ int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep
  * @retval zero success
  * @retval non-zero conversion was not possible
  */
-#define cx_strtouz_lc(str, output, base, groupsep) cx_strtouz_lc(cx_strcast(str), output, base, groupsep)
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep);
 
 /**
- * @copydoc cx_strtouz()
- */
-#define cx_strtos(str, output, base) cx_strtos_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtoi(str, output, base) cx_strtoi_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtol(str, output, base) cx_strtol_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtoll(str, output, base) cx_strtoll_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtoi8(str, output, base) cx_strtoi8_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtoi16(str, output, base) cx_strtoi16_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtoi32(str, output, base) cx_strtoi32_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtoi64(str, output, base) cx_strtoi64_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtoz(str, output, base) cx_strtoz_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtous(str, output, base) cx_strtous_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtou(str, output, base) cx_strtou_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtoul(str, output, base) cx_strtoul_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtoull(str, output, base) cx_strtoull_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtou8(str, output, base) cx_strtou8_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtou16(str, output, base) cx_strtou16_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
- */
-#define cx_strtou32(str, output, base) cx_strtou32_lc(str, output, base, ",")
-/**
- * @copydoc cx_strtouz()
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
  */
-#define cx_strtou64(str, output, base) cx_strtou64_lc(str, output, base, ",")
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep);
+
 /**
  * Converts a string to a number.
  *
@@ -1462,90 +1264,863 @@ int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep
  * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
  * It sets errno to ERANGE when the target datatype is too small.
  *
- * The comma character is treated as group separator and ignored during parsing.
- * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtouz_lc()).
- *
  * @param str the string to convert
  * @param output a pointer to the integer variable where the result shall be stored
  * @param base 2, 8, 10, or 16
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
  * @retval zero success
  * @retval non-zero conversion was not possible
  */
-#define cx_strtouz(str, output, base) cx_strtouz_lc(str, output, base, ",")
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep);
 
 /**
- * Converts a string to a single precision floating point number.
+ * Converts a string to a number.
  *
  * The function returns non-zero when conversion is not possible.
- * In that case the function sets errno to EINVAL when the reason is an invalid character.
- * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
- *
- * The decimal separator is assumed to be a dot character.
- * The comma character is treated as group separator and ignored during parsing.
- * If you want to choose a different format, use cx_strtof_lc().
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
  *
  * @param str the string to convert
- * @param output a pointer to the float variable where the result shall be stored
- * @param decsep the decimal separator
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
  * @param groupsep each character in this string is treated as group separator and ignored during conversion
  * @retval zero success
  * @retval non-zero conversion was not possible
  */
-#define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc(cx_strcast(str), output, decsep, groupsep)
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep);
+
 /**
- * Converts a string to a double precision floating point number.
+ * Converts a string to a number.
  *
  * The function returns non-zero when conversion is not possible.
- * In that case the function sets errno to EINVAL when the reason is an invalid character.
- *
- * The decimal separator is assumed to be a dot character.
- * The comma character is treated as group separator and ignored during parsing.
- * If you want to choose a different format, use cx_strtof_lc().
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
  *
  * @param str the string to convert
- * @param output a pointer to the double variable where the result shall be stored
- * @param decsep the decimal separator
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
  * @param groupsep each character in this string is treated as group separator and ignored during conversion
  * @retval zero success
  * @retval non-zero conversion was not possible
  */
-#define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc(cx_strcast(str), output, decsep, groupsep)
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep);
 
 /**
- * Converts a string to a single precision floating point number.
+ * Converts a string to a number.
  *
  * The function returns non-zero when conversion is not possible.
- * In that case the function sets errno to EINVAL when the reason is an invalid character.
- * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
- *
- * The decimal separator is assumed to be a dot character.
- * The comma character is treated as group separator and ignored during parsing.
- * If you want to choose a different format, use cx_strtof_lc().
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
  *
  * @param str the string to convert
- * @param output a pointer to the float variable where the result shall be stored
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
  * @retval zero success
  * @retval non-zero conversion was not possible
  */
-#define cx_strtof(str, output) cx_strtof_lc(str, output, '.', ",")
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep);
+
 /**
- * Converts a string to a double precision floating point number.
+ * Converts a string to a number.
  *
  * The function returns non-zero when conversion is not possible.
- * In that case the function sets errno to EINVAL when the reason is an invalid character.
- *
- * The decimal separator is assumed to be a dot character.
- * The comma character is treated as group separator and ignored during parsing.
- * If you want to choose a different format, use cx_strtof_lc().
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
  *
  * @param str the string to convert
- * @param output a pointer to the double variable where the result shall be stored
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
  * @retval zero success
  * @retval non-zero conversion was not possible
  */
-#define cx_strtod(str, output) cx_strtod_lc(str, output, '.', ",")
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep);
 
-#endif
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep);
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep);
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep);
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep);
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep);
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep);
+
+/**
+ * Converts a string to a single precision floating point number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character.
+ * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the float variable where the result shall be stored
+ * @param decsep the decimal separator
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep);
+
+/**
+ * Converts a string to a double precision floating point number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character.
+ * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the float variable where the result shall be stored
+ * @param decsep the decimal separator
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+cx_attr_access_w(2) cx_attr_nonnull_arg(2) cx_attr_export
+int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep);
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtos_lc(str, output, base, groupsep) cx_strtos_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoi_lc(str, output, base, groupsep) cx_strtoi_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtol_lc(str, output, base, groupsep) cx_strtol_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoll_lc(str, output, base, groupsep) cx_strtoll_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoi8_lc(str, output, base, groupsep) cx_strtoi8_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoi16_lc(str, output, base, groupsep) cx_strtoi16_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoi32_lc(str, output, base, groupsep) cx_strtoi32_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoi64_lc(str, output, base, groupsep) cx_strtoi64_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtous_lc(str, output, base, groupsep) cx_strtous_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtou_lc(str, output, base, groupsep) cx_strtou_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoul_lc(str, output, base, groupsep) cx_strtoul_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoull_lc(str, output, base, groupsep) cx_strtoull_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtou8_lc(str, output, base, groupsep) cx_strtou8_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtou16_lc(str, output, base, groupsep) cx_strtou16_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtou32_lc(str, output, base, groupsep) cx_strtou32_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtou64_lc(str, output, base, groupsep) cx_strtou64_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @param groupsep (@c const @c char*) each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoz_lc(str, output, base, groupsep) cx_strtoz_lc_(cx_strcast(str), output, base, groupsep)
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtos(str, output, base) cx_strtos_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoi(str, output, base) cx_strtoi_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtol(str, output, base) cx_strtol_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoll(str, output, base) cx_strtoll_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoi8(str, output, base) cx_strtoi8_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoi16(str, output, base) cx_strtoi16_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoi32(str, output, base) cx_strtoi32_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoi64(str, output, base) cx_strtoi64_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoz(str, output, base) cx_strtoz_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtous(str, output, base) cx_strtous_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtou(str, output, base) cx_strtou_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoul(str, output, base) cx_strtoul_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtoull(str, output, base) cx_strtoull_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtou8(str, output, base) cx_strtou8_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtou16(str, output, base) cx_strtou16_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtou32(str, output, base) cx_strtou32_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character or an unsupported base.
+ * It sets errno to ERANGE when the target datatype is too small.
+ *
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose the set of group separators, use the @c _lc variant of this function (e.g. cx_strtoz_lc()).
+ *
+ * @param str the string to convert
+ * @param output a pointer to the integer variable where the result shall be stored
+ * @param base 2, 8, 10, or 16
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtou64(str, output, base) cx_strtou64_lc_(cx_strcast(str), output, base, ",")
+
+/**
+ * Converts a string to a single precision floating point number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character.
+ * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the float variable where the result shall be stored
+ * @param decsep the decimal separator
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtof_lc(str, output, decsep, groupsep) cx_strtof_lc_(cx_strcast(str), output, decsep, groupsep)
+
+/**
+ * Converts a string to a double precision floating point number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character.
+ *
+ * @param str the string to convert
+ * @param output a pointer to the double variable where the result shall be stored
+ * @param decsep the decimal separator
+ * @param groupsep each character in this string is treated as group separator and ignored during conversion
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtod_lc(str, output, decsep, groupsep) cx_strtod_lc_(cx_strcast(str), output, decsep, groupsep)
+
+/**
+ * Converts a string to a single precision floating point number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character.
+ * It sets errno to ERANGE when the necessary representation would exceed the limits defined in libc's float.h.
+ *
+ * The decimal separator is assumed to be a dot character.
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose a different format, use cx_strtof_lc().
+ *
+ * @param str the string to convert
+ * @param output a pointer to the float variable where the result shall be stored
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtof(str, output) cx_strtof_lc_(cx_strcast(str), output, '.', ",")
+
+/**
+ * Converts a string to a double precision floating point number.
+ *
+ * The function returns non-zero when conversion is not possible.
+ * In that case the function sets errno to EINVAL when the reason is an invalid character.
+ *
+ * The decimal separator is assumed to be a dot character.
+ * The comma character is treated as group separator and ignored during parsing.
+ * If you want to choose a different format, use cx_strtof_lc().
+ *
+ * @param str the string to convert
+ * @param output a pointer to the double variable where the result shall be stored
+ * @retval zero success
+ * @retval non-zero conversion was not possible
+ */
+#define cx_strtod(str, output) cx_strtod_lc_(cx_strcast(str), output, '.', ",")
 
 #ifdef __cplusplus
 } // extern "C"
index 515e7dba705b2304eeeab0426feac189b0174020..b7f49b5127ed8d2ad6f337127524dfc4e7634377 100644 (file)
@@ -263,6 +263,7 @@ static inline void cxTreeVisitorDispose(CxTreeVisitor *visitor) {
  * @see cx_tree_unlink()
  */
 cx_attr_nonnull
+cx_attr_export
 void cx_tree_link(
         void *parent,
         void *node,
@@ -288,6 +289,7 @@ void cx_tree_link(
  * @see cx_tree_link()
  */
 cx_attr_nonnull
+cx_attr_export
 void cx_tree_unlink(
         void *node,
         ptrdiff_t loc_parent,
@@ -387,6 +389,7 @@ typedef int (*cx_tree_search_func)(const void *node, const void *new_node);
  */
 cx_attr_nonnull
 cx_attr_access_w(5)
+cx_attr_export
 int cx_tree_search_data(
         const void *root,
         size_t depth,
@@ -423,6 +426,7 @@ int cx_tree_search_data(
  */
 cx_attr_nonnull
 cx_attr_access_w(5)
+cx_attr_export
 int cx_tree_search(
         const void *root,
         size_t depth,
@@ -454,6 +458,7 @@ int cx_tree_search(
  * @see cxTreeIteratorDispose()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxTreeIterator cx_tree_iterator(
         void *root,
         bool visit_on_exit,
@@ -480,6 +485,7 @@ CxTreeIterator cx_tree_iterator(
  * @see cxTreeVisitorDispose()
  */
 cx_attr_nodiscard
+cx_attr_export
 CxTreeVisitor cx_tree_visitor(
         void *root,
         ptrdiff_t loc_children,
@@ -505,6 +511,7 @@ typedef void *(*cx_tree_node_create_func)(const void *, void *);
  * This variable is used by #cx_tree_add_array() and #cx_tree_add_iter() to
  * implement optimized insertion of multiple elements into a tree.
  */
+cx_attr_export
 extern unsigned int cx_tree_add_look_around_depth;
 
 /**
@@ -547,6 +554,7 @@ extern unsigned int cx_tree_add_look_around_depth;
  */
 cx_attr_nonnull_arg(1, 3, 4, 6, 7)
 cx_attr_access_w(6)
+cx_attr_export
 size_t cx_tree_add_iter(
         struct cx_iterator_base_s *iter,
         size_t num,
@@ -601,6 +609,7 @@ size_t cx_tree_add_iter(
  */
 cx_attr_nonnull_arg(1, 4, 5, 7, 8)
 cx_attr_access_w(7)
+cx_attr_export
 size_t cx_tree_add_array(
         const void *src,
         size_t num,
@@ -664,6 +673,7 @@ size_t cx_tree_add_array(
  */
 cx_attr_nonnull_arg(1, 2, 3, 5, 6)
 cx_attr_access_w(5)
+cx_attr_export
 int cx_tree_add(
         const void *src,
         cx_tree_search_func sfunc,
@@ -894,6 +904,7 @@ typedef struct cx_tree_s CxTree;
  * @see cxTreeFree()
  */
 cx_attr_nonnull
+cx_attr_export
 void cxTreeDestroySubtree(CxTree *tree, void *node);
 
 
@@ -932,6 +943,7 @@ void cxTreeDestroySubtree(CxTree *tree, void *node);
  *
  * @param tree the tree to free
  */
+cx_attr_export
 void cxTreeFree(CxTree *tree);
 
 /**
@@ -962,6 +974,7 @@ cx_attr_nonnull_arg(2, 3, 4)
 cx_attr_nodiscard
 cx_attr_malloc
 cx_attr_dealloc(cxTreeFree, 1)
+cx_attr_export
 CxTree *cxTreeCreate(
         const CxAllocator *allocator,
         cx_tree_node_create_func create_func,
@@ -1022,6 +1035,7 @@ cx_attr_nonnull_arg(2)
 cx_attr_nodiscard
 cx_attr_malloc
 cx_attr_dealloc(cxTreeFree, 1)
+cx_attr_export
 CxTree *cxTreeCreateWrapped(
         const CxAllocator *allocator,
         void *root,
@@ -1067,7 +1081,7 @@ static inline int cxTreeInsert(
 cx_attr_nonnull
 static inline size_t cxTreeInsertIter(
         CxTree *tree,
-        struct cx_iterator_base_s *iter,
+        CxIteratorBase *iter,
         size_t n
 ) {
     return tree->cl->insert_many(tree, iter, n);
@@ -1158,6 +1172,7 @@ static inline void *cxTreeFindInSubtree(
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 size_t cxTreeSubtreeSize(CxTree *tree, void *subtree_root);
 
 /**
@@ -1169,6 +1184,7 @@ size_t cxTreeSubtreeSize(CxTree *tree, void *subtree_root);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 size_t cxTreeSubtreeDepth(CxTree *tree, void *subtree_root);
 
 /**
@@ -1179,6 +1195,7 @@ size_t cxTreeSubtreeDepth(CxTree *tree, void *subtree_root);
  */
 cx_attr_nonnull
 cx_attr_nodiscard
+cx_attr_export
 size_t cxTreeDepth(CxTree *tree);
 
 /**
@@ -1267,6 +1284,7 @@ static inline CxTreeVisitor cxTreeVisit(CxTree *tree) {
  * @see cxTreeAddChildNode()
  */
 cx_attr_nonnull
+cx_attr_export
 void cxTreeSetParent(
         CxTree *tree,
         void *parent,
@@ -1289,6 +1307,7 @@ void cxTreeSetParent(
  * @see cxTreeSetParent()
  */
 cx_attr_nonnull
+cx_attr_export
 void cxTreeAddChildNode(
         CxTree *tree,
         void *parent,
@@ -1313,6 +1332,7 @@ void cxTreeAddChildNode(
  * @see cxTreeInsert()
  */
 cx_attr_nonnull
+cx_attr_export
 int cxTreeAddChild(
         CxTree *tree,
         void *parent,
@@ -1353,6 +1373,7 @@ typedef void (*cx_tree_relink_func)(
  * @return zero on success, non-zero if @p node is the root node of the tree
  */
 cx_attr_nonnull_arg(1, 2)
+cx_attr_export
 int cxTreeRemoveNode(
         CxTree *tree,
         void *node,
@@ -1371,6 +1392,7 @@ int cxTreeRemoveNode(
  * @param node the node to remove
  */
 cx_attr_nonnull
+cx_attr_export
 void cxTreeRemoveSubtree(CxTree *tree, void *node);
 
 /**
@@ -1392,6 +1414,7 @@ void cxTreeRemoveSubtree(CxTree *tree, void *node);
  * @return zero on success, non-zero if @p node is the root node of the tree
  */
 cx_attr_nonnull_arg(1, 2)
+cx_attr_export
 int cxTreeDestroyNode(
         CxTree *tree,
         void *node,
index fa9eba4ccee66d03897543a925ec0116ccc8f178..1721e8c9575989158b389b87a3e8fe5bd4ac6ff4 100644 (file)
@@ -103,7 +103,8 @@ static int cx_hash_map_put(
 
     if (elm != NULL && elm->key.hash == hash && elm->key.len == key.len &&
         memcmp(elm->key.data, key.data, key.len) == 0) {
-        // overwrite existing element
+        // overwrite existing element, but call destructors first
+        cx_invoke_destructor(map, elm->data);
         if (map->collection.store_pointer) {
             memcpy(elm->data, &value, sizeof(void *));
         } else {
@@ -252,22 +253,22 @@ static int cx_hash_map_remove(
 }
 
 static void *cx_hash_map_iter_current_entry(const void *it) {
-    const struct cx_iterator_s *iter = it;
-    // struct has to have a compatible signature
-    return (struct cx_map_entry_s *) &(iter->kv_data);
+    const CxMapIterator *iter = it;
+    // we have to cast away const, because of the signature
+    return (void*) &iter->entry;
 }
 
 static void *cx_hash_map_iter_current_key(const void *it) {
-    const struct cx_iterator_s *iter = it;
-    struct cx_hash_map_element_s *elm = iter->elem_handle;
+    const CxMapIterator *iter = it;
+    struct cx_hash_map_element_s *elm = iter->elem;
     return &elm->key;
 }
 
 static void *cx_hash_map_iter_current_value(const void *it) {
-    const struct cx_iterator_s *iter = it;
-    const struct cx_hash_map_s *map = iter->src_handle.c;
-    struct cx_hash_map_element_s *elm = iter->elem_handle;
-    if (map->base.collection.store_pointer) {
+    const CxMapIterator *iter = it;
+    const CxMap *map = iter->map.c;
+    struct cx_hash_map_element_s *elm = iter->elem;
+    if (map->collection.store_pointer) {
         return *(void **) elm->data;
     } else {
         return elm->data;
@@ -275,14 +276,15 @@ static void *cx_hash_map_iter_current_value(const void *it) {
 }
 
 static bool cx_hash_map_iter_valid(const void *it) {
-    const struct cx_iterator_s *iter = it;
-    return iter->elem_handle != NULL;
+    const CxMapIterator *iter = it;
+    return iter->elem != NULL;
 }
 
 static void cx_hash_map_iter_next(void *it) {
-    struct cx_iterator_s *iter = it;
-    struct cx_hash_map_element_s *elm = iter->elem_handle;
-    struct cx_hash_map_s *map = iter->src_handle.m;
+    CxMapIterator *iter = it;
+    CxMap *map = iter->map.m;
+    struct cx_hash_map_s *hmap = (struct cx_hash_map_s *) map;
+    struct cx_hash_map_element_s *elm = iter->elem;
 
     // remove current element, if asked
     if (iter->base.remove) {
@@ -295,18 +297,18 @@ static void cx_hash_map_iter_next(void *it) {
 
         // search the previous element
         struct cx_hash_map_element_s *prev = NULL;
-        if (map->buckets[iter->slot] != elm) {
-            prev = map->buckets[iter->slot];
+        if (hmap->buckets[iter->slot] != elm) {
+            prev = hmap->buckets[iter->slot];
             while (prev->next != elm) {
                 prev = prev->next;
             }
         }
 
         // destroy
-        cx_invoke_destructor((struct cx_map_s *) map, elm->data);
+        cx_invoke_destructor(map, elm->data);
 
         // unlink
-        cx_hash_map_unlink(map, iter->slot, prev, elm);
+        cx_hash_map_unlink(hmap, iter->slot, prev, elm);
 
         // advance
         elm = next;
@@ -317,32 +319,31 @@ static void cx_hash_map_iter_next(void *it) {
     }
 
     // search the next bucket, if required
-    while (elm == NULL && ++iter->slot < map->bucket_count) {
-        elm = map->buckets[iter->slot];
+    while (elm == NULL && ++iter->slot < hmap->bucket_count) {
+        elm = hmap->buckets[iter->slot];
     }
-
-    // fill the struct with the next element
-    iter->elem_handle = elm;
-    if (elm == NULL) {
-        iter->kv_data.key = NULL;
-        iter->kv_data.value = NULL;
-    } else {
-        iter->kv_data.key = &elm->key;
-        if (map->base.collection.store_pointer) {
-            iter->kv_data.value = *(void **) elm->data;
+    iter->elem = elm;
+
+    // copy data to a location where the iterator can point to
+    // we need to do it here, because the iterator function call
+    // must not modify the iterator (the parameter is const)
+    if (elm != NULL) {
+        iter->entry.key = &elm->key;
+        if (iter->map.c->collection.store_pointer) {
+            iter->entry.value = *(void **) elm->data;
         } else {
-            iter->kv_data.value = elm->data;
+            iter->entry.value = elm->data;
         }
     }
 }
 
-static CxIterator cx_hash_map_iterator(
+static CxMapIterator cx_hash_map_iterator(
         const CxMap *map,
         enum cx_map_iterator_type type
 ) {
-    CxIterator iter;
+    CxMapIterator iter;
 
-    iter.src_handle.c = map;
+    iter.map.c = map;
     iter.elem_count = map->collection.size;
 
     switch (type) {
@@ -376,17 +377,15 @@ static CxIterator cx_hash_map_iterator(
         while (elm == NULL) {
             elm = hash_map->buckets[++iter.slot];
         }
-        iter.elem_handle = elm;
-        iter.kv_data.key = &elm->key;
+        iter.elem = elm;
+        iter.entry.key = &elm->key;
         if (map->collection.store_pointer) {
-            iter.kv_data.value = *(void **) elm->data;
+            iter.entry.value = *(void **) elm->data;
         } else {
-            iter.kv_data.value = elm->data;
+            iter.entry.value = elm->data;
         }
     } else {
-        iter.elem_handle = NULL;
-        iter.kv_data.key = NULL;
-        iter.kv_data.value = NULL;
+        iter.elem = NULL;
     }
 
     return iter;
@@ -433,11 +432,10 @@ CxMap *cxHashMapCreate(
     map->base.collection.allocator = allocator;
 
     if (itemsize > 0) {
-        map->base.collection.store_pointer = false;
         map->base.collection.elem_size = itemsize;
     } else {
-        map->base.collection.store_pointer = true;
         map->base.collection.elem_size = sizeof(void *);
+        map->base.collection.store_pointer = true;
     }
 
     return (CxMap *) map;
index 72c7811da00484eeb8e2fd6b47030b6ce1660a91..4993d97569a32fbc97a2699da796f826e08efac6 100644 (file)
  */
 
 #include "cx/json.h"
-#include "cx/compare.h"
 
 #include <string.h>
-#include <ctype.h>
 #include <assert.h>
 #include <stdio.h>
-#include <errno.h>
 #include <inttypes.h>
 
 /*
@@ -135,6 +132,16 @@ static void token_destroy(CxJsonToken *token) {
     }
 }
 
+static bool json_isdigit(char c) {
+    // TODO: remove once UCX has public API for this
+    return c >= '0' && c <= '9';
+}
+
+static bool json_isspace(char c) {
+    // TODO: remove once UCX has public API for this
+    return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v' || c == '\f';
+}
+
 static int num_isexp(const char *content, size_t length, size_t pos) {
     if (pos >= length) {
         return 0;
@@ -143,7 +150,7 @@ static int num_isexp(const char *content, size_t length, size_t pos) {
     int ok = 0;
     for (size_t i = pos; i < length; i++) {
         char c = content[i];
-        if (isdigit(c)) {
+        if (json_isdigit(c)) {
             ok = 1;
         } else if (i == pos) {
             if (!(c == '+' || c == '-')) {
@@ -160,7 +167,7 @@ static int num_isexp(const char *content, size_t length, size_t pos) {
 static CxJsonTokenType token_numbertype(const char *content, size_t length) {
     if (length == 0) return CX_JSON_TOKEN_ERROR;
 
-    if (content[0] != '-' && !isdigit(content[0])) {
+    if (content[0] != '-' && !json_isdigit(content[0])) {
         return CX_JSON_TOKEN_ERROR;
     }
 
@@ -173,7 +180,7 @@ static CxJsonTokenType token_numbertype(const char *content, size_t length) {
             type = CX_JSON_TOKEN_NUMBER;
         } else if (content[i] == 'e' || content[i] == 'E') {
             return num_isexp(content, length, i + 1) ? CX_JSON_TOKEN_NUMBER : CX_JSON_TOKEN_ERROR;
-        } else if (!isdigit(content[i])) {
+        } else if (!json_isdigit(content[i])) {
             return CX_JSON_TOKEN_ERROR; // char is not a digit, decimal separator or exponent sep
         }
     }
@@ -237,7 +244,7 @@ static CxJsonTokenType char2ttype(char c) {
             return CX_JSON_TOKEN_STRING;
         }
         default: {
-            if (isspace(c)) {
+            if (json_isspace(c)) {
                 return CX_JSON_TOKEN_SPACE;
             }
         }
@@ -254,7 +261,10 @@ static enum cx_json_status token_parse_next(CxJson *json, CxJsonToken *result) {
 
     // current token type and start index
     CxJsonTokenType ttype = json->uncompleted.tokentype;
-    size_t token_start = json->buffer.pos;
+    size_t token_part_start = json->buffer.pos;
+
+    bool escape_end_of_string = ttype == CX_JSON_TOKEN_STRING
+        && json->uncompleted.content.ptr[json->uncompleted.content.length-1] == '\\';
 
     for (size_t i = json->buffer.pos; i < json->buffer.size; i++) {
         char c = json->buffer.space[i];
@@ -268,7 +278,7 @@ static enum cx_json_status token_parse_next(CxJson *json, CxJsonToken *result) {
                 } else if (ctype == CX_JSON_TOKEN_STRING) {
                     // begin string
                     ttype = CX_JSON_TOKEN_STRING;
-                    token_start = i;
+                    token_part_start = i;
                 } else if (ctype != CX_JSON_NO_TOKEN) {
                     // single-char token
                     json->buffer.pos = i + 1;
@@ -276,12 +286,12 @@ static enum cx_json_status token_parse_next(CxJson *json, CxJsonToken *result) {
                     return CX_JSON_NO_ERROR;
                 } else {
                     ttype = CX_JSON_TOKEN_LITERAL; // number or literal
-                    token_start = i;
+                    token_part_start = i;
                 }
             } else {
                 // finish token
                 if (ctype != CX_JSON_NO_TOKEN) {
-                    *result = token_create(json, false, token_start, i);
+                    *result = token_create(json, false, token_part_start, i);
                     if (result->tokentype == CX_JSON_NO_TOKEN) {
                         return CX_JSON_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE
                     }
@@ -294,18 +304,18 @@ static enum cx_json_status token_parse_next(CxJson *json, CxJsonToken *result) {
             }
         } else {
             // currently inside a string
-            if (json->tokenizer_escape) {
-                json->tokenizer_escape = false;
+            if (escape_end_of_string) {
+                escape_end_of_string = false;
             } else {
                 if (c == '"') {
-                    *result = token_create(json, true, token_start, i + 1);
+                    *result = token_create(json, true, token_part_start, i + 1);
                     if (result->tokentype == CX_JSON_NO_TOKEN) {
                         return CX_JSON_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE
                     }
                     json->buffer.pos = i + 1;
                     return CX_JSON_NO_ERROR;
                 } else if (c == '\\') {
-                    json->tokenizer_escape = true;
+                    escape_end_of_string = true;
                 }
             }
         }
@@ -313,13 +323,13 @@ static enum cx_json_status token_parse_next(CxJson *json, CxJsonToken *result) {
 
     if (ttype != CX_JSON_NO_TOKEN) {
         // uncompleted token
-        size_t uncompleted_len = json->buffer.size - token_start;
+        size_t uncompleted_len = json->buffer.size - token_part_start;
         if (json->uncompleted.tokentype == CX_JSON_NO_TOKEN) {
             // current token is uncompleted
             // save current token content
             CxJsonToken uncompleted = {
                 ttype, true,
-                cx_strdup(cx_strn(json->buffer.space + token_start, uncompleted_len))
+                cx_strdup(cx_strn(json->buffer.space + token_part_start, uncompleted_len))
             };
             if (uncompleted.content.ptr == NULL) {
                 return CX_JSON_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE
@@ -330,7 +340,7 @@ static enum cx_json_status token_parse_next(CxJson *json, CxJsonToken *result) {
             // combine the uncompleted token with the current token
             assert(json->uncompleted.allocated);
             cxmutstr str = cx_strcat_m(json->uncompleted.content, 1,
-                cx_strn(json->buffer.space + token_start, uncompleted_len));
+                cx_strn(json->buffer.space + token_part_start, uncompleted_len));
             if (str.ptr == NULL) {
                 return CX_JSON_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE
             }
@@ -343,9 +353,75 @@ static enum cx_json_status token_parse_next(CxJson *json, CxJsonToken *result) {
     return CX_JSON_INCOMPLETE_DATA;
 }
 
+// converts a Unicode codepoint to utf8
+static unsigned codepoint_to_utf8(uint32_t codepoint, char *output_buf) {
+    if (codepoint <= 0x7F) {
+        *output_buf = (char)codepoint;
+        return 1;
+    } else if (codepoint <= 0x7FF) {
+        output_buf[0] = (char)(0xC0 | ((codepoint >> 6) & 0x1F));
+        output_buf[1] = (char)(0x80 | (codepoint & 0x3F));
+        return 2;
+    } else if (codepoint <= 0xFFFF) {
+        output_buf[0] = (char)(0xE0 | ((codepoint >> 12) & 0x0F));
+        output_buf[1] = (char)(0x80 | ((codepoint >> 6) & 0x3F));
+        output_buf[2] = (char)(0x80 | (codepoint & 0x3F));
+        return 3;
+    } else if (codepoint <= 0x10FFFF) {
+        output_buf[0] = (char)(0xF0 | ((codepoint >> 18) & 0x07));
+        output_buf[1] = (char)(0x80 | ((codepoint >> 12) & 0x3F));
+        output_buf[2] = (char)(0x80 | ((codepoint >> 6) & 0x3F));
+        output_buf[3] = (char)(0x80 | (codepoint & 0x3F));
+        return 4;
+    }
+    
+    return 0; // LCOV_EXCL_LINE
+}
+
+// converts a utf16 surrogate pair to utf8
+static inline uint32_t utf16pair_to_codepoint(uint16_t c0, uint16_t c1) {
+    return ((c0 - 0xD800) << 10) + (c1 - 0xDC00) + 0x10000;
+}
+
+static unsigned unescape_unicode_string(cxstring str, char *utf8buf) {
+    // str is supposed to start with "\uXXXX" or "\uXXXX\uXXXX"
+    // remaining bytes in the string are ignored (str may be larger!)
+
+    if (str.length < 6 || str.ptr[0] != '\\' || str.ptr[1] != 'u') {
+        return 0;
+    }
+
+    unsigned utf8len = 0;
+    cxstring ustr1 = { str.ptr + 2, 4};
+    uint16_t utf16a, utf16b;
+    if (!cx_strtou16_lc(ustr1, &utf16a, 16, "")) {
+        uint32_t codepoint;
+        if (utf16a < 0xD800 || utf16a > 0xE000) {
+            // character is in the Basic Multilingual Plane
+            // and encoded as a single utf16 char
+            codepoint = utf16a;
+            utf8len = codepoint_to_utf8(codepoint, utf8buf);
+        } else if (utf16a >= 0xD800 && utf16a <= 0xDBFF) {
+            // character is encoded as a surrogate pair
+            // get next 6 bytes
+            if (str.length >= 12) {
+                if (str.ptr[6] == '\\' && str.ptr[7] == 'u') {
+                    cxstring ustr2 = { str.ptr+8, 4 };
+                    if (!cx_strtou16_lc(ustr2, &utf16b, 16, "")
+                            && utf16b >= 0xDC00 && utf16b <= 0xDFFF) {
+                        codepoint = utf16pair_to_codepoint(utf16a, utf16b);
+                        utf8len = codepoint_to_utf8(codepoint, utf8buf);
+                    }
+                }
+            }
+        }
+    }
+    return utf8len;
+}
+
 static cxmutstr unescape_string(const CxAllocator *a, cxmutstr str) {
-    // TODO: support more escape sequences
-    // we know that the unescaped string will be shorter by at least 2 chars
+    // note: this function expects that str contains the enclosing quotes!
+
     cxmutstr result;
     result.length = 0;
     result.ptr = cxMalloc(a, str.length - 1);
@@ -358,9 +434,45 @@ static cxmutstr unescape_string(const CxAllocator *a, cxmutstr str) {
             u = false;
             if (c == 'n') {
                 c = '\n';
+            } else if (c == '"') {
+                c = '"';
             } else if (c == 't') {
                 c = '\t';
+            } else if (c == 'r') {
+                c = '\r';
+            } else if (c == '\\') {
+                c = '\\';
+            } else if (c == '/') {
+                c = '/'; // always unescape, we don't need settings here
+            } else if (c == 'f') {
+                c = '\f';
+            } else if (c == 'b') {
+                c = '\b';
+            } else if (c == 'u') {
+                char utf8buf[4];
+                unsigned utf8len = unescape_unicode_string(
+                    cx_strn(str.ptr + i - 1, str.length + 1 - i),
+                    utf8buf
+                );
+                if(utf8len > 0) {
+                    i += utf8len < 4 ? 4 : 10;
+                    // add all bytes from utf8buf except the last char
+                    // to the result (last char will be added below)
+                    utf8len--;
+                    c = utf8buf[utf8len];
+                    for (unsigned x = 0; x < utf8len; x++) {
+                        result.ptr[result.length++] = utf8buf[x];
+                    }
+                } else {
+                    // decoding failed, ignore the entire sequence
+                    result.ptr[result.length++] = '\\';
+                }
+            } else {
+                // TODO: discuss the behavior for unrecognized escape sequences
+                //       most parsers throw an error here - we just ignore it
+                result.ptr[result.length++] = '\\';
             }
+
             result.ptr[result.length++] = c;
         } else {
             if (c == '\\') {
@@ -375,7 +487,60 @@ static cxmutstr unescape_string(const CxAllocator *a, cxmutstr str) {
     return result;
 }
 
-static CxJsonValue* create_json_value(CxJson *json, CxJsonValueType type) {
+static cxmutstr escape_string(cxmutstr str, bool escape_slash) {
+    // note: this function produces the string without enclosing quotes
+    // the reason is that we don't want to allocate memory just for that
+    CxBuffer buf = {0};
+
+    bool all_printable = true;
+    for (size_t i = 0; i < str.length; i++) {
+        unsigned char c = str.ptr[i];
+        bool escape = c < 0x20 || c == '\\' || c == '"'
+            || (escape_slash && c == '/');
+
+        if (all_printable && escape) {
+            size_t capa = str.length + 32;
+            char *space = malloc(capa);
+            if (space == NULL) return cx_mutstrn(NULL, 0);
+            cxBufferInit(&buf, space, capa, NULL, CX_BUFFER_AUTO_EXTEND);
+            cxBufferWrite(str.ptr, 1, i, &buf);
+            all_printable = false;
+        }
+        if (escape) {
+            cxBufferPut(&buf, '\\');
+            if (c == '\"') {
+                cxBufferPut(&buf, '\"');
+            } else if (c == '\n') {
+                cxBufferPut(&buf, 'n');
+            } else if (c == '\t') {
+                cxBufferPut(&buf, 't');
+            } else if (c == '\r') {
+                cxBufferPut(&buf, 'r');
+            } else if (c == '\\') {
+                cxBufferPut(&buf, '\\');
+            } else if (c == '/') {
+                cxBufferPut(&buf, '/');
+            } else if (c == '\f') {
+                cxBufferPut(&buf, 'f');
+            } else if (c == '\b') {
+                cxBufferPut(&buf, 'b');
+            } else {
+                char code[6];
+                snprintf(code, sizeof(code), "u%04x", (unsigned int) c);
+                cxBufferPutString(&buf, code);
+            }
+        } else if (!all_printable) {
+            cxBufferPut(&buf, c);
+        }
+    }
+    if (!all_printable) {
+        str = cx_mutstrn(buf.space, buf.size);
+    }
+    cxBufferDestroy(&buf);
+    return str;
+}
+
+static CxJsonValue* json_create_value(CxJson *json, CxJsonValueType type) {
     CxJsonValue *v = cxCalloc(json->allocator, 1, sizeof(CxJsonValue));
     if (v == NULL) return NULL; // LCOV_EXCL_LINE
 
@@ -541,21 +706,21 @@ static enum cx_json_status json_parse(CxJson *json) {
         json_add_state(json, 10 + state);
         switch (token.tokentype) {
             case CX_JSON_TOKEN_BEGIN_ARRAY: {
-                if (create_json_value(json, CX_JSON_ARRAY) == NULL) {
+                if (json_create_value(json, CX_JSON_ARRAY) == NULL) {
                     return_rec(CX_JSON_VALUE_ALLOC_FAILED); // LCOV_EXCL_LINE
                 }
                 json_add_state(json, JP_STATE_VALUE_BEGIN_AR);
                 return_rec(CX_JSON_NO_ERROR);
             }
             case CX_JSON_TOKEN_BEGIN_OBJECT: {
-                if (create_json_value(json, CX_JSON_OBJECT) == NULL) {
+                if (json_create_value(json, CX_JSON_OBJECT) == NULL) {
                     return_rec(CX_JSON_VALUE_ALLOC_FAILED); // LCOV_EXCL_LINE
                 }
                 json_add_state(json, JP_STATE_OBJ_NAME_OR_CLOSE);
                 return_rec(CX_JSON_NO_ERROR);
             }
             case CX_JSON_TOKEN_STRING: {
-                if ((vbuf = create_json_value(json, CX_JSON_STRING)) == NULL) {
+                if ((vbuf = json_create_value(json, CX_JSON_STRING)) == NULL) {
                     return_rec(CX_JSON_VALUE_ALLOC_FAILED); // LCOV_EXCL_LINE
                 }
                 cxmutstr str = unescape_string(json->allocator, token.content);
@@ -568,7 +733,7 @@ static enum cx_json_status json_parse(CxJson *json) {
             case CX_JSON_TOKEN_INTEGER:
             case CX_JSON_TOKEN_NUMBER: {
                 int type = token.tokentype == CX_JSON_TOKEN_INTEGER ? CX_JSON_INTEGER : CX_JSON_NUMBER;
-                if (NULL == (vbuf = create_json_value(json, type))) {
+                if (NULL == (vbuf = json_create_value(json, type))) {
                     return_rec(CX_JSON_VALUE_ALLOC_FAILED); // LCOV_EXCL_LINE
                 }
                 if (type == CX_JSON_INTEGER) {
@@ -583,7 +748,7 @@ static enum cx_json_status json_parse(CxJson *json) {
                 return_rec(CX_JSON_NO_ERROR);
             }
             case CX_JSON_TOKEN_LITERAL: {
-                if ((vbuf = create_json_value(json, CX_JSON_LITERAL)) == NULL) {
+                if ((vbuf = json_create_value(json, CX_JSON_LITERAL)) == NULL) {
                     return_rec(CX_JSON_VALUE_ALLOC_FAILED); // LCOV_EXCL_LINE
                 }
                 if (0 == cx_strcmp(cx_strcast(token.content), cx_str("true"))) {
@@ -734,6 +899,7 @@ void cxJsonValueFree(CxJsonValue *value) {
 }
 
 CxJsonValue* cxJsonCreateObj(const CxAllocator* allocator) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;
@@ -755,6 +921,7 @@ CxJsonValue* cxJsonCreateObj(const CxAllocator* allocator) {
 }
 
 CxJsonValue* cxJsonCreateArr(const CxAllocator* allocator) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;
@@ -765,6 +932,7 @@ CxJsonValue* cxJsonCreateArr(const CxAllocator* allocator) {
 }
 
 CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;
@@ -774,6 +942,7 @@ CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num) {
 }
 
 CxJsonValue* cxJsonCreateInteger(const CxAllocator* allocator, int64_t num) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;
@@ -787,6 +956,7 @@ CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, const char* str) {
 }
 
 CxJsonValue* cxJsonCreateCxString(const CxAllocator* allocator, cxstring str) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;
@@ -798,6 +968,7 @@ CxJsonValue* cxJsonCreateCxString(const CxAllocator* allocator, cxstring str) {
 }
 
 CxJsonValue* cxJsonCreateLiteral(const CxAllocator* allocator, CxJsonLiteral lit) {
+    if (allocator == NULL) allocator = cxDefaultAllocator;
     CxJsonValue* v = cxMalloc(allocator, sizeof(CxJsonValue));
     if (v == NULL) return NULL;
     v->allocator = allocator;
@@ -808,7 +979,7 @@ CxJsonValue* cxJsonCreateLiteral(const CxAllocator* allocator, CxJsonLiteral lit
 
 // LCOV_EXCL_START
 // never called as long as malloc() does not return NULL
-static void cx_json_arr_free_temp(CxJsonValue** values, size_t count) {
+static void json_arr_free_temp(CxJsonValue** values, size_t count) {
     for (size_t i = 0; i < count; i++) {
         if (values[i] == NULL) break;
         cxJsonValueFree(values[i]);
@@ -822,7 +993,7 @@ int cxJsonArrAddNumbers(CxJsonValue* arr, const double* num, size_t count) {
     if (values == NULL) return -1;
     for (size_t i = 0; i < count; i++) {
         values[i] = cxJsonCreateNumber(arr->allocator, num[i]);
-        if (values[i] == NULL) { cx_json_arr_free_temp(values, count); return -1; }
+        if (values[i] == NULL) { json_arr_free_temp(values, count); return -1; }
     }
     int ret = cxJsonArrAddValues(arr, values, count);
     free(values);
@@ -834,7 +1005,7 @@ int cxJsonArrAddIntegers(CxJsonValue* arr, const int64_t* num, size_t count) {
     if (values == NULL) return -1;
     for (size_t i = 0; i < count; i++) {
         values[i] = cxJsonCreateInteger(arr->allocator, num[i]);
-        if (values[i] == NULL) { cx_json_arr_free_temp(values, count); return -1; }
+        if (values[i] == NULL) { json_arr_free_temp(values, count); return -1; }
     }
     int ret = cxJsonArrAddValues(arr, values, count);
     free(values);
@@ -846,7 +1017,7 @@ int cxJsonArrAddStrings(CxJsonValue* arr, const char* const* str, size_t count)
     if (values == NULL) return -1;
     for (size_t i = 0; i < count; i++) {
         values[i] = cxJsonCreateString(arr->allocator, str[i]);
-        if (values[i] == NULL) { cx_json_arr_free_temp(values, count); return -1; }
+        if (values[i] == NULL) { json_arr_free_temp(values, count); return -1; }
     }
     int ret = cxJsonArrAddValues(arr, values, count);
     free(values);
@@ -858,7 +1029,7 @@ int cxJsonArrAddCxStrings(CxJsonValue* arr, const cxstring* str, size_t count) {
     if (values == NULL) return -1;
     for (size_t i = 0; i < count; i++) {
         values[i] = cxJsonCreateCxString(arr->allocator, str[i]);
-        if (values[i] == NULL) { cx_json_arr_free_temp(values, count); return -1; }
+        if (values[i] == NULL) { json_arr_free_temp(values, count); return -1; }
     }
     int ret = cxJsonArrAddValues(arr, values, count);
     free(values);
@@ -870,7 +1041,7 @@ int cxJsonArrAddLiterals(CxJsonValue* arr, const CxJsonLiteral* lit, size_t coun
     if (values == NULL) return -1;
     for (size_t i = 0; i < count; i++) {
         values[i] = cxJsonCreateLiteral(arr->allocator, lit[i]);
-        if (values[i] == NULL) { cx_json_arr_free_temp(values, count); return -1; }
+        if (values[i] == NULL) { json_arr_free_temp(values, count); return -1; }
     }
     int ret = cxJsonArrAddValues(arr, values, count);
     free(values);
@@ -979,25 +1150,25 @@ CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name) {
     }
 }
 
-static const CxJsonWriter cx_json_writer_default = {
-    false,
-    true,
-    255,
-    false,
-    4
-};
-
 CxJsonWriter cxJsonWriterCompact(void) {
-    return cx_json_writer_default;
+    return (CxJsonWriter) {
+        false,
+        true,
+        6,
+        false,
+        4,
+        false
+    };
 }
 
 CxJsonWriter cxJsonWriterPretty(bool use_spaces) {
     return (CxJsonWriter) {
         true,
         true,
-        255,
+        6,
         use_spaces,
-        4
+        4,
+        false
     };
 }
 
@@ -1044,7 +1215,7 @@ int cx_json_write_rec(
     size_t actual = 0, expected = 0;
 
     // small buffer for number to string conversions
-    char numbuf[32];
+    char numbuf[40];
 
     // recursively write the values
     switch (value->type) {
@@ -1078,9 +1249,11 @@ int cx_json_write_rec(
 
                 // the name
                 actual += wfunc("\"", 1, 1, target);
-                // TODO: escape the string
-                actual += wfunc(member->name.ptr, 1,
-                    member->name.length, target);
+                cxmutstr name = escape_string(member->name, settings->escape_slash);
+                actual += wfunc(name.ptr, 1, name.length, target);
+                if (name.ptr != member->name.ptr) {
+                    cx_strfree(&name);
+                }
                 actual += wfunc("\"", 1, 1, target);
                 const char *obj_name_sep = ": ";
                 if (settings->pretty) {
@@ -1146,20 +1319,81 @@ int cx_json_write_rec(
         }
         case CX_JSON_STRING: {
             actual += wfunc("\"", 1, 1, target);
-            // TODO: escape the string
-            actual += wfunc(value->value.string.ptr, 1,
-                value->value.string.length, target);
+            cxmutstr str = escape_string(value->value.string, settings->escape_slash);
+            actual += wfunc(str.ptr, 1, str.length, target);
+            if (str.ptr != value->value.string.ptr) {
+                cx_strfree(&str);
+            }
             actual += wfunc("\"", 1, 1, target);
             expected += 2 + value->value.string.length;
             break;
         }
         case CX_JSON_NUMBER: {
-            // TODO: locale bullshit
-            // TODO: formatting settings
-            snprintf(numbuf, 32, "%g", value->value.number);
-            size_t len = strlen(numbuf);
-            actual += wfunc(numbuf, 1, len, target);
-            expected += len;
+            int precision = settings->frac_max_digits;
+            // because of the way how %g is defined, we need to
+            // double the precision and truncate ourselves
+            precision = 1 + (precision > 15 ? 30 : 2 * precision);
+            snprintf(numbuf, 40, "%.*g", precision, value->value.number);
+            char *dot, *exp;
+            unsigned char max_digits;
+            // find the decimal separator and hope that it's one of . or ,
+            dot = strchr(numbuf, '.');
+            if (dot == NULL) {
+                dot = strchr(numbuf, ',');
+            }
+            if (dot == NULL) {
+                // no decimal separator found
+                // output everything until a possible exponent
+                max_digits = 30;
+                dot = numbuf;
+            } else {
+                // found a decimal separator
+                // output everything until the separator
+                // and set max digits to what the settings say
+                size_t len = dot - numbuf;
+                actual += wfunc(numbuf, 1, len, target);
+                expected += len;
+                max_digits = settings->frac_max_digits;
+                if (max_digits > 15) {
+                    max_digits = 15;
+                }
+                // locale independent separator
+                if (max_digits > 0) {
+                    actual += wfunc(".", 1, 1, target);
+                    expected++;
+                }
+                dot++;
+            }
+            // find the exponent
+            exp = strchr(dot, 'e');
+            if (exp == NULL) {
+                // no exponent - output the rest
+                if (max_digits > 0) {
+                    size_t len = strlen(dot);
+                    if (len > max_digits) {
+                        len = max_digits;
+                    }
+                    actual += wfunc(dot, 1, len, target);
+                    expected += len;
+                }
+            } else {
+                // exponent found - truncate the frac digits
+                // and then output the rest
+                if (max_digits > 0) {
+                    size_t len = exp - dot - 1;
+                    if (len > max_digits) {
+                        len = max_digits;
+                    }
+                    actual += wfunc(dot, 1, len, target);
+                    expected += len;
+                }
+                actual += wfunc("e", 1, 1, target);
+                expected++;
+                exp++;
+                size_t len = strlen(exp);
+                actual += wfunc(exp, 1, len, target);
+                expected += len;
+            }
             break;
         }
         case CX_JSON_INTEGER: {
@@ -1201,12 +1435,13 @@ int cxJsonWrite(
     cx_write_func wfunc,
     const CxJsonWriter *settings
 ) {
-    if (settings == NULL) {
-        settings = &cx_json_writer_default;
-    }
     assert(target != NULL);
     assert(value != NULL);
     assert(wfunc != NULL);
 
+    CxJsonWriter writer_default = cxJsonWriterCompact();
+    if (settings == NULL) {
+        settings = &writer_default;
+    }
     return cx_json_write_rec(target, value, wfunc, settings, 0);
 }
index 19955f6c185d7459c260d19f0b957aa3ec4c2c77..3833d4426f0cac7393ceeb78e6c2d7b6088ac364 100644 (file)
@@ -56,48 +56,33 @@ void *cx_linked_list_at(
     return (void *) cur;
 }
 
-ssize_t cx_linked_list_find(
+void *cx_linked_list_find(
         const void *start,
         ptrdiff_t loc_advance,
         ptrdiff_t loc_data,
         cx_compare_func cmp_func,
-        const void *elem
-) {
-    void *dummy;
-    return cx_linked_list_find_node(
-            &dummy, start,
-            loc_advance, loc_data,
-            cmp_func, elem
-    );
-}
-
-ssize_t cx_linked_list_find_node(
-        void **result,
-        const void *start,
-        ptrdiff_t loc_advance,
-        ptrdiff_t loc_data,
-        cx_compare_func cmp_func,
-        const void *elem
+        const void *elem,
+        size_t *found_index
 ) {
-    assert(result != NULL);
     assert(start != NULL);
     assert(loc_advance >= 0);
     assert(loc_data >= 0);
     assert(cmp_func);
 
-    const void *node = start;
-    ssize_t index = 0;
+    void *node = (void*) start;
+    size_t index = 0;
     do {
         void *current = ll_data(node);
         if (cmp_func(current, elem) == 0) {
-            *result = (void *) node;
-            return index;
+            if (found_index != NULL) {
+                *found_index = index;
+            }
+            return node;
         }
         node = ll_advance(node);
         index++;
     } while (node != NULL);
-    *result = NULL;
-    return -1;
+    return NULL;
 }
 
 void *cx_linked_list_first(
@@ -811,11 +796,6 @@ static void cx_ll_clear(struct cx_list_s *list) {
     list->collection.size = 0;
 }
 
-#ifndef CX_LINKED_LIST_SWAP_SBO_SIZE
-#define CX_LINKED_LIST_SWAP_SBO_SIZE 128
-#endif
-const unsigned cx_linked_list_swap_sbo_size = CX_LINKED_LIST_SWAP_SBO_SIZE;
-
 static int cx_ll_swap(
         struct cx_list_s *list,
         size_t i,
@@ -894,41 +874,33 @@ static int cx_ll_swap(
         }
     }
 
-    if (list->collection.elem_size > CX_LINKED_LIST_SWAP_SBO_SIZE) {
-        cx_linked_list_node *prev = nleft->prev;
-        cx_linked_list_node *next = nright->next;
-        cx_linked_list_node *midstart = nleft->next;
-        cx_linked_list_node *midend = nright->prev;
+    cx_linked_list_node *prev = nleft->prev;
+    cx_linked_list_node *next = nright->next;
+    cx_linked_list_node *midstart = nleft->next;
+    cx_linked_list_node *midend = nright->prev;
 
-        if (prev == NULL) {
-            ll->begin = nright;
-        } else {
-            prev->next = nright;
-        }
-        nright->prev = prev;
-        if (midstart == nright) {
-            // special case: both nodes are adjacent
-            nright->next = nleft;
-            nleft->prev = nright;
-        } else {
-            // likely case: a chain is between the two nodes
-            nright->next = midstart;
-            midstart->prev = nright;
-            midend->next = nleft;
-            nleft->prev = midend;
-        }
-        nleft->next = next;
-        if (next == NULL) {
-            ll->end = nleft;
-        } else {
-            next->prev = nleft;
-        }
+    if (prev == NULL) {
+        ll->begin = nright;
+    } else {
+        prev->next = nright;
+    }
+    nright->prev = prev;
+    if (midstart == nright) {
+        // special case: both nodes are adjacent
+        nright->next = nleft;
+        nleft->prev = nright;
+    } else {
+        // likely case: a chain is between the two nodes
+        nright->next = midstart;
+        midstart->prev = nright;
+        midend->next = nleft;
+        nleft->prev = midend;
+    }
+    nleft->next = next;
+    if (next == NULL) {
+        ll->end = nleft;
     } else {
-        // swap payloads to avoid relinking
-        char buf[CX_LINKED_LIST_SWAP_SBO_SIZE];
-        memcpy(buf, nleft->payload, list->collection.elem_size);
-        memcpy(nleft->payload, nright->payload, list->collection.elem_size);
-        memcpy(nright->payload, buf, list->collection.elem_size);
+        next->prev = nleft;
     }
 
     return 0;
@@ -943,35 +915,30 @@ static void *cx_ll_at(
     return node == NULL ? NULL : node->payload;
 }
 
-static ssize_t cx_ll_find_remove(
+static size_t cx_ll_find_remove(
         struct cx_list_s *list,
         const void *elem,
         bool remove
 ) {
+    size_t index;
+    cx_linked_list *ll = ((cx_linked_list *) list);
+    cx_linked_list_node *node = cx_linked_list_find(
+            ll->begin,
+            CX_LL_LOC_NEXT, CX_LL_LOC_DATA,
+            list->collection.cmpfunc, elem,
+            &index
+    );
+    if (node == NULL) {
+        return list->collection.size;
+    }
     if (remove) {
-        cx_linked_list *ll = ((cx_linked_list *) list);
-        cx_linked_list_node *node;
-        ssize_t index = cx_linked_list_find_node(
-                (void **) &node,
-                ll->begin,
-                CX_LL_LOC_NEXT, CX_LL_LOC_DATA,
-                list->collection.cmpfunc, elem
-        );
-        if (node != NULL) {
-            cx_invoke_destructor(list, node->payload);
-            cx_linked_list_remove((void **) &ll->begin, (void **) &ll->end,
-                                  CX_LL_LOC_PREV, CX_LL_LOC_NEXT, node);
-            list->collection.size--;
-            cxFree(list->collection.allocator, node);
-        }
-        return index;
-    } else {
-        return cx_linked_list_find(
-                ((cx_linked_list *) list)->begin,
-                CX_LL_LOC_NEXT, CX_LL_LOC_DATA,
-                list->collection.cmpfunc, elem
-        );
+        cx_invoke_destructor(list, node->payload);
+        cx_linked_list_remove((void **) &ll->begin, (void **) &ll->end,
+                              CX_LL_LOC_PREV, CX_LL_LOC_NEXT, node);
+        list->collection.size--;
+        cxFree(list->collection.allocator, node);
     }
+    return index;
 }
 
 static void cx_ll_sort(struct cx_list_s *list) {
@@ -1138,17 +1105,8 @@ CxList *cxLinkedListCreate(
 
     cx_linked_list *list = cxCalloc(allocator, 1, sizeof(cx_linked_list));
     if (list == NULL) return NULL;
-
-    list->base.cl = &cx_linked_list_class;
-    list->base.collection.allocator = allocator;
-
-    if (elem_size > 0) {
-        list->base.collection.elem_size = elem_size;
-        list->base.collection.cmpfunc = comparator;
-    } else {
-        list->base.collection.cmpfunc = comparator == NULL ? cx_cmp_ptr : comparator;
-        cxListStorePointers((CxList *) list);
-    }
+    cx_list_init((CxList*)list, &cx_linked_list_class,
+            allocator, comparator, elem_size);
 
     return (CxList *) list;
 }
index 8fb18e695b95ddc1f07a8abf4fb84b4b34e5a4b8..daf6b9ecce5a897aec6a16292b419dcc2ab374a2 100644 (file)
@@ -128,13 +128,13 @@ static void *cx_pl_at(
     return ptr == NULL ? NULL : *ptr;
 }
 
-static ssize_t cx_pl_find_remove(
+static size_t cx_pl_find_remove(
         struct cx_list_s *list,
         const void *elem,
         bool remove
 ) {
     cx_pl_hack_cmpfunc(list);
-    ssize_t ret = list->climpl->find_remove(list, &elem, remove);
+    size_t ret = list->climpl->find_remove(list, &elem, remove);
     cx_pl_unhack_cmpfunc(list);
     return ret;
 }
@@ -192,22 +192,6 @@ static cx_list_class cx_pointer_list_class = {
         cx_pl_reverse,
         cx_pl_iterator,
 };
-
-void cxListStoreObjects(CxList *list) {
-    list->collection.store_pointer = false;
-    if (list->climpl != NULL) {
-        list->cl = list->climpl;
-        list->climpl = NULL;
-    }
-}
-
-void cxListStorePointers(CxList *list) {
-    list->collection.elem_size = sizeof(void *);
-    list->collection.store_pointer = true;
-    list->climpl = list->cl;
-    list->cl = &cx_pointer_list_class;
-}
-
 // </editor-fold>
 
 // <editor-fold desc="empty list implementation">
@@ -223,12 +207,12 @@ static void *cx_emptyl_at(
     return NULL;
 }
 
-static ssize_t cx_emptyl_find_remove(
+static size_t cx_emptyl_find_remove(
         cx_attr_unused struct cx_list_s *list,
         cx_attr_unused const void *elem,
         cx_attr_unused bool remove
 ) {
-    return -1;
+    return 0;
 }
 
 static bool cx_emptyl_iter_valid(cx_attr_unused const void *iter) {
@@ -265,18 +249,19 @@ static cx_list_class cx_empty_list_class = {
 };
 
 CxList cx_empty_list = {
-        {
-                NULL,
-                NULL,
-                0,
-                0,
-                NULL,
-                NULL,
-                NULL,
-                false
-        },
-        &cx_empty_list_class,
-        NULL
+    {
+        NULL,
+        NULL,
+        0,
+        0,
+        NULL,
+        NULL,
+        NULL,
+        false,
+        true,
+    },
+    &cx_empty_list_class,
+    NULL
 };
 
 CxList *const cxEmptyList = &cx_empty_list;
@@ -417,6 +402,29 @@ int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j) {
     return 0;
 }
 
+void cx_list_init(
+    struct cx_list_s *list,
+    struct cx_list_class_s *cl,
+    const struct cx_allocator_s *allocator,
+    cx_compare_func comparator,
+    size_t elem_size
+) {
+    list->cl = cl;
+    list->collection.allocator = allocator;
+    list->collection.cmpfunc = comparator;
+    if (elem_size > 0) {
+        list->collection.elem_size = elem_size;
+    } else {
+        list->collection.elem_size = sizeof(void *);
+        if (list->collection.cmpfunc == NULL) {
+            list->collection.cmpfunc = cx_cmp_ptr;
+        }
+        list->collection.store_pointer = true;
+        list->climpl = list->cl;
+        list->cl = &cx_pointer_list_class;
+    }
+}
+
 int cxListCompare(
         const CxList *list,
         const CxList *other
index 8a34dcc716b96a54d12337c8f8811685045e07ef..49223f5533ea54d4fa0405d4e6ea88ec9638902b 100644 (file)
--- a/ucx/map.c
+++ b/ucx/map.c
@@ -46,12 +46,12 @@ static bool cx_empty_map_iter_valid(cx_attr_unused const void *iter) {
     return false;\r
 }\r
 \r
-static CxIterator cx_empty_map_iterator(\r
+static CxMapIterator cx_empty_map_iterator(\r
         const struct cx_map_s *map,\r
         cx_attr_unused enum cx_map_iterator_type type\r
 ) {\r
-    CxIterator iter = {0};\r
-    iter.src_handle.c = map;\r
+    CxMapIterator iter = {0};\r
+    iter.map.c = map;\r
     iter.base.valid = cx_empty_map_iter_valid;\r
     return iter;\r
 }\r
@@ -66,37 +66,38 @@ static struct cx_map_class_s cx_empty_map_class = {
 };\r
 \r
 CxMap cx_empty_map = {\r
-        {\r
-                NULL,\r
-                NULL,\r
-                0,\r
-                0,\r
-                NULL,\r
-                NULL,\r
-                NULL,\r
-                false\r
-        },\r
-        &cx_empty_map_class\r
+    {\r
+        NULL,\r
+        NULL,\r
+        0,\r
+        0,\r
+        NULL,\r
+        NULL,\r
+        NULL,\r
+        false,\r
+        true\r
+    },\r
+    &cx_empty_map_class\r
 };\r
 \r
 CxMap *const cxEmptyMap = &cx_empty_map;\r
 \r
 // </editor-fold>\r
 \r
-CxIterator cxMapMutIteratorValues(CxMap *map) {\r
-    CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);\r
+CxMapIterator cxMapMutIteratorValues(CxMap *map) {\r
+    CxMapIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);\r
     it.base.mutating = true;\r
     return it;\r
 }\r
 \r
-CxIterator cxMapMutIteratorKeys(CxMap *map) {\r
-    CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);\r
+CxMapIterator cxMapMutIteratorKeys(CxMap *map) {\r
+    CxMapIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);\r
     it.base.mutating = true;\r
     return it;\r
 }\r
 \r
-CxIterator cxMapMutIterator(CxMap *map) {\r
-    CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);\r
+CxMapIterator cxMapMutIterator(CxMap *map) {\r
+    CxMapIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);\r
     it.base.mutating = true;\r
     return it;\r
 }\r
index 265d0c32a890c997f62625aab17453bc25a4fb7c..23f79b318a65c92d3ada6caa4edc5854bd9670a0 100644 (file)
 
 const CxPropertiesConfig cx_properties_config_default = {
         '=',
-        //'\\',
         '#',
         '\0',
-        '\0'
+        '\0',
+    '\\',
 };
 
 void cxPropertiesInit(
@@ -226,8 +226,6 @@ CxPropertiesStatus cxPropertiesNext(
                 return CX_PROPERTIES_INVALID_EMPTY_KEY;
             }
         }
-        // unreachable - either we returned or skipped a blank line
-        assert(false);
     }
 
     // when we come to this point, all data must have been read
@@ -254,7 +252,7 @@ static int cx_properties_sink_map(
 CxPropertiesSink cxPropertiesMapSink(CxMap *map) {
     CxPropertiesSink sink;
     sink.sink = map;
-    sink.data = cxDefaultAllocator;
+    sink.data = (void*) cxDefaultAllocator;
     sink.sink_func = cx_properties_sink_map;
     return sink;
 }
@@ -282,7 +280,7 @@ static int cx_properties_read_file(
 ) {
     target->ptr = src->data_ptr;
     target->length = fread(src->data_ptr, 1, src->data_size, src->src);
-    return ferror(src->src);
+    return ferror((FILE*)src->src);
 }
 
 static int cx_properties_read_init_file(
@@ -362,6 +360,7 @@ CxPropertiesStatus cxPropertiesLoad(
 
     // transfer the data from the source to the sink
     CxPropertiesStatus status;
+    CxPropertiesStatus kv_status = CX_PROPERTIES_NO_DATA;
     bool found = false;
     while (true) {
         // read input
@@ -373,14 +372,23 @@ CxPropertiesStatus cxPropertiesLoad(
 
         // no more data - break
         if (input.length == 0) {
-            status = found ? CX_PROPERTIES_NO_ERROR : CX_PROPERTIES_NO_DATA;
+            if (found) {
+                // something was found, check the last kv_status
+                if (kv_status == CX_PROPERTIES_INCOMPLETE_DATA) {
+                    status = CX_PROPERTIES_INCOMPLETE_DATA;
+                } else {
+                    status = CX_PROPERTIES_NO_ERROR;
+                }
+            } else {
+                // nothing found
+                status = CX_PROPERTIES_NO_DATA;
+            }
             break;
         }
 
         // set the input buffer and read the k/v-pairs
         cxPropertiesFill(prop, input);
 
-        CxPropertiesStatus kv_status;
         do {
             cxstring key, value;
             kv_status = cxPropertiesNext(prop, &key, &value);
index e532ea12e015693c8324eb4481e61f32d41e8d20..14b732e6d16623dc7798cb65dc9a02e061d7c0a3 100644 (file)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-#define CX_STR_IMPLEMENTATION
 #include "cx/string.h"
 
 #include <string.h>
 #include <stdarg.h>
-#include <ctype.h>
 #include <assert.h>
 #include <errno.h>
 #include <limits.h>
@@ -222,14 +220,9 @@ cxstring cx_strchr(
         cxstring string,
         int chr
 ) {
-    chr = 0xFF & chr;
-    // TODO: improve by comparing multiple bytes at once
-    for (size_t i = 0; i < string.length; i++) {
-        if (string.ptr[i] == chr) {
-            return cx_strsubs(string, i);
-        }
-    }
-    return (cxstring) {NULL, 0};
+    char *ret = memchr(string.ptr, 0xFF & chr, string.length);
+    if (ret == NULL) return (cxstring) {NULL, 0};
+    return (cxstring) {ret, string.length - (ret - string.ptr)};
 }
 
 cxmutstr cx_strchr_m(
@@ -265,7 +258,7 @@ cxmutstr cx_strrchr_m(
 }
 
 #ifndef CX_STRSTR_SBO_SIZE
-#define CX_STRSTR_SBO_SIZE 512
+#define CX_STRSTR_SBO_SIZE 128
 #endif
 const unsigned cx_strstr_sbo_size = CX_STRSTR_SBO_SIZE;
 
@@ -295,7 +288,7 @@ cxstring cx_strstr(
 
     // check needle length and use appropriate prefix table
     // if the pattern exceeds static prefix table, allocate on the heap
-    bool useheap = needle.length >= CX_STRSTR_SBO_SIZE;
+    const bool useheap = needle.length >= CX_STRSTR_SBO_SIZE;
     register size_t *ptable = useheap ? calloc(needle.length + 1,
                                                sizeof(size_t)) : s_prefix_table;
 
@@ -334,7 +327,7 @@ cxstring cx_strstr(
     }
 
     // if prefix table was allocated on the heap, free it
-    if (ptable != s_prefix_table) {
+    if (useheap) {
         free(ptable);
     }
 
@@ -512,7 +505,7 @@ int cx_strcasecmp_p(
     return cx_strcasecmp(*left, *right);
 }
 
-cxmutstr cx_strdup_a(
+cxmutstr cx_strdup_a_(
         const CxAllocator *allocator,
         cxstring string
 ) {
@@ -529,14 +522,19 @@ cxmutstr cx_strdup_a(
     return result;
 }
 
+static bool str_isspace(char c) {
+    // TODO: remove once UCX has public API for this
+    return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\v' || c == '\f';
+}
+
 cxstring cx_strtrim(cxstring string) {
     cxstring result = string;
     // TODO: optimize by comparing multiple bytes at once
-    while (result.length > 0 && isspace(*result.ptr)) {
+    while (result.length > 0 && str_isspace(*result.ptr)) {
         result.ptr++;
         result.length--;
     }
-    while (result.length > 0 && isspace(result.ptr[result.length - 1])) {
+    while (result.length > 0 && str_isspace(result.ptr[result.length - 1])) {
         result.length--;
     }
     return result;
@@ -590,18 +588,6 @@ bool cx_strcasesuffix(
 #endif
 }
 
-void cx_strlower(cxmutstr string) {
-    for (size_t i = 0; i < string.length; i++) {
-        string.ptr[i] = (char) tolower(string.ptr[i]);
-    }
-}
-
-void cx_strupper(cxmutstr string) {
-    for (size_t i = 0; i < string.length; i++) {
-        string.ptr[i] = (char) toupper(string.ptr[i]);
-    }
-}
-
 #ifndef CX_STRREPLACE_INDEX_BUFFER_SIZE
 #define CX_STRREPLACE_INDEX_BUFFER_SIZE 64
 #endif
@@ -613,6 +599,8 @@ struct cx_strreplace_ibuf {
 };
 
 static void cx_strrepl_free_ibuf(struct cx_strreplace_ibuf *buf) {
+    // remember, the first data is on the stack!
+    buf = buf->next;
     while (buf) {
         struct cx_strreplace_ibuf *next = buf->next;
         free(buf->buf);
@@ -624,49 +612,46 @@ static void cx_strrepl_free_ibuf(struct cx_strreplace_ibuf *buf) {
 cxmutstr cx_strreplacen_a(
         const CxAllocator *allocator,
         cxstring str,
-        cxstring pattern,
+        cxstring search,
         cxstring replacement,
         size_t replmax
 ) {
 
-    if (pattern.length == 0 || pattern.length > str.length || replmax == 0)
+    if (search.length == 0 || search.length > str.length || replmax == 0)
         return cx_strdup_a(allocator, str);
 
     // Compute expected buffer length
-    size_t ibufmax = str.length / pattern.length;
+    size_t ibufmax = str.length / search.length;
     size_t ibuflen = replmax < ibufmax ? replmax : ibufmax;
     if (ibuflen > CX_STRREPLACE_INDEX_BUFFER_SIZE) {
         ibuflen = CX_STRREPLACE_INDEX_BUFFER_SIZE;
     }
 
-    // Allocate first index buffer
-    struct cx_strreplace_ibuf *firstbuf, *curbuf;
-    firstbuf = curbuf = calloc(1, sizeof(struct cx_strreplace_ibuf));
-    if (!firstbuf) return cx_mutstrn(NULL, 0);
-    firstbuf->buf = calloc(ibuflen, sizeof(size_t));
-    if (!firstbuf->buf) {
-        free(firstbuf);
-        return cx_mutstrn(NULL, 0);
-    }
+    // First index buffer can be on the stack
+    struct cx_strreplace_ibuf ibuf, *curbuf = &ibuf;
+    size_t ibuf_sbo[CX_STRREPLACE_INDEX_BUFFER_SIZE];
+    ibuf.buf = ibuf_sbo;
+    ibuf.next = NULL;
+    ibuf.len = 0;
 
     // Search occurrences
     cxstring searchstr = str;
     size_t found = 0;
     do {
-        cxstring match = cx_strstr(searchstr, pattern);
+        cxstring match = cx_strstr(searchstr, search);
         if (match.length > 0) {
             // Allocate next buffer in chain, if required
             if (curbuf->len == ibuflen) {
                 struct cx_strreplace_ibuf *nextbuf =
                         calloc(1, sizeof(struct cx_strreplace_ibuf));
                 if (!nextbuf) {
-                    cx_strrepl_free_ibuf(firstbuf);
+                    cx_strrepl_free_ibuf(&ibuf);
                     return cx_mutstrn(NULL, 0);
                 }
                 nextbuf->buf = calloc(ibuflen, sizeof(size_t));
                 if (!nextbuf->buf) {
                     free(nextbuf);
-                    cx_strrepl_free_ibuf(firstbuf);
+                    cx_strrepl_free_ibuf(&ibuf);
                     return cx_mutstrn(NULL, 0);
                 }
                 curbuf->next = nextbuf;
@@ -677,8 +662,8 @@ cxmutstr cx_strreplacen_a(
             found++;
             size_t idx = match.ptr - str.ptr;
             curbuf->buf[curbuf->len++] = idx;
-            searchstr.ptr = match.ptr + pattern.length;
-            searchstr.length = str.length - idx - pattern.length;
+            searchstr.ptr = match.ptr + search.length;
+            searchstr.length = str.length - idx - search.length;
         } else {
             break;
         }
@@ -687,9 +672,9 @@ cxmutstr cx_strreplacen_a(
     // Allocate result string
     cxmutstr result;
     {
-        ssize_t adjlen = (ssize_t) replacement.length - (ssize_t) pattern.length;
+        long long adjlen = (long long) replacement.length - (long long) search.length;
         size_t rcount = 0;
-        curbuf = firstbuf;
+        curbuf = &ibuf;
         do {
             rcount += curbuf->len;
             curbuf = curbuf->next;
@@ -697,13 +682,13 @@ cxmutstr cx_strreplacen_a(
         result.length = str.length + rcount * adjlen;
         result.ptr = cxMalloc(allocator, result.length + 1);
         if (!result.ptr) {
-            cx_strrepl_free_ibuf(firstbuf);
+            cx_strrepl_free_ibuf(&ibuf);
             return cx_mutstrn(NULL, 0);
         }
     }
 
     // Build result string
-    curbuf = firstbuf;
+    curbuf = &ibuf;
     size_t srcidx = 0;
     char *destptr = result.ptr;
     do {
@@ -718,7 +703,7 @@ cxmutstr cx_strreplacen_a(
             }
 
             // Copy the replacement and skip the source pattern
-            srcidx += pattern.length;
+            srcidx += search.length;
             memcpy(destptr, replacement.ptr, replacement.length);
             destptr += replacement.length;
         }
@@ -730,12 +715,12 @@ cxmutstr cx_strreplacen_a(
     result.ptr[result.length] = '\0';
 
     // Free index buffer
-    cx_strrepl_free_ibuf(firstbuf);
+    cx_strrepl_free_ibuf(&ibuf);
 
     return result;
 }
 
-CxStrtokCtx cx_strtok(
+CxStrtokCtx cx_strtok_(
         cxstring str,
         cxstring delim,
         size_t limit
@@ -753,14 +738,6 @@ CxStrtokCtx cx_strtok(
     return ctx;
 }
 
-CxStrtokCtx cx_strtok_m(
-        cxmutstr str,
-        cxstring delim,
-        size_t limit
-) {
-    return cx_strtok(cx_strcast(str), delim, limit);
-}
-
 bool cx_strtok_next(
         CxStrtokCtx *ctx,
         cxstring *token
@@ -832,25 +809,24 @@ void cx_strtok_delim(
     *output = (rtype) result; \
     return 0
 
-int cx_strtos_lc(cxstring str, short *output, int base, const char *groupsep) {
+int cx_strtos_lc_(cxstring str, short *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(short, SHRT_MIN, SHRT_MAX);
 }
 
-int cx_strtoi_lc(cxstring str, int *output, int base, const char *groupsep) {
+int cx_strtoi_lc_(cxstring str, int *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(int, INT_MIN, INT_MAX);
 }
 
-int cx_strtol_lc(cxstring str, long *output, int base, const char *groupsep) {
+int cx_strtol_lc_(cxstring str, long *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(long, LONG_MIN, LONG_MAX);
 }
 
-int cx_strtoll_lc(cxstring str, long long *output, int base, const char *groupsep) {
+int cx_strtoll_lc_(cxstring str, long long *output, int base, const char *groupsep) {
     // strategy: parse as unsigned, check range, negate if required
     bool neg = false;
     size_t start_unsigned = 0;
 
-    // trim already, to search for a sign character
-    str = cx_strtrim(str);
+    // emptiness check
     if (str.length == 0) {
         errno = EINVAL;
         return -1;
@@ -890,33 +866,23 @@ int cx_strtoll_lc(cxstring str, long long *output, int base, const char *groupse
     }
 }
 
-int cx_strtoi8_lc(cxstring str, int8_t *output, int base, const char *groupsep) {
+int cx_strtoi8_lc_(cxstring str, int8_t *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(int8_t, INT8_MIN, INT8_MAX);
 }
 
-int cx_strtoi16_lc(cxstring str, int16_t *output, int base, const char *groupsep) {
+int cx_strtoi16_lc_(cxstring str, int16_t *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(int16_t, INT16_MIN, INT16_MAX);
 }
 
-int cx_strtoi32_lc(cxstring str, int32_t *output, int base, const char *groupsep) {
+int cx_strtoi32_lc_(cxstring str, int32_t *output, int base, const char *groupsep) {
     cx_strtoX_signed_impl(int32_t, INT32_MIN, INT32_MAX);
 }
 
-int cx_strtoi64_lc(cxstring str, int64_t *output, int base, const char *groupsep) {
+int cx_strtoi64_lc_(cxstring str, int64_t *output, int base, const char *groupsep) {
     assert(sizeof(long long) == sizeof(int64_t)); // should be true on all platforms
     return cx_strtoll_lc(str, (long long*) output, base, groupsep);
 }
 
-int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep) {
-#if SSIZE_MAX == INT32_MAX
-    return cx_strtoi32_lc(str, (int32_t*) output, base, groupsep);
-#elif SSIZE_MAX == INT64_MAX
-    return cx_strtoll_lc(str, (long long*) output, base, groupsep);
-#else
-#error "unsupported ssize_t size"
-#endif
-}
-
 #define cx_strtoX_unsigned_impl(rtype, rmax) \
     uint64_t result; \
     if (cx_strtou64_lc(str, &result, base, groupsep)) { \
@@ -929,21 +895,20 @@ int cx_strtoz_lc(cxstring str, ssize_t *output, int base, const char *groupsep)
     *output = (rtype) result; \
     return 0
 
-int cx_strtous_lc(cxstring str, unsigned short *output, int base, const char *groupsep) {
+int cx_strtous_lc_(cxstring str, unsigned short *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(unsigned short, USHRT_MAX);
 }
 
-int cx_strtou_lc(cxstring str, unsigned int *output, int base, const char *groupsep) {
+int cx_strtou_lc_(cxstring str, unsigned int *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(unsigned int, UINT_MAX);
 }
 
-int cx_strtoul_lc(cxstring str, unsigned long *output, int base, const char *groupsep) {
+int cx_strtoul_lc_(cxstring str, unsigned long *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(unsigned long, ULONG_MAX);
 }
 
-int cx_strtoull_lc(cxstring str, unsigned long long *output, int base, const char *groupsep) {
+int cx_strtoull_lc_(cxstring str, unsigned long long *output, int base, const char *groupsep) {
     // some sanity checks
-    str = cx_strtrim(str);
     if (str.length == 0) {
         errno = EINVAL;
         return -1;
@@ -1021,37 +986,37 @@ int cx_strtoull_lc(cxstring str, unsigned long long *output, int base, const cha
     return 0;
 }
 
-int cx_strtou8_lc(cxstring str, uint8_t *output, int base, const char *groupsep) {
+int cx_strtou8_lc_(cxstring str, uint8_t *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(uint8_t, UINT8_MAX);
 }
 
-int cx_strtou16_lc(cxstring str, uint16_t *output, int base, const char *groupsep) {
+int cx_strtou16_lc_(cxstring str, uint16_t *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(uint16_t, UINT16_MAX);
 }
 
-int cx_strtou32_lc(cxstring str, uint32_t *output, int base, const char *groupsep) {
+int cx_strtou32_lc_(cxstring str, uint32_t *output, int base, const char *groupsep) {
     cx_strtoX_unsigned_impl(uint32_t, UINT32_MAX);
 }
 
-int cx_strtou64_lc(cxstring str, uint64_t *output, int base, const char *groupsep) {
+int cx_strtou64_lc_(cxstring str, uint64_t *output, int base, const char *groupsep) {
     assert(sizeof(unsigned long long) == sizeof(uint64_t)); // should be true on all platforms
     return cx_strtoull_lc(str, (unsigned long long*) output, base, groupsep);
 }
 
-int cx_strtouz_lc(cxstring str, size_t *output, int base, const char *groupsep) {
+int cx_strtoz_lc_(cxstring str, size_t *output, int base, const char *groupsep) {
 #if SIZE_MAX == UINT32_MAX
-    return cx_strtou32_lc(str, (uint32_t*) output, base, groupsep);
+    return cx_strtou32_lc_(str, (uint32_t*) output, base, groupsep);
 #elif SIZE_MAX == UINT64_MAX
-    return cx_strtoull_lc(str, (unsigned long long *) output, base, groupsep);
+    return cx_strtoull_lc_(str, (unsigned long long *) output, base, groupsep);
 #else
 #error "unsupported size_t size"
 #endif
 }
 
-int cx_strtof_lc(cxstring str, float *output, char decsep, const char *groupsep) {
+int cx_strtof_lc_(cxstring str, float *output, char decsep, const char *groupsep) {
     // use string to double and add a range check
     double d;
-    int ret = cx_strtod_lc(str, &d, decsep, groupsep);
+    int ret = cx_strtod_lc_(str, &d, decsep, groupsep);
     if (ret != 0) return ret;
     // note: FLT_MIN is the smallest POSITIVE number that can be represented
     double test = d < 0 ? -d : d;
@@ -1063,12 +1028,16 @@ int cx_strtof_lc(cxstring str, float *output, char decsep, const char *groupsep)
     return 0;
 }
 
-int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep) {
+static bool str_isdigit(char c) {
+    // TODO: remove once UCX has public API for this
+    return c >= '0' && c <= '9';
+}
+
+int cx_strtod_lc_(cxstring str, double *output, char decsep, const char *groupsep) {
     // TODO: overflow check
     // TODO: increase precision
 
-    // trim and check
-    str = cx_strtrim(str);
+    // emptiness check
     if (str.length == 0) {
         errno = EINVAL;
         return -1;
@@ -1096,7 +1065,7 @@ int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep
     // parse all digits until we find the decsep
     size_t pos = 0;
     do {
-        if (isdigit(str.ptr[pos])) {
+        if (str_isdigit(str.ptr[pos])) {
             result = result * 10 + (str.ptr[pos] - '0');
         } else if (strchr(groupsep, str.ptr[pos]) == NULL) {
             break;
@@ -1125,7 +1094,7 @@ int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep
         // parse everything until exponent or end
         double factor = 1.;
         do {
-            if (isdigit(str.ptr[pos])) {
+            if (str_isdigit(str.ptr[pos])) {
                 factor *= 0.1;
                 result = result + factor * (str.ptr[pos] - '0');
             } else if (strchr(groupsep, str.ptr[pos]) == NULL) {
@@ -1166,7 +1135,7 @@ int cx_strtod_lc(cxstring str, double *output, char decsep, const char *groupsep
     // parse the exponent
     unsigned int exp = 0;
     do {
-        if (isdigit(str.ptr[pos])) {
+        if (str_isdigit(str.ptr[pos])) {
             exp = 10 * exp + (str.ptr[pos] - '0');
         } else if (strchr(groupsep, str.ptr[pos]) == NULL) {
             errno = EINVAL;
index b2fbb0474f3ac27638e6c6136a9829bd00012c4f..397f9087ad937e87293f0d07f16d065008ff7c82 100644 (file)
@@ -749,7 +749,7 @@ static int cx_tree_default_insert_element(
 
 static size_t cx_tree_default_insert_many(
         CxTree *tree,
-        struct cx_iterator_base_s *iter,
+        CxIteratorBase *iter,
         size_t n
 ) {
     size_t ins = 0;
diff --git a/ucx/utils.c b/ucx/utils.c
deleted file mode 100644 (file)
index c01979b..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright
- *      notice, this list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright
- *      notice, this list of conditions and the following disclaimer in the
- *      documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "cx/utils.h"
-
-#ifndef CX_STREAM_BCOPY_BUF_SIZE
-#define CX_STREAM_BCOPY_BUF_SIZE 8192
-#endif
-
-#ifndef CX_STREAM_COPY_BUF_SIZE
-#define CX_STREAM_COPY_BUF_SIZE 1024
-#endif
-
-size_t cx_stream_bncopy(
-        void *src,
-        void *dest,
-        cx_read_func rfnc,
-        cx_write_func wfnc,
-        char *buf,
-        size_t bufsize,
-        size_t n
-) {
-    if (n == 0) {
-        return 0;
-    }
-
-    char *lbuf;
-    size_t ncp = 0;
-
-    if (buf) {
-        if (bufsize == 0) return 0;
-        lbuf = buf;
-    } else {
-        if (bufsize == 0) bufsize = CX_STREAM_BCOPY_BUF_SIZE;
-        lbuf = malloc(bufsize);
-        if (lbuf == NULL) {
-            return 0;
-        }
-    }
-
-    size_t r;
-    size_t rn = bufsize > n ? n : bufsize;
-    while ((r = rfnc(lbuf, 1, rn, src)) != 0) {
-        r = wfnc(lbuf, 1, r, dest);
-        ncp += r;
-        n -= r;
-        rn = bufsize > n ? n : bufsize;
-        if (r == 0 || n == 0) {
-            break;
-        }
-    }
-
-    if (lbuf != buf) {
-        free(lbuf);
-    }
-
-    return ncp;
-}
-
-size_t cx_stream_ncopy(
-        void *src,
-        void *dest,
-        cx_read_func rfnc,
-        cx_write_func wfnc,
-        size_t n
-) {
-    char buf[CX_STREAM_COPY_BUF_SIZE];
-    return cx_stream_bncopy(src, dest, rfnc, wfnc,
-                            buf, CX_STREAM_COPY_BUF_SIZE, n);
-}
-
-#ifndef CX_SZMUL_BUILTIN
-#include "szmul.c"
-#endif
index fbf783383a4cbaf557318688459c10ad9d34f5b8..a04537eac47c4b8434828418e5be0a864eec9533 100644 (file)
@@ -40,7 +40,7 @@
 #include <cx/mempool.h>
 
 static UiObject* create_window(const char *title, BOOL simple) {
-    CxMempool *mp = cxBasicMempoolCreate(256);
+    CxMempool *mp = cxMempoolCreateSimple(256);
     UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject));
     obj->ref = 0;
     
index 3483eaef1ce954ed329536136cca657f4d7bbfd4..f7dfdd363107e876f80b396f2e8f0f4485fec032 100644 (file)
@@ -45,7 +45,7 @@
 static UiContext* global_context;
 
 void uic_init_global_context(void) {
-    CxMempool *mp = cxBasicMempoolCreate(32);
+    CxMempool *mp = cxMempoolCreateSimple(32);
     global_context = uic_context(NULL, mp);
 }
 
@@ -61,7 +61,7 @@ UiContext* uic_context(UiObject *toplevel, CxMempool *mp) {
     ctx->obj = toplevel;
     ctx->vars = cxHashMapCreate(mp->allocator, CX_STORE_POINTERS, 16);
     
-    ctx->documents = cxLinkedListCreate(mp->allocator, cx_cmp_intptr, CX_STORE_POINTERS);
+    ctx->documents = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, CX_STORE_POINTERS);
     ctx->group_widgets = cxLinkedListCreate(mp->allocator, cx_cmp_ptr, sizeof(UiGroupWidget));
     ctx->groups = cxArrayListCreate(mp->allocator, cx_cmp_int, sizeof(int), 32);
     
@@ -98,7 +98,7 @@ void uic_context_attach_document(UiContext *ctx, void *document) {
     UiContext *var_ctx = ctx;
     while(var_ctx) {
         if(var_ctx->vars_unbound &&  cxMapSize(var_ctx->vars_unbound) > 0) {
-            CxIterator i = cxMapIterator(var_ctx->vars_unbound);
+            CxMapIterator i = cxMapIterator(var_ctx->vars_unbound);
             cx_foreach(CxMapEntry*, entry, i) {
                 printf("attach %s\n", entry->key->data);
                 UiVar *var = entry->value;
@@ -116,8 +116,8 @@ void uic_context_attach_document(UiContext *ctx, void *document) {
 }
 
 static void uic_context_unbind_vars(UiContext *ctx) {
-    CxIterator i = cxMapIterator(ctx->vars);
-    cx_foreach(CxMapEntry*, entry, i) {
+    CxMapIterator mi = cxMapIterator(ctx->vars);
+    cx_foreach(CxMapEntry*, entry, mi) {
         UiVar *var = entry->value;
         if(var->from && var->from_ctx) {
             uic_save_var2(var);
@@ -128,7 +128,7 @@ static void uic_context_unbind_vars(UiContext *ctx) {
     }
     
     if(ctx->documents) {
-        i = cxListIterator(ctx->documents);
+        CxIterator i = cxListIterator(ctx->documents);
         cx_foreach(void *, doc, i) {
             UiContext *subctx = ui_document_context(doc);
             uic_context_unbind_vars(subctx);
@@ -471,7 +471,7 @@ UIEXPORT void ui_context_destroy(UiContext *ctx) {
 
 
 void ui_set_group(UiContext *ctx, int group) {
-    if(cxListFind(ctx->groups, &group) == -1) {
+    if(!cxListIndexValid(ctx->groups, cxListFind(ctx->groups, &group))) {
         cxListAdd(ctx->groups, &group);
     }
     
index fc3c11cff80a12ad743ff616246fb0f2090d4251..d36014dc5d14d4e506be2b72664863b637db4567 100644 (file)
@@ -85,12 +85,7 @@ void* ui_get_subdocument(void *document) {
 void* ui_document_new(size_t size) {
     CxMempool *mp = cxMempoolCreate(256, NULL);
     const CxAllocator *a = mp->allocator;
-    UiContext *ctx = cxCalloc(a, 1, sizeof(UiContext));
-    ctx->mp = mp;
-    ctx->attach_document = uic_context_attach_document;
-    ctx->detach_document2 = uic_context_detach_document2;
-    ctx->allocator = a;
-    ctx->vars = cxHashMapCreate(a, CX_STORE_POINTERS, 16);
+    UiContext *ctx = uic_context(NULL, mp);
     
     void *document = cxCalloc(a, size, 1);
     cxMapPut(documents, cx_hash_key(&document, sizeof(void*)), ctx);
index 4138c607e56bc44708e267488b29e4145bf47103..30cbd034d659970e88a57da792a374e9baed0976 100644 (file)
@@ -304,8 +304,12 @@ UIEXPORT UiGeneric* ui_generic_new(UiContext *ctx, char *name) {
 
 
 void ui_int_set(UiInteger* i, int64_t value) {
-    if (i && i->set) {
-        i->set(i, value);
+    if (i) {
+        if (i->set) {
+            i->set(i, value);
+        } else {
+            i->value = value;
+        }
     }
 }
 
@@ -318,8 +322,12 @@ int64_t ui_int_get(UiInteger* i) {
 }
 
 void ui_double_set(UiDouble* d, double value) {
-    if (d && d->set) {
-        d->set(d, value);
+    if (d) {
+        if (d->set) {
+            d->set(d, value);
+        } else {
+            d->value = value;
+        }
     }
 }
 
@@ -333,8 +341,21 @@ double ui_double_get(UiDouble* d) {
 }
 
 void ui_string_set(UiString* s, const char* value) {
-    if (s && s->set) {
-        s->set(s, value);
+    if (s) {
+        if (s->set) {
+            s->set(s, value);
+        } else {
+            if(s->value.free) {
+                s->value.free(s->value.ptr);
+            }
+            if (value) {
+                s->value.ptr = strdup(value);
+                s->value.free = free;
+            } else {
+                s->value.ptr = NULL;
+                s->value.free = NULL;
+            }
+        }
     }
 }
 
@@ -348,8 +369,21 @@ char* ui_string_get(UiString* s) {
 }
 
 void ui_text_set(UiText* s, const char* value) {
-    if (s && s->set) {
-        s->set(s, value);
+    if (s) {
+        if (s->set) {
+            s->set(s, value);
+        } else {
+            if(s->value.free) {
+                s->value.free(s->value.ptr);
+            }
+            if (value) {
+                s->value.ptr = strdup(value);
+                s->value.free = free;
+            } else {
+                s->value.ptr = NULL;
+                s->value.free = NULL;
+            }
+        }
     }
 }
 
index b9374aa9f91211452c24d6e847d858f7c85e5bc6..21e934150768af7bb86d5aa0091fbcfe1bc967b8 100644 (file)
@@ -240,7 +240,7 @@ int ucx_properties_load(CxMap *map, FILE *file) {
 }
 
 int ucx_properties_store(CxMap *map, FILE *file) {
-    CxIterator iter = cxMapIterator(map);
+    CxMapIterator iter = cxMapIterator(map);
     cxstring value;
     size_t written;
 
index 9df30094c6129a7c7d97b1fede2ca511161cf949..8a1697732bf9b7b06432c87c9172915ea9edbc72 100644 (file)
@@ -1143,7 +1143,7 @@ static void update_itemlist(UiList *list, int c) {
             ui_box_container_add(ct->container, item_obj->widget, FALSE);
         } else {
             // create new widget and object for this list element
-            CxMempool *mp = cxBasicMempoolCreate(256);
+            CxMempool *mp = cxMempoolCreateSimple(256);
             const CxAllocator *a = mp->allocator;
             UiObject *obj = cxCalloc(a, 1, sizeof(UiObject));
             obj->ctx = uic_context(obj, mp);
index 6f204a1ec28bf13d80f157bc4ceffb08b86465a6..9f3bebb95b63b7a11ac2694e5d93d04687f4e65e 100644 (file)
 
 #include "toolkit.h"
 #include "container.h"
-#include "../ui/webview.h"
 
-#ifdef UI_WEBVIEW
+#include "webview.h"
 
-#include <webkit/webkit.h>
+#ifdef UI_WEBVIEW
 
 UIWIDGET ui_webview_create(UiObject *obj, UiWebviewArgs args) {
     UiObject* current = uic_current_obj(obj);
     
     GtkWidget *webview = webkit_web_view_new();
-    webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), "https://code.unixwork.de");
     
     ui_set_name_and_style(webview, args.name, args.style_class);
     
+    UiVar *var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_GENERIC);
+    if(var) {
+        WebViewData *data = malloc(sizeof(WebViewData));
+        memset(data, 0, sizeof(WebViewData));
+        data->webview = WEBKIT_WEB_VIEW(webview);
+        WebKitSettings *settings = webkit_web_view_get_settings(data->webview);
+        data->javascript = webkit_settings_get_enable_javascript(settings);
+        data->zoom = webkit_web_view_get_zoom_level(data->webview);
+        
+        UiGeneric *value = var->value;
+        value->get = ui_webview_get;
+        value->get_type = ui_webview_get_type;
+        value->set = ui_webview_set;
+        value->obj = data;
+        if(value->value && value->type && !strcmp(value->type, UI_WEBVIEW_OBJECT_TYPE)) {
+            // TODO
+        }
+    }
+    
     ui_set_widget_groups(obj->ctx, webview, args.groups);
     UI_APPLY_LAYOUT1(current, args);
     current->container->add(current->container, webview, FALSE);
@@ -49,5 +66,112 @@ UIWIDGET ui_webview_create(UiObject *obj, UiWebviewArgs args) {
     return webview;
 }
 
+void* ui_webview_get(UiGeneric *g) {
+    return g->value;
+}
+
+const char* ui_webview_get_type(UiGeneric *g) {
+    return UI_WEBVIEW_OBJECT_TYPE;
+}
+
+int ui_webview_set(UiGeneric *g, void *value, const char *type) {
+    if(!type || strcmp(type, UI_WEBVIEW_OBJECT_TYPE)) {
+        return 1;
+    }
+    
+    WebViewData *obj = g->obj;
+    if(!obj->webview) {
+        return 1;
+    }
+    
+    WebViewData *data = value;
+    if(data->type == WEBVIEW_CONTENT_URL) {
+        webkit_web_view_load_uri(obj->webview, data->uri);
+    } else {
+        if(!data->content) {
+            return 1;
+        }
+        
+        GBytes *bytes = g_bytes_new(data->content, data->contentlength);
+        webkit_web_view_load_bytes(obj->webview, bytes, data->mimetype, data->encoding, data->uri);
+    }
+    
+    ui_webview_enable_javascript(g, data->javascript);
+    webkit_web_view_set_zoom_level(data->webview, data->zoom);
+    
+    return 0;
+}
+
+void ui_webview_load_url(UiGeneric *g, const char *url) {
+    WebViewData data = { .uri = (char*)url, .type = WEBVIEW_CONTENT_URL };
+    g->set(g, &data, UI_WEBVIEW_OBJECT_TYPE);
+}
+
+void ui_webview_load_content(
+        UiGeneric *g,
+        const char *uri,
+        const char *content,
+        size_t contentlength,
+        const char *mimetype,
+        const char *encoding)
+{
+    WebViewData data;
+    data.uri = (char*)uri;
+    data.content = (char*)content;
+    data.contentlength = contentlength;
+    data.mimetype = (char*)mimetype;
+    data.encoding = (char*)encoding;
+    data.type = WEBVIEW_CONTENT_CONTENT;
+    g->set(g, &data, UI_WEBVIEW_OBJECT_TYPE);
+}
+
+void ui_webview_reload(UiGeneric *g) {
+    WebViewData *webview = g->obj;
+    webkit_web_view_reload(webview->webview);
+}
+
+UiBool ui_webview_can_go_back(UiGeneric *g) {
+    WebViewData *webview = g->obj;
+    return webkit_web_view_can_go_back(webview->webview);
+}
+
+UiBool ui_webview_can_go_forward(UiGeneric *g) {
+    WebViewData *webview = g->obj;
+    return webkit_web_view_can_go_forward(webview->webview);
+}
+
+void ui_webview_go_back(UiGeneric *g) {
+    WebViewData *webview = g->obj;
+    webkit_web_view_go_back(webview->webview);
+}
+
+void ui_webview_go_forward(UiGeneric *g) {
+    WebViewData *webview = g->obj;
+    webkit_web_view_go_forward(webview->webview);
+}
+
+const char* ui_webview_get_uri(UiGeneric *g) {
+    WebViewData *webview = g->obj;
+    return webkit_web_view_get_uri(webview->webview);
+}
+
+void ui_webview_enable_javascript(UiGeneric *g, UiBool enable) {
+    WebViewData *webview = g->obj;
+    WebKitSettings *settings = webkit_web_view_get_settings(webview->webview);
+    webkit_settings_set_enable_javascript(settings, enable);
+}
+
+void ui_webview_set_zoom(UiGeneric *g, double zoom) {
+    WebViewData *webview = g->obj;
+    webkit_web_view_set_zoom_level(webview->webview, zoom);
+    webview->zoom = zoom;
+}
+
+double ui_webview_get_zoom(UiGeneric *g) {
+    WebViewData *webview = g->obj;
+    webview->zoom = webkit_web_view_get_zoom_level(webview->webview);
+    return webview->zoom;
+}
+
 
 #endif
index f4fd44bd4e34a3413fedd11c671484cd75a2c92a..4957616d8fcfd7d477cd39f6c314ad61a444fc44 100644 (file)
 #ifndef WEBVIEW_H
 #define WEBVIEW_H
 
+#include "../ui/webview.h"
+#include <webkit/webkit.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
+    
+enum WebViewDataType {
+    WEBVIEW_CONTENT_URL,
+    WEBVIEW_CONTENT_CONTENT
+};
+    
+typedef struct WebViewData {
+    WebKitWebView *webview;
+    char *uri;
+    char *mimetype;
+    char *encoding;
+    char *content;
+    size_t contentlength;
+    enum WebViewDataType type;
+    
+    double zoom;
+    UiBool javascript;
+} WebViewData;
 
-
+void* ui_webview_get(UiGeneric *g);
+const char* ui_webview_get_type(UiGeneric *g);
+int ui_webview_set(UiGeneric *g, void *value, const char *type);
 
 
 #ifdef __cplusplus
index 0120ea5f977904a5ac488a016ab6bd8c97d40f44..ca284c01d48a6a0edc5041c7842c8f66791d29a2 100644 (file)
@@ -102,7 +102,7 @@ static gboolean close_request(GtkWidget* self, GdkEvent* event, UiObject *obj) {
 #endif
 
 static UiObject* create_window(const char *title, void *window_data, UiBool sidebar, UiBool simple) {
-    CxMempool *mp = cxBasicMempoolCreate(256);
+    CxMempool *mp = cxMempoolCreateSimple(256);
     UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject));
     obj->ref = 0;
    
@@ -761,7 +761,7 @@ UiObject* ui_dialog_window_create(UiObject *parent, UiDialogWindowArgs args) {
         gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
     }
     
-    CxMempool *mp = cxBasicMempoolCreate(256);
+    CxMempool *mp = cxMempoolCreateSimple(256);
     UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); 
     obj->ctx = uic_context(obj, mp);
     obj->widget = dialog;
index 52f73c525db0ca7399fe4258555722ab81383daa..430e529da193e6028647e4d0993ccac27d1edfd3 100644 (file)
@@ -57,7 +57,7 @@ static void window_close_handler(Widget window, void *udata, void *cdata) {
 
 
 static UiObject* create_window(const char *title, void *window_data, Boolean simple) {
-    CxMempool *mp = cxBasicMempoolCreate(256);
+    CxMempool *mp = cxMempoolCreateSimple(256);
     const CxAllocator *a = mp->allocator;
     UiObject *obj = cxCalloc(a, 1, sizeof(UiObject));
     obj->ctx = uic_context(obj, mp);
index 18bb5ac3122630fe5a4e8986572f1f11fa629a11..98be28c01d19f276987cd9b77bd53da97bb1b621 100644 (file)
@@ -36,6 +36,8 @@
 extern "C" {
 #endif
     
+#define UI_WEBVIEW_OBJECT_TYPE "webview"
+    
 typedef struct UiWebviewArgs {
     UiTri fill;
     UiBool hexpand;
@@ -48,6 +50,9 @@ typedef struct UiWebviewArgs {
     const char *name;
     const char *style_class;
     
+    UiGeneric *value;
+    const char *varname;
+    
     const int* groups;
 } UiWebviewArgs;
 
@@ -55,7 +60,26 @@ typedef struct UiWebviewArgs {
 
 UIWIDGET ui_webview_create(UiObject *obj, UiWebviewArgs args);
 
+void ui_webview_load_url(UiGeneric *g, const char *url);
+
+void ui_webview_load_content(
+        UiGeneric *g,
+        const char *uri,
+        const char *content,
+        size_t contentlength,
+        const char *mimetype,
+        const char *encoding);
+
 
+void ui_webview_reload(UiGeneric *g);
+UiBool ui_webview_can_go_back(UiGeneric *g);
+UiBool ui_webview_can_go_forward(UiGeneric *g);
+void ui_webview_go_back(UiGeneric *g);
+void ui_webview_go_forward(UiGeneric *g);
+const char * ui_webview_get_uri(UiGeneric *g);
+void ui_webview_enable_javascript(UiGeneric *g, UiBool enable);
+void ui_webview_set_zoom(UiGeneric *g, double zoom);
+double ui_webview_get_zoom(UiGeneric *g);
 
 
 #ifdef __cplusplus
index 208c23c4c457107ea1705a8946a739eb9f30dd03..1e3e89c5c0831b464a56b141099261d79bab35ba 100644 (file)
@@ -142,7 +142,7 @@ UiObject* ui_window(const char* title, void* window_data) {
 }\r
 \r
 UIEXPORT UiObject* ui_simple_window(const char *title, void *window_data) {\r
-       CxMempool* mp = cxBasicMempoolCreate(256);\r
+       CxMempool* mp = cxMempoolCreateSimple(256);\r
        UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject));\r
 \r
        obj->ctx = uic_context(obj, mp);\r
@@ -223,7 +223,7 @@ UIEXPORT UiObject* ui_dialog_window_create(UiObject *parent, UiDialogWindowArgs
                return NULL;\r
        }\r
        \r
-       CxMempool* mp = cxBasicMempoolCreate(256);\r
+       CxMempool* mp = cxMempoolCreateSimple(256);\r
        UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject));\r
        \r
        obj->ctx = uic_context(obj, mp);\r