add convenience function to make keys from strings

Fri, 27 May 2022 13:25:42 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 27 May 2022 13:25:42 +0200
changeset 558
9b767b07602c
parent 557
2aae1246b578
child 559
8603709932b9

add convenience function to make keys from strings

src/CMakeLists.txt file | annotate | diff | comparison | revisions
src/cx/map.h file | annotate | diff | comparison | revisions
src/map.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/CMakeLists.txt	Fri May 27 12:59:41 2022 +0200
     1.2 +++ b/src/CMakeLists.txt	Fri May 27 13:25:42 2022 +0200
     1.3 @@ -5,6 +5,7 @@
     1.4          linked_list.c
     1.5          tree.c
     1.6          buffer.c
     1.7 +        map.c
     1.8          hash_map.c
     1.9  )
    1.10  set(headers
     2.1 --- a/src/cx/map.h	Fri May 27 12:59:41 2022 +0200
     2.2 +++ b/src/cx/map.h	Fri May 27 13:25:42 2022 +0200
     2.3 @@ -262,6 +262,14 @@
     2.4      return map->cl->iterator(map);
     2.5  }
     2.6  
     2.7 +/**
     2.8 + * Convenience function to make a key from a NULL-terminated string.
     2.9 + *
    2.10 + * @param str the NULL-terminated string
    2.11 + * @return the string wrapped to be used as a map key
    2.12 + */
    2.13 +__attribute__((__nonnull__, __warn_unused_result__))
    2.14 +CxDataPtr cxMapKeyStr(char const *str);
    2.15  
    2.16  #ifdef    __cplusplus
    2.17  }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/map.c	Fri May 27 13:25:42 2022 +0200
     3.3 @@ -0,0 +1,35 @@
     3.4 +/*
     3.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3.6 + *
     3.7 + * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
     3.8 + *
     3.9 + * Redistribution and use in source and binary forms, with or without
    3.10 + * modification, are permitted provided that the following conditions are met:
    3.11 + *
    3.12 + *   1. Redistributions of source code must retain the above copyright
    3.13 + *      notice, this list of conditions and the following disclaimer.
    3.14 + *
    3.15 + *   2. Redistributions in binary form must reproduce the above copyright
    3.16 + *      notice, this list of conditions and the following disclaimer in the
    3.17 + *      documentation and/or other materials provided with the distribution.
    3.18 + *
    3.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    3.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    3.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    3.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    3.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    3.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    3.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    3.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    3.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    3.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    3.29 + * POSSIBILITY OF SUCH DAMAGE.
    3.30 + */
    3.31 +
    3.32 +#include <string.h>
    3.33 +#include "cx/map.h"
    3.34 +
    3.35 +CxDataPtr cxMapKeyStr(char const *str) {
    3.36 +    CxDataPtr key = {(unsigned char const *) str, 1 + strlen(str)};
    3.37 +    return key;
    3.38 +}
    3.39 \ No newline at end of file

mercurial