Exemplo n.º 1
0
static VALUE
rb_yaml_emitter_document(VALUE self, SEL sel, int argc, VALUE *argv)
{
    yaml_emitter_t *emitter = &RYAMLEmitter(self)->emitter;

    VALUE impl_beg = Qnil, impl_end = Qnil;
    rb_scan_args(argc, argv, "02", &impl_beg, &impl_end);
    if (NIL_P(impl_beg)) {
	impl_beg = Qfalse;
    }
    if (NIL_P(impl_end)) {
	impl_end = Qtrue;
    }

    yaml_event_t ev;
    yaml_document_start_event_initialize(&ev, NULL, NULL, NULL, 0);
    yaml_emitter_emit(emitter, &ev);

    rb_yield(self);

    yaml_document_end_event_initialize(&ev, 1);
    yaml_emitter_emit(emitter, &ev);
    yaml_emitter_flush(emitter);
    return self;
}
Exemplo n.º 2
0
static int
yaml_emitter_dump_mapping(yaml_emitter_t *emitter, yaml_node_t *node,
        yaml_char_t *anchor)
{
    yaml_event_t event;
    yaml_mark_t mark  = { 0, 0, 0 };

    int implicit = (strcmp((char *)node->tag, YAML_DEFAULT_MAPPING_TAG) == 0);

    yaml_node_pair_t *pair;

    MAPPING_START_EVENT_INIT(event, anchor, node->tag, implicit,
            node->data.mapping.style, mark, mark);
    if (!yaml_emitter_emit(emitter, &event)) return 0;

    for (pair = node->data.mapping.pairs.start;
            pair < node->data.mapping.pairs.top; pair ++) {
        if (!yaml_emitter_dump_node(emitter, pair->key)) return 0;
        if (!yaml_emitter_dump_node(emitter, pair->value)) return 0;
    }

    MAPPING_END_EVENT_INIT(event, mark, mark);
    if (!yaml_emitter_emit(emitter, &event)) return 0;

    return 1;
}
Exemplo n.º 3
0
static bool emit_mapping(node *mapping, void *context)
{
    log_trace(component, "emitting mapping");
    yaml_emitter_t *emitter = (yaml_emitter_t *)context;
    yaml_event_t event;

    log_trace(component, "mapping start");
    uint8_t *name = node_name(mapping);
    yaml_char_t *tag = NULL == name ? (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG : (yaml_char_t *)name;
    yaml_mapping_start_event_initialize(&event, NULL, tag, NULL == name, YAML_BLOCK_MAPPING_STYLE);
    if (!yaml_emitter_emit(emitter, &event))
        return false;

    if(!mapping_iterate(mapping, emit_mapping_item, context))
    {
        return false;
    }

    log_trace(component, "mapping end");
    yaml_mapping_end_event_initialize(&event);
    if (!yaml_emitter_emit(emitter, &event))
        return false;

    return true;
}
Exemplo n.º 4
0
static int
yaml_emitter_dump_sequence(yaml_emitter_t *emitter, yaml_node_t *node,
        yaml_char_t *anchor)
{
    yaml_event_t event;
    yaml_mark_t mark  = { 0, 0, 0 };

    int implicit = (strcmp((char *)node->tag, YAML_DEFAULT_SEQUENCE_TAG) == 0);

    yaml_node_item_t *item;

    SEQUENCE_START_EVENT_INIT(event, anchor, node->tag, implicit,
            node->data.sequence.style, mark, mark);
    if (!yaml_emitter_emit(emitter, &event)) return 0;

    for (item = node->data.sequence.items.start;
            item < node->data.sequence.items.top; item ++) {
        if (!yaml_emitter_dump_node(emitter, *item)) return 0;
    }

    SEQUENCE_END_EVENT_INIT(event, mark, mark);
    if (!yaml_emitter_emit(emitter, &event)) return 0;

    return 1;
}
Exemplo n.º 5
0
static bool emit_sequence(node *sequence, void *context)
{
    log_trace(component, "emitting seqence");
    yaml_emitter_t *emitter = (yaml_emitter_t *)context;
    yaml_event_t event;

    log_trace(component, "seqence start");
    uint8_t *name = node_name(sequence);
    yaml_char_t *tag = NULL == name ? (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG : (yaml_char_t *)name;
    yaml_sequence_start_event_initialize(&event, NULL, tag, NULL == name, YAML_BLOCK_SEQUENCE_STYLE);
    if (!yaml_emitter_emit(emitter, &event))
        return false;

    if(!sequence_iterate(sequence, emit_sequence_item, context))
    {
        return false;
    }

    log_trace(component, "seqence end");
    yaml_sequence_end_event_initialize(&event);
    if (!yaml_emitter_emit(emitter, &event))
        return false;

    return true;
}
Exemplo n.º 6
0
int MapObject::yamlDocEpilog(yaml_emitter_t *emitter, yaml_event_t *event) {
	yaml_document_end_event_initialize(event, true);
	yaml_emitter_emit(emitter, event);
 
	yaml_stream_end_event_initialize(event);
	yaml_emitter_emit(emitter, event);
 
	return 1;
}
Exemplo n.º 7
0
int MapObject::yamlDocProlog(yaml_emitter_t *emitter, yaml_event_t *event) {
	yaml_stream_start_event_initialize(event, YAML_UTF8_ENCODING);
 
	if (!yaml_emitter_emit(emitter, event)) {
		yaml_emitter_delete(emitter);
		return 0;
	}
 
	yaml_document_start_event_initialize(event, NULL, NULL, NULL, true);
	yaml_emitter_emit(emitter, event);
 
	return 1;
}
Exemplo n.º 8
0
void emit_yaml(const nodelist *list, const struct settings *settings)
{
    log_debug(component, "emitting...");
    yaml_emitter_t emitter;
    yaml_event_t event;

    yaml_emitter_initialize(&emitter);
    yaml_emitter_set_output_file(&emitter, stdout);
    yaml_emitter_set_unicode(&emitter, 1);

    log_trace(component, "stream start");
    yaml_stream_start_event_initialize(&event, YAML_UTF8_ENCODING);
    if (!yaml_emitter_emit(&emitter, &event))
        goto error;

    log_trace(component, "document start");
    yaml_document_start_event_initialize(&event, &(yaml_version_directive_t){1, 1}, NULL, NULL, 0);
    if (!yaml_emitter_emit(&emitter, &event))
        goto error;

    if(1 == nodelist_length(list))
    {
        if(!emit_node(nodelist_get(list, 0), &emitter))
        {
            fprintf(stderr, "%s: %s\n", settings->program_name, emitter.problem);
            goto error;
        }
    }
    else
    {
        if(!emit_nodelist(list, &emitter))
        {
            fprintf(stderr, "%s: %s\n", settings->program_name, emitter.problem);
            goto error;
        }
    }

    log_trace(component, "document end");
    yaml_document_end_event_initialize(&event, 1);
    if (!yaml_emitter_emit(&emitter, &event))
        goto error;

    log_trace(component, "stream end");
    yaml_stream_end_event_initialize(&event);
    if (!yaml_emitter_emit(&emitter, &event))
        goto error;

  error:
    yaml_emitter_delete(&emitter);
    fflush(stdout);
}
Exemplo n.º 9
0
yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document)
{
    yaml_event_t event;
    yaml_mark_t mark = { 0, 0, 0 };

    assert(emitter);            /* Non-NULL emitter object is required. */
    assert(document);           /* Non-NULL emitter object is expected. */

    emitter->document = document;

    if (!emitter->opened) {
        if (!yaml_emitter_open(emitter)) goto error;
    }

    if (STACK_EMPTY(emitter, document->nodes)) {
        if (!yaml_emitter_close(emitter)) goto error;
        yaml_emitter_delete_document_and_anchors(emitter);
        return 1;
    }

    assert(emitter->opened);    /* Emitter should be opened. */

    emitter->anchors = yaml_malloc(sizeof(*(emitter->anchors))
            * (document->nodes.top - document->nodes.start));
    if (!emitter->anchors) goto error;
    memset(emitter->anchors, 0, sizeof(*(emitter->anchors))
            * (document->nodes.top - document->nodes.start));

    DOCUMENT_START_EVENT_INIT(event, document->version_directive,
            document->tag_directives.start, document->tag_directives.end,
            document->start_implicit, mark, mark);
    if (!yaml_emitter_emit(emitter, &event)) goto error;

    yaml_emitter_anchor_node(emitter, 1);
    if (!yaml_emitter_dump_node(emitter, 1)) goto error;

    DOCUMENT_END_EVENT_INIT(event, document->end_implicit, mark, mark);
    if (!yaml_emitter_emit(emitter, &event)) goto error;

    yaml_emitter_delete_document_and_anchors(emitter);

    return 1;

error:

    yaml_emitter_delete_document_and_anchors(emitter);

    return 0;
}
Exemplo n.º 10
0
/* Emit a SEQUENCE_START event. */
static int
emit_SEQUENCE_START (lua_State *L, lyaml_emitter *emitter)
{
   yaml_event_t event;
   yaml_sequence_style_t yaml_style;
   yaml_char_t *anchor = NULL, *tag = NULL;
   int implicit = 1;
   const char *style = NULL;

   RAWGET_STRDUP (style);  lua_pop (L, 1);

#define MENTRY(_s) (STREQ (style, #_s)) { yaml_style = YAML_##_s##_SEQUENCE_STYLE; }
   if (style == NULL) { yaml_style = YAML_ANY_SEQUENCE_STYLE; } else
   if MENTRY( BLOCK	) else
   if MENTRY( FLOW	) else
   {
      emitter->error++;
      lua_pushfstring (L, "invalid sequence style '%s'", style);
      lua_insert (L, -2);
   }
#undef MENTRY

   RAWGET_YAML_CHARP (anchor); lua_pop (L, 1);
   RAWGET_YAML_CHARP (tag);    lua_pop (L, 1);
   RAWGET_BOOLEAN (implicit);  lua_pop (L, 1);

   yaml_sequence_start_event_initialize (&event, anchor, tag, implicit, yaml_style);
   return yaml_emitter_emit (&emitter->emitter, &event);
}
Exemplo n.º 11
0
std::string MapObject::exportYaml() {
	yaml_emitter_t emitter;
	yaml_event_t event;
 
	std::string exportValue = "";
 
	yaml_emitter_initialize(&emitter);
	yaml_emitter_set_output(&emitter, write_handler, &exportValue);
	yaml_emitter_set_encoding(&emitter, YAML_UTF8_ENCODING);
 
	if (! yamlDocProlog(&emitter, &event))
		return "";
 
	if (this->mapPtr->map.size()) yamlMap(&emitter, &event, this->mapPtr);
	else if (this->mapObjects.size()) yamlSequence(&emitter, &event, &this->mapObjects);
	else {
		yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*) (this->value.c_str()), (int) this->value.length(), 1, 1, YAML_ANY_SCALAR_STYLE);
		yaml_emitter_emit(&emitter, &event);
	}
 
	yamlDocEpilog(&emitter, &event);
 
	yaml_event_delete(&event);
	yaml_emitter_delete(&emitter);
 
	return exportValue;
}
Exemplo n.º 12
0
static VALUE
rb_yaml_emitter_scalar(VALUE self, SEL sel, VALUE taguri, VALUE val,
	VALUE style)
{
    yaml_event_t ev;
    yaml_emitter_t *emitter = &RYAMLEmitter(self)->emitter;
    yaml_char_t *output = (yaml_char_t *)RSTRING_PTR(val);
    const size_t length = strlen((const char *)output);

    int can_omit_tag = 0;
    int string_tag   = 0;
    yaml_char_t *tag = rb_yaml_tag_or_null(taguri, &can_omit_tag, &string_tag);
    yaml_scalar_style_t sstyl = rb_symbol_to_scalar_style(style);
    if (string_tag
	    && (sstyl==YAML_ANY_SCALAR_STYLE || sstyl==YAML_PLAIN_SCALAR_STYLE)
	    && (detect_scalar_type((const char *)output, length) != NULL)) {
	// Quote so this is read back as a string, no matter what type it
	// looks like.
	sstyl = YAML_DOUBLE_QUOTED_SCALAR_STYLE;
    }
    yaml_scalar_event_initialize(&ev, NULL, tag, output, length,
	    can_omit_tag, can_omit_tag, sstyl);
    yaml_emitter_emit(emitter, &ev);

    return self;
}
Exemplo n.º 13
0
void MapObject::exportYaml(std::wstring fileName) {
	yaml_emitter_t emitter;
	yaml_event_t event;
 
	FILE *file;
	_wfopen_s(&file, fileName.c_str(), _T("wb"));
 
	yaml_emitter_initialize(&emitter);
	yaml_emitter_set_output_file(&emitter, file);
	yaml_emitter_set_encoding(&emitter, YAML_UTF8_ENCODING);
 
	if (! yamlDocProlog(&emitter, &event))
		return;
 
	if (this->mapPtr->map.size()) yamlMap(&emitter, &event, this->mapPtr);
	else if (this->mapObjects.size()) yamlSequence(&emitter, &event, &this->mapObjects, (this->flow == true ? 1 : 0));
	else {
		yaml_scalar_event_initialize(&event, NULL, NULL, (yaml_char_t*) (this->value.c_str()), (int) this->value.length(), 1, 1, YAML_ANY_SCALAR_STYLE);
		yaml_emitter_emit(&emitter, &event);
	}
 
	yamlDocEpilog(&emitter, &event);
	yaml_emitter_flush(&emitter);
	fclose(file);
 
	yaml_event_delete(&event);
	yaml_emitter_delete(&emitter);
}
Exemplo n.º 14
0
/* Emit a MAPPING_END event. */
static int
emit_MAPPING_END (lua_State *L, lyaml_emitter *emitter)
{
   yaml_event_t event;
   yaml_mapping_end_event_initialize (&event);
   return yaml_emitter_emit (&emitter->emitter, &event);
}
Exemplo n.º 15
0
/* Emit a SEQUENCE_END event. */
static int
emit_SEQUENCE_END (lua_State *L, lyaml_emitter *emitter)
{
   yaml_event_t event;
   yaml_sequence_end_event_initialize (&event);
   return yaml_emitter_emit (&emitter->emitter, &event);
}
Exemplo n.º 16
0
/* Emit a SCALAR event. */
static int
emit_SCALAR (lua_State *L, lyaml_emitter *emitter)
{
   yaml_event_t event;
   yaml_scalar_style_t yaml_style;
   yaml_char_t *anchor = NULL, *tag = NULL, *value;
   int length = 0, plain_implicit = 1, quoted_implicit = 1;
   const char *style = NULL;

   RAWGET_STRDUP (style);  lua_pop (L, 1);

#define MENTRY(_s) (STREQ (style, #_s)) { yaml_style = YAML_##_s##_SCALAR_STYLE; }
   if (style == NULL) { yaml_style = YAML_ANY_SCALAR_STYLE; } else
   if MENTRY( PLAIN		) else
   if MENTRY( SINGLE_QUOTED	) else
   if MENTRY( DOUBLE_QUOTED	) else
   if MENTRY( LITERAL		) else
   if MENTRY( FOLDED		) else
   {
      emitter->error++;
      lua_pushfstring (L, "invalid scalar style '%s'", style);
      lua_insert (L, -2);
   }
#undef MENTRY

   RAWGET_YAML_CHARP (anchor); lua_pop (L, 1);
   RAWGET_YAML_CHARP (tag);    lua_pop (L, 1);
   RAWGET_YAML_CHARP (value);  length = lua_objlen (L, -1); lua_pop (L, 1);

   yaml_scalar_event_initialize (&event, anchor, tag, value, length,
      plain_implicit, quoted_implicit, yaml_style);
   return yaml_emitter_emit (&emitter->emitter, &event);
}
Exemplo n.º 17
0
/* Emit a STREAM_START event. */
static int
emit_STREAM_START (lua_State *L, lyaml_emitter *emitter)
{
   yaml_event_t event;
   yaml_encoding_t yaml_encoding;
   const char *encoding = NULL;

   RAWGET_STRDUP (encoding); lua_pop (L, 1);

#define MENTRY(_s) (STREQ (encoding, #_s)) { yaml_encoding = YAML_##_s##_ENCODING; }
   if (encoding == NULL) { yaml_encoding = YAML_ANY_ENCODING; } else
   if MENTRY( UTF8	) else
   if MENTRY( UTF16LE	) else
   if MENTRY( UTF16BE	) else
   {
      emitter->error++;
      lua_pushfstring (L, "invalid stream encoding '%s'", encoding);
      lua_insert (L, -2);
   }
#undef MENTRY

   if (encoding) free ((void *) encoding);

   if (emitter->error != 0)
     return 0;

   yaml_stream_start_event_initialize (&event, yaml_encoding);
   return yaml_emitter_emit (&emitter->emitter, &event);
}
Exemplo n.º 18
0
/* Emit a STREAM_END event. */
static int
emit_STREAM_END (lua_State *L, lyaml_emitter *emitter)
{
   yaml_event_t event;
   yaml_stream_end_event_initialize (&event);
   return yaml_emitter_emit (&emitter->emitter, &event);
}
Exemplo n.º 19
0
int print_config_to_emitter(yaml_emitter_t emitter, 
                            const config_t conf){
    yaml_event_t event;
    
    int r = CONF_OK;
    yaml_stream_start_event_initialize(&event, YAML_UTF8_ENCODING);
    r = yaml_emitter_emit(&emitter, &event);
    if(r){
            r = emit(&emitter, conf);
    }
    if(r){
            yaml_stream_end_event_initialize(&event);    
            r = yaml_emitter_emit(&emitter, &event);   
    }
    return r;            
}
Exemplo n.º 20
0
void yamlTryEmit(yaml_emitter_t *emitter,
                 yaml_event_t *event)
{
  if (!yaml_emitter_emit(emitter, event))
  {
    throw YamlException();
  }
}
Exemplo n.º 21
0
/* Emit a DOCUMENT_START event. */
static int
emit_DOCUMENT_START (lua_State *L, lyaml_emitter *emitter)
{
   yaml_event_t event;
   yaml_version_directive_t version_directive, *Pversion_directive = NULL;
   yaml_tag_directive_t *tag_directives_start = NULL, *tag_directives_end = NULL;
   int implicit = 0;

   RAWGET_PUSHTABLE ("version_directive");
   if (lua_type (L, -1) == LUA_TTABLE)
   {
      RAWGETS_INTEGER (version_directive.major, "major");
      ERROR_IFNIL ("version_directive missing key 'major'");
      if (emitter->error == 0)
      {
         RAWGETS_INTEGER (version_directive.minor, "minor");
         ERROR_IFNIL ("version_directive missing key 'minor'");
      }
      Pversion_directive = &version_directive;
   }
   lua_pop (L, 1);		/* pop version_directive rawget */

   RAWGET_PUSHTABLE ("tag_directives");
   if (lua_type (L, -1) == LUA_TTABLE)
   {
      size_t bytes = lua_objlen (L, -1) * sizeof (yaml_tag_directive_t);

      tag_directives_start = (yaml_tag_directive_t *) malloc (bytes);
      tag_directives_end = tag_directives_start;

      lua_pushnil (L);	/* first key */
      while (lua_next (L, -2) != 0)
      {
         RAWGETS_STRDUP (tag_directives_end->handle, "handle");
         ERROR_IFNIL ("tag_directives item missing key 'handle'");
         lua_pop (L, 1);	/* pop handle */

         RAWGETS_STRDUP (tag_directives_end->prefix, "prefix");
         ERROR_IFNIL ("tag_directives item missing key 'prefix'");
         lua_pop (L, 1);	/* pop prefix */

         tag_directives_end += 1;

         /* pop tag_directives list elewent, leave key for next iteration */
         lua_pop (L, 1);
      }
   }
   lua_pop (L, 1);	/* pop lua_rawget "tag_directives" result */

   RAWGET_BOOLEAN (implicit); lua_pop (L, 1);

   if (emitter->error != 0)
      return 0;

   yaml_document_start_event_initialize (&event, Pversion_directive,
      tag_directives_start, tag_directives_end, implicit);
   return yaml_emitter_emit (&emitter->emitter, &event);
}
Exemplo n.º 22
0
static int
yaml_emitter_dump_alias (yaml_emitter_t* emitter, yaml_char_t* anchor) {
  yaml_event_t event;
  yaml_mark_t mark  = { 0, 0, 0 };

  ALIAS_EVENT_INIT (event, anchor, mark, mark);

  return yaml_emitter_emit (emitter, &event);
  }
