本文整理汇总了C++中StringWriter函数的典型用法代码示例。如果您正苦于以下问题:C++ StringWriter函数的具体用法?C++ StringWriter怎么用?C++ StringWriter使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringWriter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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);
}
示例4: VerifyBundleSequence
static bool VerifyBundleSequence(EvalContext *ctx, const Policy *policy, const GenericAgentConfig *config)
{
Rlist *rp;
char *name;
Rval retval;
int ok = true;
FnCall *fp;
if (!EvalContextVariableControlCommonGet(ctx, COMMON_CONTROL_BUNDLESEQUENCE, &retval))
{
Log(LOG_LEVEL_ERR, " No bundlesequence in the common control body");
return false;
}
if (retval.type != RVAL_TYPE_LIST)
{
FatalError(ctx, "Promised bundlesequence was not a list");
}
for (rp = (Rlist *) retval.item; rp != NULL; rp = rp->next)
{
switch (rp->type)
{
case RVAL_TYPE_SCALAR:
name = (char *) rp->item;
break;
case RVAL_TYPE_FNCALL:
fp = (FnCall *) rp->item;
name = (char *) fp->name;
break;
default:
name = NULL;
ok = false;
{
Writer *w = StringWriter();
WriterWrite(w, "Illegal item found in bundlesequence '");
RvalWrite(w, (Rval) {rp->item, rp->type});
WriterWrite(w, "'");
Log(LOG_LEVEL_ERR, "%s", StringWriterData(w));
WriterClose(w);
}
break;
}
if (strcmp(name, CF_NULL_VALUE) == 0)
{
continue;
}
if (!config->ignore_missing_bundles && !PolicyGetBundle(policy, NULL, NULL, name))
{
Log(LOG_LEVEL_ERR, "Bundle '%s' listed in the bundlesequence is not a defined bundle", name);
ok = false;
}
}
return ok;
}
示例5: 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);
}
示例6: 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);
}
}
示例7: test_comment
void test_comment(void **state)
{
Writer *w = StringWriter();
XmlComment(w, "foobar");
assert_string_equal(StringWriterClose(w), "<!-- foobar -->\n");
}
示例8: 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");
}
示例9: ShowVariablesFormatted
static void ShowVariablesFormatted(EvalContext *ctx)
{
VariableTableIterator *iter = EvalContextVariableTableIteratorNew(ctx, NULL, NULL, NULL);
Variable *v = NULL;
Seq *seq = SeqNew(2000, free);
while ((v = VariableTableIteratorNext(iter)))
{
char *varname = VarRefToString(v->ref, true);
Writer *w = StringWriter();
switch (DataTypeToRvalType(v->type))
{
case RVAL_TYPE_CONTAINER:
JsonWriteCompact(w, RvalContainerValue(v->rval));
break;
default:
RvalWrite(w, v->rval);
}
const char *var_value;
if (StringIsPrintable(StringWriterData(w)))
{
var_value = StringWriterData(w);
}
else
{
var_value = "<non-printable>";
}
StringSet *tagset = EvalContextVariableTags(ctx, v->ref);
Buffer *tagbuf = StringSetToBuffer(tagset, ',');
char *line;
xasprintf(&line, "%-40s %-60s %-40s", varname, var_value, BufferData(tagbuf));
SeqAppend(seq, line);
BufferDestroy(tagbuf);
WriterClose(w);
free(varname);
}
SeqSort(seq, (SeqItemComparator)strcmp, NULL);
printf("%-40s %-60s %-40s\n", "Variable name", "Variable value", "Meta tags");
for (size_t i = 0; i < SeqLength(seq); i++)
{
const char *variable = SeqAt(seq, i);
printf("%s\n", variable);
}
SeqDestroy(seq);
VariableTableIteratorDestroy(iter);
}
示例10: test_show_object_compound
static void test_show_object_compound(void **state)
{
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();
JsonElementPrint(writer, json, 0);
assert_string_equal(OBJECT_COMPOUND, StringWriterData(writer));
JsonElementDestroy(json);
}
示例11: test_empty
void test_empty(void **state)
{
Writer *w = StringWriter();
CsvWriter *c = CsvWriterOpen(w);
CsvWriterClose(c);
assert_string_equal(StringWriterClose(w), "");
}
示例12: LogPromiseContext
static void LogPromiseContext(const EvalContext *ctx, const Promise *pp)
{
Rval retval;
char *v;
if (EvalContextVariableControlCommonGet(ctx, COMMON_CONTROL_VERSION, &retval))
{
v = (char *) retval.item;
}
else
{
v = "not specified";
}
const char *sp = PromiseGetHandle(pp);
if (sp == NULL)
{
sp = PromiseID(pp);
}
if (sp == NULL)
{
sp = "(unknown)";
}
Log(LOG_LEVEL_INFO, "Report relates to a promise with handle '%s'", sp);
if (PromiseGetBundle(pp)->source_path)
{
Log(LOG_LEVEL_INFO, "Made in version '%s' of '%s' near line %zu",
v, PromiseGetBundle(pp)->source_path, pp->offset.line);
}
else
{
Log(LOG_LEVEL_INFO, "Promise is made internally by CFEngine");
}
switch (pp->promisee.type)
{
case RVAL_TYPE_SCALAR:
Log(LOG_LEVEL_INFO,"The promise was made to '%s'", (char *) pp->promisee.item);
break;
case RVAL_TYPE_LIST:
{
Writer *w = StringWriter();
RlistWrite(w, pp->promisee.item);
Log(LOG_LEVEL_INFO, "The promise was made to (stakeholders) '%s'", StringWriterData(w));
WriterClose(w);
break;
}
default:
break;
}
if (pp->comment)
{
Log(LOG_LEVEL_INFO, "Comment '%s'", pp->comment);
}
}
示例13: 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;
}
示例14: 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");
}
示例15: 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");
}