parent
01a9488f6e
commit
60141c4d8a
@ -1,32 +0,0 @@
|
|||||||
#include "webfuse/core/string.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
char * wf_create_string(char const * format, ...)
|
|
||||||
{
|
|
||||||
char * result = NULL;
|
|
||||||
|
|
||||||
va_list measure_args;
|
|
||||||
va_start(measure_args, format);
|
|
||||||
char buffer;
|
|
||||||
int needed = vsnprintf(&buffer, 1, format, measure_args);
|
|
||||||
va_end(measure_args);
|
|
||||||
|
|
||||||
if (0 <= needed)
|
|
||||||
{
|
|
||||||
result = malloc(needed + 1);
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
int count = vsnprintf(result, needed + 1, format, args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
if ((count < 0) || (needed < count))
|
|
||||||
{
|
|
||||||
free(result);
|
|
||||||
result = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
#ifndef WF_CORE_STRING_H
|
|
||||||
#define WF_CORE_STRING_H
|
|
||||||
|
|
||||||
#ifndef __cplusplus
|
|
||||||
#include <stdarg.h>
|
|
||||||
#else
|
|
||||||
#include <cstdarg>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern char * wf_create_string(char const * format, ...);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,18 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "webfuse/core/string.h"
|
|
||||||
|
|
||||||
TEST(wf_string_create, Default)
|
|
||||||
{
|
|
||||||
char * value = wf_create_string("test %s/%d", "hello", 42);
|
|
||||||
ASSERT_STREQ("test hello/42", value);
|
|
||||||
free(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_string_create, EmptyString)
|
|
||||||
{
|
|
||||||
char * value = wf_create_string("");
|
|
||||||
ASSERT_STREQ("", value);
|
|
||||||
free(value);
|
|
||||||
}
|
|
Loading…
Reference in new issue