From 456e41a2a2ed80aa2bbcb0b7cccf46f2443723d9 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT service" Date: Mon, 12 Jan 2009 21:42:45 +0100 Subject: [PATCH] removed mhl_str_concat_XXX() inlines --- mhl/string.h | 431 +++++++++++++++++------------------------------------------ 1 file changed, 124 insertions(+), 307 deletions(-) rewrite mhl/string.h (68%) diff --git a/mhl/string.h b/mhl/string.h dissimilarity index 68% index cbf7be929..e725c45b8 100644 --- a/mhl/string.h +++ b/mhl/string.h @@ -1,307 +1,124 @@ -#ifndef __MHL_STRING_H -#define __MHL_STRING_H - -#include -#include -#include "../mhl/memory.h" - -#define mhl_str_dup(str) ((str ? strdup(str) : strdup(""))) -#define mhl_str_ndup(str,len) ((str ? strndup(str,len) : strdup(""))) -#define mhl_str_len(str) ((str ? strlen(str) : 0)) - -static inline char* mhl_str_trim(char* str) -{ - if (!str) return NULL; // NULL string ?! bail out. - - // find the first non-space - char* start; for (start=str; ((*str) && (!isspace(*str))); str++); - - // only spaces ? - if (!(*str)) { *str = 0; return str; } - - // get the size (cannot be empty - catched above) - int _sz = strlen(str); - - // find the proper end - char* end; - for (end=(str+_sz-1); ((end>str) && (isspace(*end))); end--); - end[1] = 0; // terminate, just to be sure - - // if we have no leading spaces, just trucate - if (start==str) { end++; *end = 0; return str; } - - - // if it' only one char, dont need memmove for that - if (start==end) { str[0]=*start; str[1]=0; return str; } - - // by here we have a (non-empty) region between start end end - memmove(str,start,(end-start+1)); - return str; -} - -static inline void mhl_str_toupper(char* str) -{ - if (str) - for (;*str;str++) - *str = toupper(*str); -} - -#define __STR_CONCAT_MAX 32 -/* _NEVER_ call this function directly ! */ -static inline char* __mhl_str_concat_hlp(const char* base, ...) -{ - static const char* arg_ptr[__STR_CONCAT_MAX]; - static int arg_sz[__STR_CONCAT_MAX]; - int count = 0; - int totalsize = 0; - - // first pass: scan through the params and count string sizes - va_list par; - - if (base) - { - arg_ptr[0] = base; - arg_sz[0] = totalsize = strlen(base); - count = 1; - } - - va_list args; - va_start(args,base); - char* a; - // note: we use ((char*)(1)) as terminator - NULL is a valid argument ! - while ((a = va_arg(args, char*))!=(char*)1) - { -// printf("a=%u\n", a); - if (a) - { - arg_ptr[count] = a; - arg_sz[count] = strlen(a); - totalsize += arg_sz[count]; - count++; - } - } - - if (!count) - return mhl_str_dup(""); - - // now as we know how much to copy, allocate the buffer - char* buffer = (char*)mhl_mem_alloc_u(totalsize+2); - char* current = buffer; - int x=0; - for (x=0; x +#include +#include "../mhl/memory.h" + +#define mhl_str_dup(str) ((str ? strdup(str) : strdup(""))) +#define mhl_str_ndup(str,len) ((str ? strndup(str,len) : strdup(""))) +#define mhl_str_len(str) ((str ? strlen(str) : 0)) + +static inline char* mhl_str_trim(char* str) +{ + if (!str) return NULL; // NULL string ?! bail out. + + // find the first non-space + char* start; for (start=str; ((*str) && (!isspace(*str))); str++); + + // only spaces ? + if (!(*str)) { *str = 0; return str; } + + // get the size (cannot be empty - catched above) + int _sz = strlen(str); + + // find the proper end + char* end; + for (end=(str+_sz-1); ((end>str) && (isspace(*end))); end--); + end[1] = 0; // terminate, just to be sure + + // if we have no leading spaces, just trucate + if (start==str) { end++; *end = 0; return str; } + + + // if it' only one char, dont need memmove for that + if (start==end) { str[0]=*start; str[1]=0; return str; } + + // by here we have a (non-empty) region between start end end + memmove(str,start,(end-start+1)); + return str; +} + +static inline void mhl_str_toupper(char* str) +{ + if (str) + for (;*str;str++) + *str = toupper(*str); +} + +#define __STR_CONCAT_MAX 32 +/* _NEVER_ call this function directly ! */ +static inline char* __mhl_str_concat_hlp(const char* base, ...) +{ + static const char* arg_ptr[__STR_CONCAT_MAX]; + static int arg_sz[__STR_CONCAT_MAX]; + int count = 0; + int totalsize = 0; + + // first pass: scan through the params and count string sizes + va_list par; + + if (base) + { + arg_ptr[0] = base; + arg_sz[0] = totalsize = strlen(base); + count = 1; + } + + va_list args; + va_start(args,base); + char* a; + // note: we use ((char*)(1)) as terminator - NULL is a valid argument ! + while ((a = va_arg(args, char*))!=(char*)1) + { +// printf("a=%u\n", a); + if (a) + { + arg_ptr[count] = a; + arg_sz[count] = strlen(a); + totalsize += arg_sz[count]; + count++; + } + } + + if (!count) + return mhl_str_dup(""); + + // now as we know how much to copy, allocate the buffer + char* buffer = (char*)mhl_mem_alloc_u(totalsize+2); + char* current = buffer; + int x=0; + for (x=0; x