#ifndef STRINGREPLACE_H
#define STRINGREPLACE_H
#include "../public/nsapi.h"
#include <cx/string.h>
#include <cx/buffer.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum StringSegmentType {
STRING_SEGMENT_STR =
0,
STRING_SEGMENT_NUM_PLACEHOLDER,
STRING_SEGMENT_VAR_PLACEHOLDER
} StringSegmentType;
typedef struct StringTemplateSegment StringTemplateSegment;
typedef struct StringTemplate StringTemplate;
struct StringTemplate {
const CxAllocator *a;
StringTemplateSegment *segments;
};
struct StringTemplateSegment {
cxmutstr str;
StringSegmentType type;
int num;
StringTemplateSegment *next;
};
typedef cxmutstr (*strtpl_var_func)(
const CxAllocator *a, StringTemplateSegment *seg,
void *userdata, WSBool *free_str);
StringTemplate* string_template_compile(
const CxAllocator *a, cxstring tpl);
ssize_t string_template_write_to(StringTemplate *tpl,
const CxAllocator *a, strtpl_var_func varfunc,
void *userdata,
void *stream, cx_write_func writef);
cxmutstr string_template_build_string(StringTemplate *tpl,
const CxAllocator *a, strtpl_var_func varfunc,
void *userdata);
void string_template_free(StringTemplate *tpl);
#ifdef __cplusplus
}
#endif
#endif