本文整理汇总了C++中StringWriterClose函数的典型用法代码示例。如果您正苦于以下问题:C++ StringWriterClose函数的具体用法?C++ StringWriterClose怎么用?C++ StringWriterClose使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringWriterClose函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_show_object_compound_compact
static void test_show_object_compound_compact(void)
{
JsonElement *json = JsonObjectCreate(10);
JsonObjectAppendString(json, "first", "one");
{
JsonElement *inner = JsonObjectCreate(10);
JsonObjectAppendString(inner, "third", "three");
JsonObjectAppendObject(json, "second", inner);
}
{
JsonElement *inner = JsonObjectCreate(10);
JsonObjectAppendString(inner, "fifth", "five");
JsonObjectAppendObject(json, "fourth", inner);
}
Writer *writer = StringWriter();
JsonWriteCompact(writer, json);
char *output = StringWriterClose(writer);
assert_string_equal("{\"first\":\"one\",\"second\":{\"third\":\"three\"},\"fourth\":{\"fifth\":\"five\"}}", output);
JsonDestroy(json);
free(output);
}
示例2: StringWriter
char *EvalContextStackPath(const EvalContext *ctx)
{
Writer *path = StringWriter();
for (size_t i = 0; i < SeqLength(ctx->stack); i++)
{
StackFrame *frame = SeqAt(ctx->stack, i);
switch (frame->type)
{
case STACK_FRAME_TYPE_BODY:
WriterWriteF(path, "/%s", frame->data.body.owner->name);
break;
case STACK_FRAME_TYPE_BUNDLE:
WriterWriteF(path, "/%s", frame->data.bundle.owner->name);
break;
case STACK_FRAME_TYPE_PROMISE_ITERATION:
WriterWriteF(path, "/%s", frame->data.promise.owner->parent_promise_type->name);
WriterWriteF(path, "/'%s'", frame->data.promise.owner->promiser);
break;
case STACK_FRAME_TYPE_PROMISE:
break;
}
}
return StringWriterClose(path);
}
示例3: ProgrammingError
char *SearchAndReplace(const char *source, const char *search, const char *replace)
{
const char *source_ptr = source;
if ((source == NULL) || (search == NULL) || (replace == NULL))
{
ProgrammingError("Programming error: NULL argument is passed to SearchAndReplace");
}
if (strcmp(search, "") == 0)
{
return xstrdup(source);
}
Writer *w = StringWriter();
for (;;)
{
const char *found_ptr = strstr(source_ptr, search);
if (found_ptr == NULL)
{
WriterWrite(w, source_ptr);
return StringWriterClose(w);
}
WriterWriteLen(w, source_ptr, found_ptr - source_ptr);
WriterWrite(w, replace);
source_ptr += found_ptr - source_ptr + strlen(search);
}
}
示例4: test_comment
void test_comment(void **state)
{
Writer *w = StringWriter();
XmlComment(w, "foobar");
assert_string_equal(StringWriterClose(w), "<!-- foobar -->\n");
}
示例5: StringWriter
char *MapNameCopy(const char *s)
{
Writer *w = StringWriter();
/* c:\a\b -> /cygdrive/c\a\b */
if (s[0] && isalpha(s[0]) && s[1] == ':')
{
WriterWriteF(w, "/cygdrive/%c", s[0]);
s += 2;
}
for (; *s; s++)
{
/* a//b//c -> a/b/c */
/* a\\b\\c -> a\b\c */
if (IsFileSep(*s) && IsFileSep(*(s + 1)))
{
continue;
}
/* a\b\c -> a/b/c */
WriterWriteChar(w, *s == '\\' ? '/' : *s);
}
return StringWriterClose(w);
}
示例6: test_no_attr
void test_no_attr(void **state)
{
Writer *w = StringWriter();
XmlTag(w, "foobar", NULL, 0);
assert_string_equal(StringWriterClose(w), "<foobar></foobar>\n");
}
示例7: test_escape
void test_escape(void **state)
{
Writer *w = StringWriter();
XmlContent(w, "&>\"'<");
assert_string_equal(StringWriterClose(w), "&>"'<");
}
示例8: test_show_object_compound
static void test_show_object_compound(void)
{
JsonElement *json = JsonObjectCreate(10);
JsonObjectAppendString(json, "first", "one");
{
JsonElement *inner = JsonObjectCreate(10);
JsonObjectAppendString(inner, "third", "three");
JsonObjectAppendObject(json, "second", inner);
}
{
JsonElement *inner = JsonObjectCreate(10);
JsonObjectAppendString(inner, "fifth", "five");
JsonObjectAppendObject(json, "fourth", inner);
}
Writer *writer = StringWriter();
JsonWrite(writer, json, 0);
char *output = StringWriterClose(writer);
assert_string_equal(OBJECT_COMPOUND, output);
JsonDestroy(json);
free(output);
}
示例9: test_empty
void test_empty(void **state)
{
Writer *w = StringWriter();
CsvWriter *c = CsvWriterOpen(w);
CsvWriterClose(c);
assert_string_equal(StringWriterClose(w), "");
}
示例10: StringWriter
char *ReadTexinfoFileF(const char *source_dir, const char *fmt, ...)
{
Writer *filenamew = StringWriter();
struct stat sb;
char *buffer = NULL;
FILE *fp = NULL;
off_t file_size;
va_list ap;
va_start(ap, fmt);
WriterWriteF(filenamew, "%s/", source_dir);
WriterWriteVF(filenamew, fmt, ap);
va_end(ap);
char *filename = StringWriterClose(filenamew);
if (cfstat(filename, &sb) == -1)
{
if (!GenerateStub(filename))
{
CfOut(OUTPUT_LEVEL_INFORM, "", "Unable to write down stub for missing texinfo file");
free(filename);
return NULL;
}
}
if ((fp = fopen(filename, "r")) == NULL)
{
CfOut(OUTPUT_LEVEL_INFORM, "fopen", "Could not read manual source %s\n", filename);
free(filename);
return NULL;
}
fseek(fp, 0, SEEK_END);
file_size = ftello(fp);
fseek(fp, 0, SEEK_SET);
buffer = (char *) xcalloc(file_size + 1, sizeof(char));
buffer[file_size] = '\0';
int cnt = fread(buffer, sizeof(char), file_size, fp);
if ((ferror(fp)) || (cnt != file_size))
{
CfOut(OUTPUT_LEVEL_INFORM, "fread", "Could not read manual source %s\n", filename);
free(buffer);
fclose(fp);
free(filename);
return NULL;
}
fclose(fp);
free(filename);
return buffer;
}
示例11: test_tag
void test_tag(void **state)
{
Writer *w = StringWriter();
XmlTag(w, "foobar", "some value", 1, (XmlAttribute)
{
"a", "b"});
assert_string_equal(StringWriterClose(w), "<foobar a=\"b\" >some value</foobar>\n");
}
示例12: test_escape
void test_escape(void **state)
{
Writer *w = StringWriter();
CsvWriter *c = CsvWriterOpen(w);
CsvWriterField(c, ",\"\r\n");
CsvWriterClose(c);
assert_string_equal(StringWriterClose(w), "\",\"\"\r\n\"\r\n");
}
示例13: test_single_field
void test_single_field(void **state)
{
Writer *w = StringWriter();
CsvWriter *c = CsvWriterOpen(w);
CsvWriterField(c, "test");
CsvWriterClose(c);
assert_string_equal(StringWriterClose(w), "test\r\n");
}
示例14: test_show_string
static void test_show_string(void **state)
{
JsonElement *str = JsonStringCreate("snookie");
Writer *writer = StringWriter();
JsonElementPrint(writer, str, 0);
assert_string_equal("\"snookie\"", StringWriterClose(writer));
JsonElementDestroy(str);
}
示例15: test_empty_last_record
void test_empty_last_record(void **state)
{
Writer *w = StringWriter();
CsvWriter *c = CsvWriterOpen(w);
CsvWriterField(c, "test1");
CsvWriterNewRecord(c);
CsvWriterNewRecord(c);
CsvWriterClose(c);
assert_string_equal(StringWriterClose(w), "test1\r\n\r\n");
}