src/stringpair.h
changeset 98 9e3d28932e7b
child 104 709edbd8f9c1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/stringpair.h	Wed Mar 11 11:52:14 2015 +0100
     1.3 @@ -0,0 +1,163 @@
     1.4 +#pragma once
     1.5 +
     1.6 +#include "dynamic_api.h"
     1.7 +
     1.8 +#ifdef __cplusplus
     1.9 +extern "C" {
    1.10 +#endif
    1.11 +
    1.12 +
    1.13 +typedef struct _stringpair_t {
    1.14 +    char * key;
    1.15 +    char * value;
    1.16 +} stringpair_t;
    1.17 +
    1.18 +
    1.19 +// new_stringpair() - allocate new stringpair_t
    1.20 +//
    1.21 +//  parameters:
    1.22 +//      key (in)        utf-8 string used as key
    1.23 +//      value (in)      utf-8 string containing the value
    1.24 +//
    1.25 +//  return value:
    1.26 +//      pointer to stringpair_t or NULL on failure
    1.27 +//
    1.28 +//  caveat:
    1.29 +//      key and value are copied and remain in the ownership of the caller
    1.30 +
    1.31 +DYNAMIC_API stringpair_t * new_stringpair(const char *key, const char *value);
    1.32 +
    1.33 +
    1.34 +// free_stringpair() - free memory allocated by stringpair_t
    1.35 +//
    1.36 +//  parameters:
    1.37 +//      pair (in)       pointer to stringpair_t to free
    1.38 +
    1.39 +DYNAMIC_API void free_stringpair(stringpair_t * pair);
    1.40 +
    1.41 +
    1.42 +// stringpair_dup() - duplicate stringpair_t (deep copy)
    1.43 +//
    1.44 +//  parameters:
    1.45 +//      src (in)        pointer to stringpair_t to duplicate
    1.46 +//
    1.47 +//  return value:
    1.48 +//      pointer to copy of src or NULL on failure
    1.49 +
    1.50 +DYNAMIC_API stringpair_t * stringpair_dup(const stringpair_t *src);
    1.51 +
    1.52 +
    1.53 +typedef struct _stringpair_list_t {
    1.54 +    stringpair_t *value;
    1.55 +    struct _stringpair_list_t *next;
    1.56 +} stringpair_list_t;
    1.57 +
    1.58 +
    1.59 +// new_stringpair_list() - allocate a new stringpair_list
    1.60 +//
    1.61 +//  parameters:
    1.62 +//      value (in)              initial value as C string or NULL for empty
    1.63 +//                              list
    1.64 +//
    1.65 +//  return value:
    1.66 +//      pointer to stringpair_list_t object or NULL if out of memory
    1.67 +//
    1.68 +//  caveat:
    1.69 +//      the value is being copied before being added to the list
    1.70 +//      the original value is still being owned by the caller
    1.71 +
    1.72 +DYNAMIC_API stringpair_list_t *new_stringpair_list(const stringpair_t *value);
    1.73 +
    1.74 +
    1.75 +// stringpair_list_dup() - duplicate a stringpair_list
    1.76 +//
    1.77 +//  parameters:
    1.78 +//      src (in)                stringpair_list to copy
    1.79 +//
    1.80 +//  return value:
    1.81 +//      pointer to stringpair_list_t object or NULL if out of memory
    1.82 +
    1.83 +DYNAMIC_API stringpair_list_t *stringpair_list_dup(
    1.84 +        const stringpair_list_t *src
    1.85 +    );
    1.86 +
    1.87 +
    1.88 +// stringpair_list_add() - add key to stringpair_list
    1.89 +//
    1.90 +//  parameters:
    1.91 +//      stringpair_list (in)    stringpair_list struct or NULL to create a new
    1.92 +//                              one
    1.93 +//      value (in)              value as C string
    1.94 +//
    1.95 +//  return value:
    1.96 +//      pointer to last element in stringpair_list or NULL if out of memory
    1.97 +//
    1.98 +//  caveat:
    1.99 +//      the value is being copied before being added to the list
   1.100 +//      the original value is still being owned by the caller
   1.101 +
   1.102 +DYNAMIC_API stringpair_list_t *stringpair_list_add(
   1.103 +        stringpair_list_t *stringpair_list,
   1.104 +        const stringpair_t *value
   1.105 +    );
   1.106 +
   1.107 +
   1.108 +// stringpair_list_append() - append stringpair_list to stringpair_list
   1.109 +//
   1.110 +//  parameters:
   1.111 +//      stringpair_list (in)    stringpair_list struct to append to
   1.112 +//      second (in)             stringpair_list struct to append
   1.113 +//
   1.114 +//  return value:
   1.115 +//      pointer to last element in stringpair_list or NULL if out of memory
   1.116 +//
   1.117 +//  caveat:
   1.118 +//      all values are being copied before being added to the list
   1.119 +//      the original values are still being owned by the caller
   1.120 +
   1.121 +DYNAMIC_API stringpair_list_t *stringpair_list_append(
   1.122 +        stringpair_list_t *stringpair_list,
   1.123 +        stringpair_list_t *second
   1.124 +    );
   1.125 +
   1.126 +
   1.127 +// stringpair_list_length() - get length of stringpair_list
   1.128 +//
   1.129 +//  parameters:
   1.130 +//      stringpair_list (in)    stringpair_list struct to determine length of
   1.131 +//
   1.132 +//  return value:
   1.133 +//      length of stringpair_list in number of elements
   1.134 +
   1.135 +DYNAMIC_API int stringpair_list_length(
   1.136 +        const stringpair_list_t *stringpair_list
   1.137 +    );
   1.138 +
   1.139 +
   1.140 +// free_stringpair_list() - free memory occupied by stringpair_list
   1.141 +//
   1.142 +//  parameters:
   1.143 +//      stringpair_list (in)    stringpair_list to free
   1.144 +
   1.145 +DYNAMIC_API void free_stringpair_list(stringpair_list_t *stringpair_list);
   1.146 +
   1.147 +
   1.148 +// stringpair_list_find() - find element in list using key
   1.149 +//
   1.150 +//  parameters:
   1.151 +//      stringpair_list (in)    list to search
   1.152 +//      key (in)                key to search for
   1.153 +//
   1.154 +//  return value:
   1.155 +//      stringpair_t if found or NULL if not
   1.156 +
   1.157 +DYNAMIC_API stringpair_t *stringpair_list_find(
   1.158 +        stringpair_list_t *stringpair_list,
   1.159 +        const char *key
   1.160 +    );
   1.161 +
   1.162 +
   1.163 +#ifdef __cplusplus
   1.164 +}
   1.165 +#endif
   1.166 +