1
1

Revert "Added enhancements from Sergei which he attached to #241."

This reverts commit 34fe2312b4aec7be01470bb7be2453a96b53413a.
Этот коммит содержится в:
Patrick Winnertz 2009-02-10 13:21:34 +01:00
родитель 428e233f37
Коммит dd1b7941d6

Просмотреть файл

@ -51,52 +51,56 @@ static inline void mhl_str_toupper(char* str)
*str = toupper(*str); *str = toupper(*str);
} }
/* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */ #define __STR_CONCAT_MAX 32
static const char * mhl_s_c_sep__ = (const char *)1;
/* _NEVER_ call this function directly ! */ /* _NEVER_ call this function directly ! */
static inline char* mhl_str_concat_hlp__(const char* va_start_dummy, ...) static inline char* __mhl_str_concat_hlp(const char* base, ...)
{ {
char * result; static const char* arg_ptr[__STR_CONCAT_MAX];
size_t result_len = 0; static size_t arg_sz[__STR_CONCAT_MAX];
char * p; int count = 0;
const char * chunk; size_t totalsize = 0;
if (base)
{
arg_ptr[0] = base;
arg_sz[0] = totalsize = strlen(base);
count = 1;
}
va_list args; va_list args;
va_start(args,va_start_dummy); va_start(args,base);
while ((chunk = va_arg(args, const char*)) != mhl_s_c_sep__) char* a;
/* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */
while ((a = va_arg(args, char*))!=(char*)1 && count < __STR_CONCAT_MAX )
{ {
if (chunk) if (a)
{ {
result_len += strlen (chunk); arg_ptr[count] = a;
arg_sz[count] = strlen(a);
totalsize += arg_sz[count];
count++;
} }
} }
va_end(args); va_end(args);
if (result_len == 0) if (!count)
return mhl_str_dup(""); return mhl_str_dup("");
/* now as we know how much to copy, allocate the buffer + '\0'*/ /* now as we know how much to copy, allocate the buffer */
result = (char*)mhl_mem_alloc_u (result_len + 1); char* buffer = (char*)mhl_mem_alloc_u(totalsize+2);
char* current = buffer;
p = result; int x=0;
for (x=0; x<count; x++)
va_start(args,va_start_dummy);
while ((chunk = va_arg(args, const char*)) != mhl_s_c_sep__)
{ {
if (chunk) memcpy(current, arg_ptr[x], arg_sz[x]);
{ current += arg_sz[x];
size_t chunk_len = strlen (chunk);
memcpy (p, chunk, chunk_len);
p += chunk_len;
}
} }
va_end(args);
*p = '\0'; *current = 0;
return result; return buffer;
} }
#define mhl_str_concat(...) (mhl_str_concat_hlp__(mhl_s_c_sep__, __VA_ARGS__, mhl_s_c_sep__)) #define mhl_str_concat(...) (__mhl_str_concat_hlp(__VA_ARGS__, (char*)(1)))
static inline char* mhl_str_reverse(char* ptr) static inline char* mhl_str_reverse(char* ptr)
{ {