fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()

Fri, 16 Aug 2013 13:40:10 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 16 Aug 2013 13:40:10 +0200
changeset 146
aa376dba1ba8
parent 145
e974640ec4e0
child 147
1aa598f36872

fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()

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
ucx/allocator.h file | annotate | diff | comparison | revisions
ucx/buffer.h file | annotate | diff | comparison | revisions
ucx/list.h file | annotate | diff | comparison | revisions
ucx/logging.h file | annotate | diff | comparison | revisions
ucx/map.h file | annotate | diff | comparison | revisions
ucx/mempool.h file | annotate | diff | comparison | revisions
ucx/properties.h file | annotate | diff | comparison | revisions
ucx/string.c file | annotate | diff | comparison | revisions
ucx/string.h file | annotate | diff | comparison | revisions
ucx/test.h file | annotate | diff | comparison | revisions
ucx/utils.h file | annotate | diff | comparison | revisions
     1.1 --- a/test/main.c	Wed Aug 14 16:07:49 2013 +0200
     1.2 +++ b/test/main.c	Fri Aug 16 13:40:10 2013 +0200
     1.3 @@ -117,6 +117,7 @@
     1.4          ucx_test_register(suite, test_sstr_len_cat);
     1.5          ucx_test_register(suite, test_sstrsplit);
     1.6          ucx_test_register(suite, test_sstrtrim);
     1.7 +        ucx_test_register(suite, test_sstrprefixsuffix);
     1.8          
     1.9          /* UcxLogger Tests */
    1.10          ucx_test_register(suite, test_ucx_logger_log);
     2.1 --- a/test/string_tests.c	Wed Aug 14 16:07:49 2013 +0200
     2.2 +++ b/test/string_tests.c	Fri Aug 16 13:40:10 2013 +0200
     2.3 @@ -209,3 +209,28 @@
     2.4      UCX_TEST_ASSERT(empty.length == 0, "empty string failed");
     2.5      UCX_TEST_END
     2.6  }
     2.7 +
     2.8 +UCX_TEST(test_sstrprefixsuffix) {
     2.9 +    sstr_t str = ST("test my prefix and my suffix");
    2.10 +    sstr_t empty = ST("");
    2.11 +    
    2.12 +    UCX_TEST_BEGIN
    2.13 +    
    2.14 +    UCX_TEST_ASSERT(!sstrprefix(empty, S("pref")), "prefix empty string fails");
    2.15 +    UCX_TEST_ASSERT(!sstrsuffix(empty, S("suf")), "suffix empty string fails");
    2.16 +    
    2.17 +    UCX_TEST_ASSERT(sstrprefix(str, empty), "empty prefix fails");
    2.18 +    UCX_TEST_ASSERT(sstrsuffix(str, empty), "empty suffix fails");
    2.19 +    
    2.20 +    UCX_TEST_ASSERT(sstrprefix(empty, empty), "string and prefix empty fails");
    2.21 +    UCX_TEST_ASSERT(sstrsuffix(empty, empty), "string and suffix empty fails");
    2.22 +    
    2.23 +    UCX_TEST_ASSERT(sstrprefix(str, S("test ")), "prefix false negative");
    2.24 +    UCX_TEST_ASSERT(!sstrprefix(str, S("8-) fsck ")), "prefix false positive");
    2.25 +    
    2.26 +    UCX_TEST_ASSERT(sstrsuffix(str, S("fix")), "suffix false negative");
    2.27 +    UCX_TEST_ASSERT(!sstrsuffix(str, S("fox")), "suffix false positive");
    2.28 +
    2.29 +    
    2.30 +    UCX_TEST_END
    2.31 +}
     3.1 --- a/test/string_tests.h	Wed Aug 14 16:07:49 2013 +0200
     3.2 +++ b/test/string_tests.h	Fri Aug 16 13:40:10 2013 +0200
     3.3 @@ -40,6 +40,7 @@
     3.4  UCX_TEST(test_sstr_len_cat);
     3.5  UCX_TEST(test_sstrsplit);
     3.6  UCX_TEST(test_sstrtrim);
     3.7 +UCX_TEST(test_sstrprefixsuffix);
     3.8  
     3.9  #ifdef	__cplusplus
    3.10  }
     4.1 --- a/ucx/allocator.h	Wed Aug 14 16:07:49 2013 +0200
     4.2 +++ b/ucx/allocator.h	Fri Aug 16 13:40:10 2013 +0200
     4.3 @@ -63,16 +63,19 @@
     4.4   * @see UcxAllocator
     4.5   */
     4.6  typedef void*(*ucx_allocator_malloc)(void *pool, size_t n);
     4.7 +
     4.8  /**
     4.9   * A function pointer to the allocators <code>calloc()</code> function.
    4.10   * @see UcxAllocator
    4.11   */
    4.12  typedef void*(*ucx_allocator_calloc)(void *pool, size_t n, size_t size);
    4.13 +
    4.14  /**
    4.15   * A function pointer to the allocators <code>realloc()</code> function.
    4.16   * @see UcxAllocator
    4.17   */
    4.18  typedef void*(*ucx_allocator_realloc)(void *pool, void *data, size_t n);
    4.19 +
    4.20  /**
    4.21   * A function pointer to the allocators <code>free()</code> function.
    4.22   * @see UcxAllocator
     5.1 --- a/ucx/buffer.h	Wed Aug 14 16:07:49 2013 +0200
     5.2 +++ b/ucx/buffer.h	Fri Aug 16 13:40:10 2013 +0200
     5.3 @@ -58,10 +58,12 @@
     5.4   * No buffer features enabled (all flags cleared).
     5.5   */
     5.6  #define UCX_BUFFER_DEFAULT      0x00
     5.7 +
     5.8  /**
     5.9   * If this flag is enabled, the buffer will automatically free its contents.
    5.10   */
    5.11  #define UCX_BUFFER_AUTOFREE     0x01
    5.12 +
    5.13  /**
    5.14   * If this flag is enabled, the buffer will automatically extends its capacity.
    5.15   */
     6.1 --- a/ucx/list.h	Wed Aug 14 16:07:49 2013 +0200
     6.2 +++ b/ucx/list.h	Fri Aug 16 13:40:10 2013 +0200
     6.3 @@ -64,6 +64,7 @@
     6.4   * @see UcxList
     6.5   */
     6.6  typedef struct UcxList UcxList;
     6.7 +
     6.8  /**
     6.9   * UCX list structure.
    6.10   */
    6.11 @@ -99,6 +100,7 @@
    6.12   * @return a pointer to the copy
    6.13   */
    6.14  UcxList *ucx_list_clone(UcxList *list, copy_func cpyfnc, void* data);
    6.15 +
    6.16  /**
    6.17   * Creates an element-wise copy of a list using an UcxAllocator.
    6.18   * 
    6.19 @@ -152,6 +154,7 @@
    6.20   * @param list the list to free
    6.21   */
    6.22  void ucx_list_free(UcxList *list);
    6.23 +
    6.24  /**
    6.25   * Destroys the entire list using an UcxAllocator.
    6.26   * 
    6.27 @@ -162,6 +165,7 @@
    6.28   * @see ucx_list_free()
    6.29   */
    6.30  void ucx_list_free_a(UcxAllocator *allocator, UcxList *list);
    6.31 +
    6.32  /**
    6.33   * Inserts an element at the end of the list.
    6.34   * 
    6.35 @@ -175,6 +179,7 @@
    6.36   * the newly created list otherwise
    6.37   */
    6.38  UcxList *ucx_list_append(UcxList *list, void *data);
    6.39 +
    6.40  /**
    6.41   * Inserts an element at the end of the list using an UcxAllocator.
    6.42   * 
    6.43 @@ -189,6 +194,7 @@
    6.44   * @see ucx_list_append()
    6.45   */
    6.46  UcxList *ucx_list_append_a(UcxAllocator *allocator, UcxList *list, void *data);
    6.47 +
    6.48  /**
    6.49   * Inserts an element at the beginning of the list.
    6.50   * 
    6.51 @@ -204,6 +210,7 @@
    6.52   * @return a pointer to the new list head
    6.53   */
    6.54  UcxList *ucx_list_prepend(UcxList *list, void *data);
    6.55 +
    6.56  /**
    6.57   * Inserts an element at the beginning of the list using an UcxAllocator.
    6.58   * 
    6.59 @@ -217,6 +224,7 @@
    6.60   * @see ucx_list_prepend()
    6.61   */
    6.62  UcxList *ucx_list_prepend_a(UcxAllocator *allocator, UcxList *list, void *data);
    6.63 +
    6.64  /**
    6.65   * Concatenates two lists.
    6.66   * 
    6.67 @@ -232,6 +240,7 @@
    6.68   * returned, otherwise <code>list1</code> is returned
    6.69   */
    6.70  UcxList *ucx_list_concat(UcxList *list1, UcxList *list2);
    6.71 +
    6.72  /**
    6.73   * Returns the first element of a list.
    6.74   * 
    6.75 @@ -243,6 +252,7 @@
    6.76   * @return the first element of the list, the specified element is a member of
    6.77   */
    6.78  UcxList *ucx_list_first(const UcxList *elem);
    6.79 +
    6.80  /**
    6.81   * Returns the last element of a list.
    6.82   * 
    6.83 @@ -254,6 +264,7 @@
    6.84   * @return the last element of the list, the specified element is a member of
    6.85   */
    6.86  UcxList *ucx_list_last(const UcxList *elem);
    6.87 +
    6.88  /**
    6.89   * Returns the list element at the specified index.
    6.90   * 
    6.91 @@ -263,6 +274,7 @@
    6.92   * index is greater than the list size
    6.93   */
    6.94  UcxList *ucx_list_get(const UcxList *list, int index);
    6.95 +
    6.96  /**
    6.97   * Returns the index of an element.
    6.98   * 
    6.99 @@ -272,6 +284,7 @@
   6.100   * element
   6.101   */
   6.102  ssize_t ucx_list_indexof(const UcxList *list, const UcxList *elem);
   6.103 +
   6.104  /**
   6.105   * Returns the element count of the list.
   6.106   * 
   6.107 @@ -279,6 +292,7 @@
   6.108   * @return the element count
   6.109   */
   6.110  size_t ucx_list_size(const UcxList *list);
   6.111 +
   6.112  /**
   6.113   * Returns the index of an element containing the specified data.
   6.114   *
   6.115 @@ -297,6 +311,7 @@
   6.116   * data is not found in this list
   6.117   */
   6.118  ssize_t ucx_list_find(UcxList *list, void *elem, cmp_func cmpfnc, void *data);
   6.119 +
   6.120  /**
   6.121   * Checks, if a list contains a specific element.
   6.122   * 
   6.123 @@ -340,6 +355,7 @@
   6.124   * is now empty
   6.125   */
   6.126  UcxList *ucx_list_remove(UcxList *list, UcxList *element);
   6.127 +
   6.128  /**
   6.129   * Removes an element from the list using an UcxAllocator.
   6.130   * 
     7.1 --- a/ucx/logging.h	Wed Aug 14 16:07:49 2013 +0200
     7.2 +++ b/ucx/logging.h	Fri Aug 16 13:40:10 2013 +0200
     7.3 @@ -44,14 +44,19 @@
     7.4  #endif
     7.5  
     7.6  /* leave enough space for custom log levels */
     7.7 +
     7.8  /** Log level for error messages. */
     7.9  #define UCX_LOGGER_ERROR        0x00
    7.10 +    
    7.11  /** Log level for warning messages. */
    7.12  #define UCX_LOGGER_WARN         0x10
    7.13 +
    7.14  /** Log level for information messages. */
    7.15  #define UCX_LOGGER_INFO         0x20
    7.16 +
    7.17  /** Log level for debug messages. */
    7.18  #define UCX_LOGGER_DEBUG        0x30
    7.19 +
    7.20  /** Log level for trace messages. */
    7.21  #define UCX_LOGGER_TRACE        0x40
    7.22  
    7.23 @@ -61,12 +66,14 @@
    7.24   * @see UcxLogger.mask
    7.25   */
    7.26  #define UCX_LOGGER_LEVEL        0x01
    7.27 +
    7.28  /**
    7.29   * Output flag for the timestmap.
    7.30   * If this flag is set, the log message will contain the timestmap.
    7.31   * @see UcxLogger.mask
    7.32   */
    7.33  #define UCX_LOGGER_TIMESTAMP    0x02
    7.34 +
    7.35  /**
    7.36   * Output flag for the source.
    7.37   * If this flag is set, the log message will contain the source file and line
    7.38 @@ -81,24 +88,28 @@
    7.39  typedef struct {
    7.40      /** The stream this logger writes its messages to.*/
    7.41      void *stream;
    7.42 +
    7.43      /**
    7.44       * The write function that shall be used.
    7.45       * For standard file or stdout loggers this might be standard fwrite
    7.46       * (default).
    7.47       */
    7.48      write_func writer;
    7.49 +
    7.50      /**
    7.51       * The date format for timestamp outputs
    7.52       * (default: <code>"%F %T %z "</code>).
    7.53       * @see UCX_LOGGER_TIMESTAMP
    7.54       */
    7.55      char *dateformat;
    7.56 +
    7.57      /**
    7.58       * The level, this logger operates on.
    7.59       * If a log command is issued, the message will only be logged, if the log
    7.60       * level of the message is less or equal than the log level of the logger.
    7.61       */
    7.62      unsigned int level;
    7.63 +
    7.64      /**
    7.65       * A configuration mask for automatic output. 
    7.66       * For each flag that is set, the logger automatically outputs some extra
    7.67 @@ -106,6 +117,7 @@
    7.68       * See the documentation for the flags for details.
    7.69       */
    7.70      unsigned int mask;
    7.71 +
    7.72      /**
    7.73       * A map of valid log levels for this logger.
    7.74       * 
    7.75 @@ -128,6 +140,7 @@
    7.76   * @return a new logger object
    7.77   */
    7.78  UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask);
    7.79 +
    7.80  /**
    7.81   * Destroys the logger.
    7.82   * 
    7.83 @@ -180,6 +193,7 @@
    7.84   */
    7.85  #define ucx_logger_error(logger, ...) \
    7.86      ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__)
    7.87 +
    7.88  /**
    7.89   * Shortcut for logging an information message.
    7.90   * @param logger the logger to use
    7.91 @@ -188,6 +202,7 @@
    7.92   */
    7.93  #define ucx_logger_info(logger, ...) \
    7.94      ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__)
    7.95 +
    7.96  /**
    7.97   * Shortcut for logging a warning message.
    7.98   * @param logger the logger to use
    7.99 @@ -196,6 +211,7 @@
   7.100   */
   7.101  #define ucx_logger_warn(logger, ...) \
   7.102      ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__)
   7.103 +
   7.104  /**
   7.105   * Shortcut for logging a debug message.
   7.106   * @param logger the logger to use
   7.107 @@ -204,6 +220,7 @@
   7.108   */
   7.109  #define ucx_logger_debug(logger, ...) \
   7.110      ucx_logger_log(logger, UCX_LOGGER_DEBUG, __VA_ARGS__)
   7.111 +
   7.112  /**
   7.113   * Shortcut for logging a trace message.
   7.114   * @param logger the logger to use
     8.1 --- a/ucx/map.h	Wed Aug 14 16:07:49 2013 +0200
     8.2 +++ b/ucx/map.h	Fri Aug 16 13:40:10 2013 +0200
     8.3 @@ -67,10 +67,13 @@
     8.4  
     8.5  /** Type for the UCX map. @see UcxMap */
     8.6  typedef struct UcxMap          UcxMap;
     8.7 +
     8.8  /** Type for a key of an UcxMap. @see UcxKey */
     8.9  typedef struct UcxKey          UcxKey;
    8.10 +
    8.11  /** Type for an element of an UcxMap. @see UcxMapElement */
    8.12  typedef struct UcxMapElement   UcxMapElement;
    8.13 +
    8.14  /** Type for an iterator over an UcxMap. @see UcxMapIterator */
    8.15  typedef struct UcxMapIterator  UcxMapIterator;
    8.16  
    8.17 @@ -100,8 +103,10 @@
    8.18  struct UcxMapElement {
    8.19      /** The value data. */
    8.20      void          *data;
    8.21 +    
    8.22      /** A pointer to the next element in the current list. */
    8.23      UcxMapElement *next;
    8.24 +    
    8.25      /** The corresponding key. */
    8.26      UcxKey        key;
    8.27  };
    8.28 @@ -110,8 +115,10 @@
    8.29  struct UcxMapIterator {
    8.30      /** The map to iterate over. */
    8.31      UcxMap        *map;
    8.32 +    
    8.33      /** The current map element. */
    8.34      UcxMapElement *cur;
    8.35 +    
    8.36      /**
    8.37       * The current index of the element list array.
    8.38       * <b>Attention: </b> this is <b>NOT</b> the element index! Do <b>NOT</b>
    8.39 @@ -235,6 +242,7 @@
    8.40   */
    8.41  #define ucx_map_sstr_put(map, key, value) \
    8.42      ucx_map_put(map, ucx_key(key.ptr, key.length), (void*)value)
    8.43 +
    8.44  /**
    8.45   * Shorthand for putting data with a C string key into the map.
    8.46   * @param map the map
    8.47 @@ -245,6 +253,7 @@
    8.48   */
    8.49  #define ucx_map_cstr_put(map, key, value) \
    8.50      ucx_map_put(map, ucx_key((void*)key, strlen(key)), (void*)value)
    8.51 +
    8.52  /**
    8.53   * Shorthand for putting data with an integer key into the map.
    8.54   * @param map the map
    8.55 @@ -256,7 +265,6 @@
    8.56  #define ucx_map_int_put(map, key, value) \
    8.57      ucx_map_put(map, ucx_key((void*)&key, sizeof(key)), (void*)value)
    8.58  
    8.59 -
    8.60  /**
    8.61   * Shorthand for getting data from the map with a sstr_t key.
    8.62   * @param map the map
    8.63 @@ -266,6 +274,7 @@
    8.64   */
    8.65  #define ucx_map_sstr_get(map, key) \
    8.66      ucx_map_get(map, ucx_key(key.ptr, key.length))
    8.67 +
    8.68  /**
    8.69   * Shorthand for getting data from the map with a C string key.
    8.70   * @param map the map
    8.71 @@ -275,6 +284,7 @@
    8.72   */
    8.73  #define ucx_map_cstr_get(map, key) \
    8.74      ucx_map_get(map, ucx_key((void*)key, strlen(key)))
    8.75 +
    8.76  /**
    8.77   * Shorthand for getting data from the map with an integer key.
    8.78   * @param map the map
    8.79 @@ -284,6 +294,7 @@
    8.80   */
    8.81  #define ucx_map_int_get(map, key) \
    8.82      ucx_map_get(map, ucx_key((void*)&key, sizeof(int)))
    8.83 +
    8.84  /**
    8.85   * Shorthand for removing data from the map with a sstr_t key.
    8.86   * @param map the map
    8.87 @@ -293,6 +304,7 @@
    8.88   */
    8.89  #define ucx_map_sstr_remove(map, key) \
    8.90      ucx_map_remove(map, ucx_key(key.ptr, key.length))
    8.91 +
    8.92  /**
    8.93   * Shorthand for removing data from the map with a C string key.
    8.94   * @param map the map
    8.95 @@ -302,6 +314,7 @@
    8.96   */
    8.97  #define ucx_map_cstr_remove(map, key) \
    8.98      ucx_map_remove(map, ucx_key((void*)key, strlen(key)))
    8.99 +
   8.100  /**
   8.101   * Shorthand for removing data from the map with an integer key.
   8.102   * @param map the map
     9.1 --- a/ucx/mempool.h	Wed Aug 14 16:07:49 2013 +0200
     9.2 +++ b/ucx/mempool.h	Fri Aug 16 13:40:10 2013 +0200
     9.3 @@ -59,8 +59,10 @@
     9.4  typedef struct {
     9.5      /** List of pointers to pooled memory. */
     9.6      void   **data;
     9.7 +    
     9.8      /** Count of pooled memory items. */
     9.9      size_t ndata;
    9.10 +    
    9.11      /** Memory pool size. */
    9.12      size_t size;
    9.13  } UcxMempool;
    9.14 @@ -125,6 +127,7 @@
    9.15   * @see ucx_allocator_calloc()
    9.16   */
    9.17  void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize);
    9.18 +
    9.19  /**
    9.20   * Reallocates pooled memory.
    9.21   * 
    9.22 @@ -140,6 +143,7 @@
    9.23   * @see ucx_allocator_realloc()
    9.24   */
    9.25  void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n);
    9.26 +
    9.27  /**
    9.28   * Frees pooled memory.
    9.29   * 
    10.1 --- a/ucx/properties.h	Wed Aug 14 16:07:49 2013 +0200
    10.2 +++ b/ucx/properties.h	Fri Aug 16 13:40:10 2013 +0200
    10.3 @@ -56,52 +56,62 @@
    10.4       * Automatically set by calls to ucx_properties_fill().
    10.5       */
    10.6      char   *buffer;
    10.7 +    
    10.8      /**
    10.9       * Length of the input buffer (don't set manually).
   10.10       * Automatically set by calls to ucx_properties_fill().
   10.11       */
   10.12      size_t buflen;
   10.13 +    
   10.14      /**
   10.15       * Current buffer position (don't set manually).
   10.16       * Used by ucx_properties_next().
   10.17       */
   10.18      size_t pos;
   10.19 +    
   10.20      /**
   10.21       * Internal temporary buffer (don't set manually).
   10.22       * Used by ucx_properties_next().
   10.23       */
   10.24      char   *tmp;
   10.25 +    
   10.26      /**
   10.27       * Internal temporary buffer length (don't set manually).
   10.28       * Used by ucx_properties_next().
   10.29       */
   10.30      size_t tmplen;
   10.31 +    
   10.32      /**
   10.33       * Internal temporary buffer capacity (don't set manually).
   10.34       * Used by ucx_properties_next().
   10.35       */
   10.36      size_t tmpcap;
   10.37 +    
   10.38      /**
   10.39       * Parser error code.
   10.40       * This is always 0 on success and a nonzero value on syntax errors.
   10.41       * The value is set by ucx_properties_next().
   10.42       */
   10.43      int    error;
   10.44 +    
   10.45      /**
   10.46       * The delimiter that shall be used.
   10.47       * This is '=' by default.
   10.48       */
   10.49      char   delimiter;
   10.50 +    
   10.51      /**
   10.52       * The first comment character.
   10.53       * This is '#' by default.
   10.54       */
   10.55      char   comment1;
   10.56 +    
   10.57      /**
   10.58       * The second comment character.
   10.59       * This is not set by default.
   10.60       */
   10.61      char   comment2;
   10.62 +    
   10.63      /**
   10.64       * The third comment character.
   10.65       * This is not set by default.
   10.66 @@ -115,11 +125,13 @@
   10.67   * @return a pointer to the new UcxProperties object
   10.68   */
   10.69  UcxProperties *ucx_properties_new();
   10.70 +
   10.71  /**
   10.72   * Destroys an UcxProperties object.
   10.73   * @param prop the UcxProperties object to destroy
   10.74   */
   10.75  void ucx_properties_free(UcxProperties *prop);
   10.76 +
   10.77  /**
   10.78   * Sets the input buffer for the properties parser.
   10.79   * 
   10.80 @@ -136,6 +148,7 @@
   10.81   * @see ucx_properties2map()
   10.82   */
   10.83  void ucx_properties_fill(UcxProperties *prop, char *buf, size_t len);
   10.84 +
   10.85  /**
   10.86   * Retrieves the next key/value-pair.
   10.87   * 
   10.88 @@ -155,6 +168,7 @@
   10.89   * @see ucx_properties_fill()
   10.90   */
   10.91  int ucx_properties_next(UcxProperties *prop, sstr_t *name, sstr_t *value);
   10.92 +
   10.93  /**
   10.94   * Retrieves all available key/value-pairs and puts them into an UcxMap.
   10.95   * 
   10.96 @@ -184,6 +198,7 @@
   10.97   * @see ucx_properties2map()
   10.98   */
   10.99  int ucx_properties_load(UcxMap *map, FILE *file);
  10.100 +
  10.101  /**
  10.102   * Stores an UcxMap to a file.
  10.103   * 
    11.1 --- a/ucx/string.c	Wed Aug 14 16:07:49 2013 +0200
    11.2 +++ b/ucx/string.c	Fri Aug 16 13:40:10 2013 +0200
    11.3 @@ -252,3 +252,34 @@
    11.4      
    11.5      return newstr;
    11.6  }
    11.7 +
    11.8 +int sstrprefix(sstr_t string, sstr_t prefix) {
    11.9 +    if (string.length == 0) {
   11.10 +        return prefix.length == 0;
   11.11 +    }
   11.12 +    if (prefix.length == 0) {
   11.13 +        return 1;
   11.14 +    }
   11.15 +    
   11.16 +    if (prefix.length > string.length) {
   11.17 +        return 0;
   11.18 +    } else {
   11.19 +        return memcmp(string.ptr, prefix.ptr, prefix.length) == 0;
   11.20 +    }
   11.21 +}
   11.22 +
   11.23 +int sstrsuffix(sstr_t string, sstr_t suffix) {
   11.24 +    if (string.length == 0) {
   11.25 +        return suffix.length == 0;
   11.26 +    }
   11.27 +    if (suffix.length == 0) {
   11.28 +        return 1;
   11.29 +    }
   11.30 +    
   11.31 +    if (suffix.length > string.length) {
   11.32 +        return 0;
   11.33 +    } else {
   11.34 +        return memcmp(string.ptr+string.length-suffix.length,
   11.35 +            suffix.ptr, suffix.length) == 0;
   11.36 +    }
   11.37 +}
    12.1 --- a/ucx/string.h	Wed Aug 14 16:07:49 2013 +0200
    12.2 +++ b/ucx/string.h	Fri Aug 16 13:40:10 2013 +0200
    12.3 @@ -54,6 +54,7 @@
    12.4  
    12.5  /** Shortcut for a <code>sstr_t struct</code> literal. */
    12.6  #define ST(s) { (char*)s, sizeof(s)-1 }
    12.7 +
    12.8  /** Shortcut for the conversion of a C string to a <code>sstr_t</code>. */
    12.9  #define S(s) sstrn((char*)s, sizeof(s)-1)
   12.10  
   12.11 @@ -338,6 +339,22 @@
   12.12   */
   12.13  sstr_t sstrtrim(sstr_t string);
   12.14  
   12.15 +/**
   12.16 + * Checks, if a string has a specific prefix.
   12.17 + * @param string the string to check
   12.18 + * @param prefix the prefix the string should have
   12.19 + * @return 1, if and only if the string has the specified prefix, 0 otherwise
   12.20 + */
   12.21 +int sstrprefix(sstr_t string, sstr_t prefix);
   12.22 +
   12.23 +/**
   12.24 + * Checks, if a string has a specific suffix.
   12.25 + * @param string the string to check
   12.26 + * @param suffix the suffix the string should have
   12.27 + * @return 1, if and only if the string has the specified suffix, 0 otherwise
   12.28 + */
   12.29 +int sstrsuffix(sstr_t string, sstr_t suffix);
   12.30 +
   12.31  #ifdef	__cplusplus
   12.32  }
   12.33  #endif
    13.1 --- a/ucx/test.h	Wed Aug 14 16:07:49 2013 +0200
    13.2 +++ b/ucx/test.h	Fri Aug 16 13:40:10 2013 +0200
    13.3 @@ -81,6 +81,7 @@
    13.4  #endif
    13.5  
    13.6  #ifndef __FUNCTION__
    13.7 +
    13.8  /**
    13.9   * Alias for the <code>__func__</code> preprocessor macro.
   13.10   * Some compilers use <code>__func__</code> and others use __FUNC__.
   13.11 @@ -92,15 +93,19 @@
   13.12  
   13.13  /** Type for the UcxTestSuite. */
   13.14  typedef struct UcxTestSuite UcxTestSuite;
   13.15 +
   13.16  /** Pointer to a test function. */
   13.17  typedef void(*UcxTest)(UcxTestSuite*,FILE*);
   13.18 +
   13.19  /** Type for the internal list of test cases. */
   13.20  typedef struct UcxTestList UcxTestList;
   13.21  
   13.22  /** Structure for the internal list of test cases. */
   13.23  struct UcxTestList {
   13.24 +    
   13.25      /** Test case. */
   13.26      UcxTest test;
   13.27 +    
   13.28      /** Pointer to the next list element. */
   13.29      UcxTestList *next;
   13.30  };
   13.31 @@ -109,10 +114,13 @@
   13.32   * A test suite containing multiple test cases.
   13.33   */
   13.34  struct UcxTestSuite {
   13.35 +    
   13.36      /** The number of successful tests after the suite has been run. */
   13.37      unsigned int success;
   13.38 +    
   13.39      /** The number of failed tests after the suite has been run. */
   13.40      unsigned int failure;
   13.41 +    
   13.42      /**
   13.43       * Internal list of test cases.
   13.44       * Use ucx_test_register() to add tests to this list.
   13.45 @@ -125,6 +133,7 @@
   13.46   * @return a new test suite
   13.47   */
   13.48  UcxTestSuite* ucx_test_suite_new();
   13.49 +
   13.50  /**
   13.51   * Destroys a test suite.
   13.52   * @param suite the test suite to destroy
   13.53 @@ -140,6 +149,7 @@
   13.54   * <code>EXIT_FAILURE</code> on failure
   13.55   */
   13.56  int ucx_test_register(UcxTestSuite* suite, UcxTest test);
   13.57 +
   13.58  /**
   13.59   * Runs a test suite and writes the test log to the specified stream.
   13.60   * @param suite the test suite to run
    14.1 --- a/ucx/utils.h	Wed Aug 14 16:07:49 2013 +0200
    14.2 +++ b/ucx/utils.h	Fri Aug 16 13:40:10 2013 +0200
    14.3 @@ -179,10 +179,10 @@
    14.4  int ucx_memcmp(void *ptr1, void *ptr2, void *n);
    14.5  
    14.6  /**
    14.7 - * A printf like function which writes the output to a stream using a write
    14.8 - * function.
    14.9 - * @param stream the stream where to write the data
   14.10 - * @param wfc the write function for the stream
   14.11 + * A <code>printf()</code> like function which writes the output to a stream by
   14.12 + * using a write_func().
   14.13 + * @param stream the stream the data is written to
   14.14 + * @param wfc the write function
   14.15   * @param fmt format string
   14.16   * @param ... additional arguments
   14.17   * @return the total number of bytes written
   14.18 @@ -190,10 +190,9 @@
   14.19  int ucx_fprintf(void *stream, write_func wfc, const char *fmt, ...);
   14.20  
   14.21  /**
   14.22 - * Same as ucx_fprintf() but with an argument list instead of variadic
   14.23 - * arguments.
   14.24 - * @param stream the stream where to write the data
   14.25 - * @param wfc the write function for the stream
   14.26 + * <code>va_list</code> version of ucx_fprintf().
   14.27 + * @param stream the stream the data is written to
   14.28 + * @param wfc the write function
   14.29   * @param fmt format string
   14.30   * @param ap argument list
   14.31   * @return the total number of bytes written
   14.32 @@ -202,30 +201,32 @@
   14.33  int ucx_vfprintf(void *stream, write_func wfc, const char *fmt, va_list ap);
   14.34  
   14.35  /**
   14.36 - * A printf like function which stores the result in a newly created string.
   14.37 + * A <code>printf()</code> like function which allocates space for a sstr_t
   14.38 + * the result is written to.
   14.39   * 
   14.40 - * The sstr_t data is allocated with the allocators ucx_allocator_malloc
   14.41 - * function. So it is implementation depended, whether the returned
   14.42 - * sstr_t.ptr pointer must be passed to the allocators ucx_allocator_free
   14.43 - * function manually.
   14.44 + * <b>Attention</b>: The sstr_t data is allocated with the allocators
   14.45 + * ucx_allocator_malloc() function. So it is implementation dependent, if
   14.46 + * the returned sstr_t.ptr pointer must be passed to the allocators
   14.47 + * ucx_allocator_free() function manually.
   14.48   * 
   14.49 - * The sstr_t.ptr of the return value will <i>always</i> be <code>NULL</code>-
   14.50 - * terminated.
   14.51 + * <b>Note</b>: The sstr_t.ptr of the return value will <i>always</i> be
   14.52 + * <code>NULL</code>-terminated.
   14.53   * 
   14.54 - * @param allocator a valid instance of an UcxAllocator
   14.55 + * @param allocator the UcxAllocator used for allocating the result sstr_t
   14.56   * @param fmt format string
   14.57   * @param ... additional arguments
   14.58 - * @return a new string
   14.59 + * @return a sstr_t containing the formatted string
   14.60   */
   14.61  sstr_t ucx_asprintf(UcxAllocator *allocator, const char *fmt, ...);
   14.62  
   14.63  /**
   14.64 - * Same as ucx_asprintf() but with an argument list instead of variadic
   14.65 - * arguments.
   14.66 - * @param allocator a valid instance of an UcxAllocator
   14.67 + * <code>va_list</code> version of ucx_asprintf().
   14.68 + * 
   14.69 + * @param allocator the UcxAllocator used for allocating the result sstr_t
   14.70   * @param fmt format string
   14.71   * @param ap argument list
   14.72 - * @return a new string
   14.73 + * @return a sstr_t containing the formatted string
   14.74 + * @see ucx_asprintf()
   14.75   */
   14.76  sstr_t ucx_vasprintf(UcxAllocator *allocator, const char *fmt, va_list ap);
   14.77  

mercurial