adds more convenience macros for sstr

Wed, 02 May 2018 21:45:52 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 02 May 2018 21:45:52 +0200
changeset 283
c3b6ff227481
parent 282
39e69d78b01d
child 284
d7e43c4b2992

adds more convenience macros for sstr

This commit also increases the UCX version number towards the next release.
- New product version: 1.1
- New library version: 2.0.1 - we are backwards, but not forward compatible.

configure.ac file | annotate | diff | comparison | revisions
src/Makefile.am file | annotate | diff | comparison | revisions
src/ucx/string.h file | annotate | diff | comparison | revisions
src/ucx/ucx.h file | annotate | diff | comparison | revisions
test/main.c file | annotate | diff | comparison | revisions
test/string_tests.c file | annotate | diff | comparison | revisions
test/string_tests.h file | annotate | diff | comparison | revisions
--- a/configure.ac	Wed May 02 20:55:23 2018 +0200
+++ b/configure.ac	Wed May 02 21:45:52 2018 +0200
@@ -27,8 +27,9 @@
 #
 
 # the package version must match the macros in ucx.h
-# if you change the package version, don't forget to adjust the library version
-AC_INIT([ucx], [1.0.1], [olaf.wintermann@gmail.com])
+# if you change the version, don't forget to adjust the
+# libtool version-info in src/Makefile.am accordingly
+AC_INIT([ucx], [1.1.0], [olaf.wintermann@gmail.com])
 
 # don't place everything in the project root
 AC_CONFIG_AUX_DIR([build-aux])
--- a/src/Makefile.am	Wed May 02 20:55:23 2018 +0200
+++ b/src/Makefile.am	Wed May 02 21:45:52 2018 +0200
@@ -27,7 +27,7 @@
 #
 
 lib_LTLIBRARIES = libucx.la
-libucx_la_LDFLAGS = -version-info 1:0:0
+libucx_la_LDFLAGS = -version-info 2:0:1
 libucx_la_SOURCES = utils.c
 libucx_la_SOURCES += list.c
 libucx_la_SOURCES += map.c
--- a/src/ucx/string.h	Wed May 02 20:55:23 2018 +0200
+++ b/src/ucx/string.h	Wed May 02 21:45:52 2018 +0200
@@ -58,6 +58,12 @@
 /** Shortcut for the conversion of a C string to a <code>sstr_t</code>. */
 #define S(s) sstrn((char*)s, sizeof(s)-1)
 
+/** Expands a sstr_t to printf arguments. */
+#define SFMT(s) (int) (s).length, (s).ptr
+
+/** Format specifier for a sstr_t. */
+#define PRIsstr ".*s"
+
 #ifdef	__cplusplus
 extern "C" {
 #endif
--- a/src/ucx/ucx.h	Wed May 02 20:55:23 2018 +0200
+++ b/src/ucx/ucx.h	Wed May 02 21:45:52 2018 +0200
@@ -40,7 +40,7 @@
 #define UCX_VERSION_MAJOR   1
 
 /** Minor UCX version as integer constant. */
-#define UCX_VERSION_MINOR   0
+#define UCX_VERSION_MINOR   1
 
 /** Version constant which ensures to increase monotonically. */
 #define UCX_VERSION (((UCX_VERSION_MAJOR)<<16)|UCX_VERSION_MINOR)
--- a/test/main.c	Wed May 02 20:55:23 2018 +0200
+++ b/test/main.c	Wed May 02 21:45:52 2018 +0200
@@ -125,6 +125,7 @@
         ucx_test_register(suite, test_ucx_default_allocator);
         
         /* sstring Tests */
+        ucx_test_register(suite, test_sstr_macros);
         ucx_test_register(suite, test_sstr);
         ucx_test_register(suite, test_sstr_len);
         ucx_test_register(suite, test_sstrcmp);
--- a/test/string_tests.c	Wed May 02 20:55:23 2018 +0200
+++ b/test/string_tests.c	Wed May 02 21:45:52 2018 +0200
@@ -28,6 +28,19 @@
 
 #include "string_tests.h"
 
+UCX_TEST(test_sstr_macros) {
+    sstr_t hello = ST("Hello");
+    sstr_t world = S("World");
+    
+    char buf[20];
+    snprintf(buf, sizeof(buf), "%" PRIsstr ", %" PRIsstr "!", SFMT(hello), SFMT(world));
+    
+    UCX_TEST_BEGIN
+    const char* cmp = "Hello, World!";
+    UCX_TEST_ASSERT(!strcmp(cmp, buf), "Something weird happened.");
+    UCX_TEST_END
+}
+
 UCX_TEST(test_sstr) {
     sstr_t s1 = sstr((char*)"1234");
     sstr_t s2 = sstrn((char*)"ab", 2);
--- a/test/string_tests.h	Wed May 02 20:55:23 2018 +0200
+++ b/test/string_tests.h	Wed May 02 21:45:52 2018 +0200
@@ -36,6 +36,7 @@
 extern "C" {
 #endif
 
+UCX_TEST(test_sstr_macros);
 UCX_TEST(test_sstr);
 UCX_TEST(test_sstr_len);
 UCX_TEST(test_sstrcmp);

mercurial