Exemplo n.º 23
0
result_t CYamlEmitter::SaveStreamEnd ( yaml_emitter_t& _emitter ) const
{
    result_t result_t = eResult_OK;

    yaml_event_t event;
    yaml_stream_end_event_initialize ( &event );
    yaml_emitter_emit ( &_emitter, &event ) || yaml_emitter_flush ( &_emitter );

    return eResult;
}
Exemplo n.º 24
0
int emit(yaml_emitter_t *emitter, const config_t conf) {
    int r = CONF_OK;     
   
    yaml_event_t evt;

    //doc start
    yaml_document_start_event_initialize(&evt, 
                                        NULL, 
                                        NULL, 
                                        NULL, 
                                        CONF_F); 
	yaml_emitter_emit(emitter, &evt); 		
   // log_yml_event(evt);
    
    yaml_mapping_start_event_initialize(&evt,
    	                                NULL,
    	                                NULL,
    	                                CONF_F,
    	                                YAML_BLOCK_MAPPING_STYLE);
    yaml_emitter_emit(emitter, &evt);
   // log_yml_event(evt);

    entry_t iter = conf->map[0];
    int i = 0;
    while(i < conf->size) {
        if(iter){
    	    emit_entry(iter, emitter);
    	}
    	iter = conf->map[++i];
    }
   
    //mapping end
    yaml_mapping_end_event_initialize(&evt); 	
    yaml_emitter_emit(emitter, &evt); 		
    //log_yml_event(evt);
    
    //doc end
    yaml_document_end_event_initialize(&evt,CONF_F);
    yaml_emitter_emit(emitter, &evt);
    //log_yml_event(evt); 		
    yaml_event_delete(&evt); 	
    return r;
}
Exemplo n.º 25
0
result_t CYamlEmitter::SaveStreamStart ( yaml_emitter_t& _emitter ) const
{
    result_t result_t = eResult_OK;

    yaml_event_t event;
    yaml_stream_start_event_initialize ( &event, GetEncoding(m_Encoding) );
    yaml_emitter_emit ( &_emitter, &event ) || yaml_emitter_flush ( &_emitter );

    return eResult;
}
Exemplo n.º 26
0
static VALUE
rb_yaml_emitter_stream(VALUE self, SEL sel)
{
    yaml_event_t ev;
    yaml_emitter_t *emitter = &RYAMLEmitter(self)->emitter;

    // RADAR: allow the encoding to be configurable
    yaml_stream_start_event_initialize(&ev, YAML_UTF8_ENCODING); 
    yaml_emitter_emit(emitter, &ev);

    rb_yield(self);

    yaml_stream_end_event_initialize(&ev);
    yaml_emitter_emit(emitter, &ev);
    yaml_emitter_flush(emitter);
    yaml_emitter_delete(emitter);
    // XXX: more cleanup here...
    return RYAMLEmitter(self)->output;
}
Exemplo n.º 27
0
static VALUE
rb_yaml_emitter_mapping(VALUE self, SEL sel, VALUE taguri, VALUE style)
{
    yaml_event_t ev;
    yaml_emitter_t *emitter = &RYAMLEmitter(self)->emitter;

    int can_omit_tag = 0;
    int string_tag   = 0;
    yaml_char_t *tag = rb_yaml_tag_or_null(taguri, &can_omit_tag, &string_tag);
    yaml_mapping_start_event_initialize(&ev, NULL, tag, can_omit_tag,
	    rb_symbol_to_mapping_style(style));
    yaml_emitter_emit(emitter, &ev);

    rb_yield(self);

    yaml_mapping_end_event_initialize(&ev);
    yaml_emitter_emit(emitter, &ev);
    return self;
}
Exemplo n.º 28
0
/* Emit an ALIAS event. */
static int
emit_ALIAS (lua_State *L, lyaml_emitter *emitter)
{
   yaml_event_t event;
   yaml_char_t *anchor;

   RAWGET_YAML_CHARP (anchor);

   yaml_alias_event_initialize (&event, anchor);
   return yaml_emitter_emit (&emitter->emitter, &event);
}
Exemplo n.º 29
0
/* Emit a DOCUMENT_END event. */
static int
emit_DOCUMENT_END (lua_State *L, lyaml_emitter *emitter)
{
   yaml_event_t event;
   int implicit = 0;

   RAWGET_BOOLEAN (implicit);

   yaml_document_end_event_initialize (&event, implicit);
   return yaml_emitter_emit (&emitter->emitter, &event);
}
Exemplo n.º 30
0
int MapObject::yamlSequence(yaml_emitter_t *emitter, yaml_event_t *event, std::vector<MapObject>* mapObjects, int flow_style) {
	if (mapObjects->size()) {
		yaml_sequence_start_event_initialize(event, NULL, NULL, true, (flow_style == false ? YAML_BLOCK_SEQUENCE_STYLE : YAML_FLOW_SEQUENCE_STYLE));
		yaml_emitter_emit(emitter, event);
 
		for (auto it = mapObjects->begin(); it != mapObjects->end(); it++) {
			if (it->mapPtr->map.size())
				yamlMap(emitter, event, it->mapPtr);
			else if (it->mapObjects.size())
				yamlSequence(emitter, event, &it->mapObjects, (it->flow == true ? 1 : 0));
			else if (! it->value.empty()) {
				yaml_scalar_event_initialize(event, NULL, NULL, (yaml_char_t*) it->value.c_str(), (int) it->value.length(), 1, 1, YAML_ANY_SCALAR_STYLE);
				yaml_emitter_emit(emitter, event);
			}
		}
 
		yaml_sequence_end_event_initialize(event);
		yaml_emitter_emit(emitter, event);
	}
	return 1;
}