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
     1.1 --- a/configure.ac	Wed May 02 20:55:23 2018 +0200
     1.2 +++ b/configure.ac	Wed May 02 21:45:52 2018 +0200
     1.3 @@ -27,8 +27,9 @@
     1.4  #
     1.5  
     1.6  # the package version must match the macros in ucx.h
     1.7 -# if you change the package version, don't forget to adjust the library version
     1.8 -AC_INIT([ucx], [1.0.1], [olaf.wintermann@gmail.com])
     1.9 +# if you change the version, don't forget to adjust the
    1.10 +# libtool version-info in src/Makefile.am accordingly
    1.11 +AC_INIT([ucx], [1.1.0], [olaf.wintermann@gmail.com])
    1.12  
    1.13  # don't place everything in the project root
    1.14  AC_CONFIG_AUX_DIR([build-aux])
     2.1 --- a/src/Makefile.am	Wed May 02 20:55:23 2018 +0200
     2.2 +++ b/src/Makefile.am	Wed May 02 21:45:52 2018 +0200
     2.3 @@ -27,7 +27,7 @@
     2.4  #
     2.5  
     2.6  lib_LTLIBRARIES = libucx.la
     2.7 -libucx_la_LDFLAGS = -version-info 1:0:0
     2.8 +libucx_la_LDFLAGS = -version-info 2:0:1
     2.9  libucx_la_SOURCES = utils.c
    2.10  libucx_la_SOURCES += list.c
    2.11  libucx_la_SOURCES += map.c
     3.1 --- a/src/ucx/string.h	Wed May 02 20:55:23 2018 +0200
     3.2 +++ b/src/ucx/string.h	Wed May 02 21:45:52 2018 +0200
     3.3 @@ -58,6 +58,12 @@
     3.4  /** Shortcut for the conversion of a C string to a <code>sstr_t</code>. */
     3.5  #define S(s) sstrn((char*)s, sizeof(s)-1)
     3.6  
     3.7 +/** Expands a sstr_t to printf arguments. */
     3.8 +#define SFMT(s) (int) (s).length, (s).ptr
     3.9 +
    3.10 +/** Format specifier for a sstr_t. */
    3.11 +#define PRIsstr ".*s"
    3.12 +
    3.13  #ifdef	__cplusplus
    3.14  extern "C" {
    3.15  #endif
     4.1 --- a/src/ucx/ucx.h	Wed May 02 20:55:23 2018 +0200
     4.2 +++ b/src/ucx/ucx.h	Wed May 02 21:45:52 2018 +0200
     4.3 @@ -40,7 +40,7 @@
     4.4  #define UCX_VERSION_MAJOR   1
     4.5  
     4.6  /** Minor UCX version as integer constant. */
     4.7 -#define UCX_VERSION_MINOR   0
     4.8 +#define UCX_VERSION_MINOR   1
     4.9  
    4.10  /** Version constant which ensures to increase monotonically. */
    4.11  #define UCX_VERSION (((UCX_VERSION_MAJOR)<<16)|UCX_VERSION_MINOR)
     5.1 --- a/test/main.c	Wed May 02 20:55:23 2018 +0200
     5.2 +++ b/test/main.c	Wed May 02 21:45:52 2018 +0200
     5.3 @@ -125,6 +125,7 @@
     5.4          ucx_test_register(suite, test_ucx_default_allocator);
     5.5          
     5.6          /* sstring Tests */
     5.7 +        ucx_test_register(suite, test_sstr_macros);
     5.8          ucx_test_register(suite, test_sstr);
     5.9          ucx_test_register(suite, test_sstr_len);
    5.10          ucx_test_register(suite, test_sstrcmp);
     6.1 --- a/test/string_tests.c	Wed May 02 20:55:23 2018 +0200
     6.2 +++ b/test/string_tests.c	Wed May 02 21:45:52 2018 +0200
     6.3 @@ -28,6 +28,19 @@
     6.4  
     6.5  #include "string_tests.h"
     6.6  
     6.7 +UCX_TEST(test_sstr_macros) {
     6.8 +    sstr_t hello = ST("Hello");
     6.9 +    sstr_t world = S("World");
    6.10 +    
    6.11 +    char buf[20];
    6.12 +    snprintf(buf, sizeof(buf), "%" PRIsstr ", %" PRIsstr "!", SFMT(hello), SFMT(world));
    6.13 +    
    6.14 +    UCX_TEST_BEGIN
    6.15 +    const char* cmp = "Hello, World!";
    6.16 +    UCX_TEST_ASSERT(!strcmp(cmp, buf), "Something weird happened.");
    6.17 +    UCX_TEST_END
    6.18 +}
    6.19 +
    6.20  UCX_TEST(test_sstr) {
    6.21      sstr_t s1 = sstr((char*)"1234");
    6.22      sstr_t s2 = sstrn((char*)"ab", 2);
     7.1 --- a/test/string_tests.h	Wed May 02 20:55:23 2018 +0200
     7.2 +++ b/test/string_tests.h	Wed May 02 21:45:52 2018 +0200
     7.3 @@ -36,6 +36,7 @@
     7.4  extern "C" {
     7.5  #endif
     7.6  
     7.7 +UCX_TEST(test_sstr_macros);
     7.8  UCX_TEST(test_sstr);
     7.9  UCX_TEST(test_sstr_len);
    7.10  UCX_TEST(test_sstrcmp);

mercurial