# HG changeset patch # User Mike Becker # Date 1376653210 -7200 # Node ID aa376dba1ba8fc99f5231a50b4d3398dad6617a1 # Parent e974640ec4e03dacda6cfca8246d8cf0e7ef7a04 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix() diff -r e974640ec4e0 -r aa376dba1ba8 test/main.c --- a/test/main.c Wed Aug 14 16:07:49 2013 +0200 +++ b/test/main.c Fri Aug 16 13:40:10 2013 +0200 @@ -117,6 +117,7 @@ ucx_test_register(suite, test_sstr_len_cat); ucx_test_register(suite, test_sstrsplit); ucx_test_register(suite, test_sstrtrim); + ucx_test_register(suite, test_sstrprefixsuffix); /* UcxLogger Tests */ ucx_test_register(suite, test_ucx_logger_log); diff -r e974640ec4e0 -r aa376dba1ba8 test/string_tests.c --- a/test/string_tests.c Wed Aug 14 16:07:49 2013 +0200 +++ b/test/string_tests.c Fri Aug 16 13:40:10 2013 +0200 @@ -209,3 +209,28 @@ UCX_TEST_ASSERT(empty.length == 0, "empty string failed"); UCX_TEST_END } + +UCX_TEST(test_sstrprefixsuffix) { + sstr_t str = ST("test my prefix and my suffix"); + sstr_t empty = ST(""); + + UCX_TEST_BEGIN + + UCX_TEST_ASSERT(!sstrprefix(empty, S("pref")), "prefix empty string fails"); + UCX_TEST_ASSERT(!sstrsuffix(empty, S("suf")), "suffix empty string fails"); + + UCX_TEST_ASSERT(sstrprefix(str, empty), "empty prefix fails"); + UCX_TEST_ASSERT(sstrsuffix(str, empty), "empty suffix fails"); + + UCX_TEST_ASSERT(sstrprefix(empty, empty), "string and prefix empty fails"); + UCX_TEST_ASSERT(sstrsuffix(empty, empty), "string and suffix empty fails"); + + UCX_TEST_ASSERT(sstrprefix(str, S("test ")), "prefix false negative"); + UCX_TEST_ASSERT(!sstrprefix(str, S("8-) fsck ")), "prefix false positive"); + + UCX_TEST_ASSERT(sstrsuffix(str, S("fix")), "suffix false negative"); + UCX_TEST_ASSERT(!sstrsuffix(str, S("fox")), "suffix false positive"); + + + UCX_TEST_END +} diff -r e974640ec4e0 -r aa376dba1ba8 test/string_tests.h --- a/test/string_tests.h Wed Aug 14 16:07:49 2013 +0200 +++ b/test/string_tests.h Fri Aug 16 13:40:10 2013 +0200 @@ -40,6 +40,7 @@ UCX_TEST(test_sstr_len_cat); UCX_TEST(test_sstrsplit); UCX_TEST(test_sstrtrim); +UCX_TEST(test_sstrprefixsuffix); #ifdef __cplusplus } diff -r e974640ec4e0 -r aa376dba1ba8 ucx/allocator.h --- a/ucx/allocator.h Wed Aug 14 16:07:49 2013 +0200 +++ b/ucx/allocator.h Fri Aug 16 13:40:10 2013 +0200 @@ -63,16 +63,19 @@ * @see UcxAllocator */ typedef void*(*ucx_allocator_malloc)(void *pool, size_t n); + /** * A function pointer to the allocators calloc() function. * @see UcxAllocator */ typedef void*(*ucx_allocator_calloc)(void *pool, size_t n, size_t size); + /** * A function pointer to the allocators realloc() function. * @see UcxAllocator */ typedef void*(*ucx_allocator_realloc)(void *pool, void *data, size_t n); + /** * A function pointer to the allocators free() function. * @see UcxAllocator diff -r e974640ec4e0 -r aa376dba1ba8 ucx/buffer.h --- a/ucx/buffer.h Wed Aug 14 16:07:49 2013 +0200 +++ b/ucx/buffer.h Fri Aug 16 13:40:10 2013 +0200 @@ -58,10 +58,12 @@ * No buffer features enabled (all flags cleared). */ #define UCX_BUFFER_DEFAULT 0x00 + /** * If this flag is enabled, the buffer will automatically free its contents. */ #define UCX_BUFFER_AUTOFREE 0x01 + /** * If this flag is enabled, the buffer will automatically extends its capacity. */ diff -r e974640ec4e0 -r aa376dba1ba8 ucx/list.h --- a/ucx/list.h Wed Aug 14 16:07:49 2013 +0200 +++ b/ucx/list.h Fri Aug 16 13:40:10 2013 +0200 @@ -64,6 +64,7 @@ * @see UcxList */ typedef struct UcxList UcxList; + /** * UCX list structure. */ @@ -99,6 +100,7 @@ * @return a pointer to the copy */ UcxList *ucx_list_clone(UcxList *list, copy_func cpyfnc, void* data); + /** * Creates an element-wise copy of a list using an UcxAllocator. * @@ -152,6 +154,7 @@ * @param list the list to free */ void ucx_list_free(UcxList *list); + /** * Destroys the entire list using an UcxAllocator. * @@ -162,6 +165,7 @@ * @see ucx_list_free() */ void ucx_list_free_a(UcxAllocator *allocator, UcxList *list); + /** * Inserts an element at the end of the list. * @@ -175,6 +179,7 @@ * the newly created list otherwise */ UcxList *ucx_list_append(UcxList *list, void *data); + /** * Inserts an element at the end of the list using an UcxAllocator. * @@ -189,6 +194,7 @@ * @see ucx_list_append() */ UcxList *ucx_list_append_a(UcxAllocator *allocator, UcxList *list, void *data); + /** * Inserts an element at the beginning of the list. * @@ -204,6 +210,7 @@ * @return a pointer to the new list head */ UcxList *ucx_list_prepend(UcxList *list, void *data); + /** * Inserts an element at the beginning of the list using an UcxAllocator. * @@ -217,6 +224,7 @@ * @see ucx_list_prepend() */ UcxList *ucx_list_prepend_a(UcxAllocator *allocator, UcxList *list, void *data); + /** * Concatenates two lists. * @@ -232,6 +240,7 @@ * returned, otherwise list1 is returned */ UcxList *ucx_list_concat(UcxList *list1, UcxList *list2); + /** * Returns the first element of a list. * @@ -243,6 +252,7 @@ * @return the first element of the list, the specified element is a member of */ UcxList *ucx_list_first(const UcxList *elem); + /** * Returns the last element of a list. * @@ -254,6 +264,7 @@ * @return the last element of the list, the specified element is a member of */ UcxList *ucx_list_last(const UcxList *elem); + /** * Returns the list element at the specified index. * @@ -263,6 +274,7 @@ * index is greater than the list size */ UcxList *ucx_list_get(const UcxList *list, int index); + /** * Returns the index of an element. * @@ -272,6 +284,7 @@ * element */ ssize_t ucx_list_indexof(const UcxList *list, const UcxList *elem); + /** * Returns the element count of the list. * @@ -279,6 +292,7 @@ * @return the element count */ size_t ucx_list_size(const UcxList *list); + /** * Returns the index of an element containing the specified data. * @@ -297,6 +311,7 @@ * data is not found in this list */ ssize_t ucx_list_find(UcxList *list, void *elem, cmp_func cmpfnc, void *data); + /** * Checks, if a list contains a specific element. * @@ -340,6 +355,7 @@ * is now empty */ UcxList *ucx_list_remove(UcxList *list, UcxList *element); + /** * Removes an element from the list using an UcxAllocator. * diff -r e974640ec4e0 -r aa376dba1ba8 ucx/logging.h --- a/ucx/logging.h Wed Aug 14 16:07:49 2013 +0200 +++ b/ucx/logging.h Fri Aug 16 13:40:10 2013 +0200 @@ -44,14 +44,19 @@ #endif /* leave enough space for custom log levels */ + /** Log level for error messages. */ #define UCX_LOGGER_ERROR 0x00 + /** Log level for warning messages. */ #define UCX_LOGGER_WARN 0x10 + /** Log level for information messages. */ #define UCX_LOGGER_INFO 0x20 + /** Log level for debug messages. */ #define UCX_LOGGER_DEBUG 0x30 + /** Log level for trace messages. */ #define UCX_LOGGER_TRACE 0x40 @@ -61,12 +66,14 @@ * @see UcxLogger.mask */ #define UCX_LOGGER_LEVEL 0x01 + /** * Output flag for the timestmap. * If this flag is set, the log message will contain the timestmap. * @see UcxLogger.mask */ #define UCX_LOGGER_TIMESTAMP 0x02 + /** * Output flag for the source. * If this flag is set, the log message will contain the source file and line @@ -81,24 +88,28 @@ typedef struct { /** The stream this logger writes its messages to.*/ void *stream; + /** * The write function that shall be used. * For standard file or stdout loggers this might be standard fwrite * (default). */ write_func writer; + /** * The date format for timestamp outputs * (default: "%F %T %z "). * @see UCX_LOGGER_TIMESTAMP */ char *dateformat; + /** * The level, this logger operates on. * If a log command is issued, the message will only be logged, if the log * level of the message is less or equal than the log level of the logger. */ unsigned int level; + /** * A configuration mask for automatic output. * For each flag that is set, the logger automatically outputs some extra @@ -106,6 +117,7 @@ * See the documentation for the flags for details. */ unsigned int mask; + /** * A map of valid log levels for this logger. * @@ -128,6 +140,7 @@ * @return a new logger object */ UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask); + /** * Destroys the logger. * @@ -180,6 +193,7 @@ */ #define ucx_logger_error(logger, ...) \ ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__) + /** * Shortcut for logging an information message. * @param logger the logger to use @@ -188,6 +202,7 @@ */ #define ucx_logger_info(logger, ...) \ ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__) + /** * Shortcut for logging a warning message. * @param logger the logger to use @@ -196,6 +211,7 @@ */ #define ucx_logger_warn(logger, ...) \ ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__) + /** * Shortcut for logging a debug message. * @param logger the logger to use @@ -204,6 +220,7 @@ */ #define ucx_logger_debug(logger, ...) \ ucx_logger_log(logger, UCX_LOGGER_DEBUG, __VA_ARGS__) + /** * Shortcut for logging a trace message. * @param logger the logger to use diff -r e974640ec4e0 -r aa376dba1ba8 ucx/map.h --- a/ucx/map.h Wed Aug 14 16:07:49 2013 +0200 +++ b/ucx/map.h Fri Aug 16 13:40:10 2013 +0200 @@ -67,10 +67,13 @@ /** Type for the UCX map. @see UcxMap */ typedef struct UcxMap UcxMap; + /** Type for a key of an UcxMap. @see UcxKey */ typedef struct UcxKey UcxKey; + /** Type for an element of an UcxMap. @see UcxMapElement */ typedef struct UcxMapElement UcxMapElement; + /** Type for an iterator over an UcxMap. @see UcxMapIterator */ typedef struct UcxMapIterator UcxMapIterator; @@ -100,8 +103,10 @@ struct UcxMapElement { /** The value data. */ void *data; + /** A pointer to the next element in the current list. */ UcxMapElement *next; + /** The corresponding key. */ UcxKey key; }; @@ -110,8 +115,10 @@ struct UcxMapIterator { /** The map to iterate over. */ UcxMap *map; + /** The current map element. */ UcxMapElement *cur; + /** * The current index of the element list array. * Attention: this is NOT the element index! Do NOT @@ -235,6 +242,7 @@ */ #define ucx_map_sstr_put(map, key, value) \ ucx_map_put(map, ucx_key(key.ptr, key.length), (void*)value) + /** * Shorthand for putting data with a C string key into the map. * @param map the map @@ -245,6 +253,7 @@ */ #define ucx_map_cstr_put(map, key, value) \ ucx_map_put(map, ucx_key((void*)key, strlen(key)), (void*)value) + /** * Shorthand for putting data with an integer key into the map. * @param map the map @@ -256,7 +265,6 @@ #define ucx_map_int_put(map, key, value) \ ucx_map_put(map, ucx_key((void*)&key, sizeof(key)), (void*)value) - /** * Shorthand for getting data from the map with a sstr_t key. * @param map the map @@ -266,6 +274,7 @@ */ #define ucx_map_sstr_get(map, key) \ ucx_map_get(map, ucx_key(key.ptr, key.length)) + /** * Shorthand for getting data from the map with a C string key. * @param map the map @@ -275,6 +284,7 @@ */ #define ucx_map_cstr_get(map, key) \ ucx_map_get(map, ucx_key((void*)key, strlen(key))) + /** * Shorthand for getting data from the map with an integer key. * @param map the map @@ -284,6 +294,7 @@ */ #define ucx_map_int_get(map, key) \ ucx_map_get(map, ucx_key((void*)&key, sizeof(int))) + /** * Shorthand for removing data from the map with a sstr_t key. * @param map the map @@ -293,6 +304,7 @@ */ #define ucx_map_sstr_remove(map, key) \ ucx_map_remove(map, ucx_key(key.ptr, key.length)) + /** * Shorthand for removing data from the map with a C string key. * @param map the map @@ -302,6 +314,7 @@ */ #define ucx_map_cstr_remove(map, key) \ ucx_map_remove(map, ucx_key((void*)key, strlen(key))) + /** * Shorthand for removing data from the map with an integer key. * @param map the map diff -r e974640ec4e0 -r aa376dba1ba8 ucx/mempool.h --- a/ucx/mempool.h Wed Aug 14 16:07:49 2013 +0200 +++ b/ucx/mempool.h Fri Aug 16 13:40:10 2013 +0200 @@ -59,8 +59,10 @@ typedef struct { /** List of pointers to pooled memory. */ void **data; + /** Count of pooled memory items. */ size_t ndata; + /** Memory pool size. */ size_t size; } UcxMempool; @@ -125,6 +127,7 @@ * @see ucx_allocator_calloc() */ void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize); + /** * Reallocates pooled memory. * @@ -140,6 +143,7 @@ * @see ucx_allocator_realloc() */ void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n); + /** * Frees pooled memory. * diff -r e974640ec4e0 -r aa376dba1ba8 ucx/properties.h --- a/ucx/properties.h Wed Aug 14 16:07:49 2013 +0200 +++ b/ucx/properties.h Fri Aug 16 13:40:10 2013 +0200 @@ -56,52 +56,62 @@ * Automatically set by calls to ucx_properties_fill(). */ char *buffer; + /** * Length of the input buffer (don't set manually). * Automatically set by calls to ucx_properties_fill(). */ size_t buflen; + /** * Current buffer position (don't set manually). * Used by ucx_properties_next(). */ size_t pos; + /** * Internal temporary buffer (don't set manually). * Used by ucx_properties_next(). */ char *tmp; + /** * Internal temporary buffer length (don't set manually). * Used by ucx_properties_next(). */ size_t tmplen; + /** * Internal temporary buffer capacity (don't set manually). * Used by ucx_properties_next(). */ size_t tmpcap; + /** * Parser error code. * This is always 0 on success and a nonzero value on syntax errors. * The value is set by ucx_properties_next(). */ int error; + /** * The delimiter that shall be used. * This is '=' by default. */ char delimiter; + /** * The first comment character. * This is '#' by default. */ char comment1; + /** * The second comment character. * This is not set by default. */ char comment2; + /** * The third comment character. * This is not set by default. @@ -115,11 +125,13 @@ * @return a pointer to the new UcxProperties object */ UcxProperties *ucx_properties_new(); + /** * Destroys an UcxProperties object. * @param prop the UcxProperties object to destroy */ void ucx_properties_free(UcxProperties *prop); + /** * Sets the input buffer for the properties parser. * @@ -136,6 +148,7 @@ * @see ucx_properties2map() */ void ucx_properties_fill(UcxProperties *prop, char *buf, size_t len); + /** * Retrieves the next key/value-pair. * @@ -155,6 +168,7 @@ * @see ucx_properties_fill() */ int ucx_properties_next(UcxProperties *prop, sstr_t *name, sstr_t *value); + /** * Retrieves all available key/value-pairs and puts them into an UcxMap. * @@ -184,6 +198,7 @@ * @see ucx_properties2map() */ int ucx_properties_load(UcxMap *map, FILE *file); + /** * Stores an UcxMap to a file. * diff -r e974640ec4e0 -r aa376dba1ba8 ucx/string.c --- a/ucx/string.c Wed Aug 14 16:07:49 2013 +0200 +++ b/ucx/string.c Fri Aug 16 13:40:10 2013 +0200 @@ -252,3 +252,34 @@ return newstr; } + +int sstrprefix(sstr_t string, sstr_t prefix) { + if (string.length == 0) { + return prefix.length == 0; + } + if (prefix.length == 0) { + return 1; + } + + if (prefix.length > string.length) { + return 0; + } else { + return memcmp(string.ptr, prefix.ptr, prefix.length) == 0; + } +} + +int sstrsuffix(sstr_t string, sstr_t suffix) { + if (string.length == 0) { + return suffix.length == 0; + } + if (suffix.length == 0) { + return 1; + } + + if (suffix.length > string.length) { + return 0; + } else { + return memcmp(string.ptr+string.length-suffix.length, + suffix.ptr, suffix.length) == 0; + } +} diff -r e974640ec4e0 -r aa376dba1ba8 ucx/string.h --- a/ucx/string.h Wed Aug 14 16:07:49 2013 +0200 +++ b/ucx/string.h Fri Aug 16 13:40:10 2013 +0200 @@ -54,6 +54,7 @@ /** Shortcut for a sstr_t struct literal. */ #define ST(s) { (char*)s, sizeof(s)-1 } + /** Shortcut for the conversion of a C string to a sstr_t. */ #define S(s) sstrn((char*)s, sizeof(s)-1) @@ -338,6 +339,22 @@ */ sstr_t sstrtrim(sstr_t string); +/** + * Checks, if a string has a specific prefix. + * @param string the string to check + * @param prefix the prefix the string should have + * @return 1, if and only if the string has the specified prefix, 0 otherwise + */ +int sstrprefix(sstr_t string, sstr_t prefix); + +/** + * Checks, if a string has a specific suffix. + * @param string the string to check + * @param suffix the suffix the string should have + * @return 1, if and only if the string has the specified suffix, 0 otherwise + */ +int sstrsuffix(sstr_t string, sstr_t suffix); + #ifdef __cplusplus } #endif diff -r e974640ec4e0 -r aa376dba1ba8 ucx/test.h --- a/ucx/test.h Wed Aug 14 16:07:49 2013 +0200 +++ b/ucx/test.h Fri Aug 16 13:40:10 2013 +0200 @@ -81,6 +81,7 @@ #endif #ifndef __FUNCTION__ + /** * Alias for the __func__ preprocessor macro. * Some compilers use __func__ and others use __FUNC__. @@ -92,15 +93,19 @@ /** Type for the UcxTestSuite. */ typedef struct UcxTestSuite UcxTestSuite; + /** Pointer to a test function. */ typedef void(*UcxTest)(UcxTestSuite*,FILE*); + /** Type for the internal list of test cases. */ typedef struct UcxTestList UcxTestList; /** Structure for the internal list of test cases. */ struct UcxTestList { + /** Test case. */ UcxTest test; + /** Pointer to the next list element. */ UcxTestList *next; }; @@ -109,10 +114,13 @@ * A test suite containing multiple test cases. */ struct UcxTestSuite { + /** The number of successful tests after the suite has been run. */ unsigned int success; + /** The number of failed tests after the suite has been run. */ unsigned int failure; + /** * Internal list of test cases. * Use ucx_test_register() to add tests to this list. @@ -125,6 +133,7 @@ * @return a new test suite */ UcxTestSuite* ucx_test_suite_new(); + /** * Destroys a test suite. * @param suite the test suite to destroy @@ -140,6 +149,7 @@ * EXIT_FAILURE on failure */ int ucx_test_register(UcxTestSuite* suite, UcxTest test); + /** * Runs a test suite and writes the test log to the specified stream. * @param suite the test suite to run diff -r e974640ec4e0 -r aa376dba1ba8 ucx/utils.h --- a/ucx/utils.h Wed Aug 14 16:07:49 2013 +0200 +++ b/ucx/utils.h Fri Aug 16 13:40:10 2013 +0200 @@ -179,10 +179,10 @@ int ucx_memcmp(void *ptr1, void *ptr2, void *n); /** - * A printf like function which writes the output to a stream using a write - * function. - * @param stream the stream where to write the data - * @param wfc the write function for the stream + * A printf() like function which writes the output to a stream by + * using a write_func(). + * @param stream the stream the data is written to + * @param wfc the write function * @param fmt format string * @param ... additional arguments * @return the total number of bytes written @@ -190,10 +190,9 @@ int ucx_fprintf(void *stream, write_func wfc, const char *fmt, ...); /** - * Same as ucx_fprintf() but with an argument list instead of variadic - * arguments. - * @param stream the stream where to write the data - * @param wfc the write function for the stream + * va_list version of ucx_fprintf(). + * @param stream the stream the data is written to + * @param wfc the write function * @param fmt format string * @param ap argument list * @return the total number of bytes written @@ -202,30 +201,32 @@ int ucx_vfprintf(void *stream, write_func wfc, const char *fmt, va_list ap); /** - * A printf like function which stores the result in a newly created string. + * A printf() like function which allocates space for a sstr_t + * the result is written to. * - * The sstr_t data is allocated with the allocators ucx_allocator_malloc - * function. So it is implementation depended, whether the returned - * sstr_t.ptr pointer must be passed to the allocators ucx_allocator_free - * function manually. + * Attention: The sstr_t data is allocated with the allocators + * ucx_allocator_malloc() function. So it is implementation dependent, if + * the returned sstr_t.ptr pointer must be passed to the allocators + * ucx_allocator_free() function manually. * - * The sstr_t.ptr of the return value will always be NULL- - * terminated. + * Note: The sstr_t.ptr of the return value will always be + * NULL-terminated. * - * @param allocator a valid instance of an UcxAllocator + * @param allocator the UcxAllocator used for allocating the result sstr_t * @param fmt format string * @param ... additional arguments - * @return a new string + * @return a sstr_t containing the formatted string */ sstr_t ucx_asprintf(UcxAllocator *allocator, const char *fmt, ...); /** - * Same as ucx_asprintf() but with an argument list instead of variadic - * arguments. - * @param allocator a valid instance of an UcxAllocator + * va_list version of ucx_asprintf(). + * + * @param allocator the UcxAllocator used for allocating the result sstr_t * @param fmt format string * @param ap argument list - * @return a new string + * @return a sstr_t containing the formatted string + * @see ucx_asprintf() */ sstr_t ucx_vasprintf(UcxAllocator *allocator, const char *fmt, va_list ap);