3 #if !defined(RARRAY_CONST_PTR) 4 #define RARRAY_CONST_PTR(s) (const VALUE *)RARRAY_PTR(s) 6 #if !defined(RARRAY_AREF) 7 #define RARRAY_AREF(a, i) RARRAY_CONST_PTR(a)[i] 13 static ID id_line_width;
14 static ID id_indentation;
15 static ID id_canonical;
17 static void emit(yaml_emitter_t * emitter, yaml_event_t * event)
19 if(!yaml_emitter_emit(emitter, event))
23 static int writer(
void *ctx,
unsigned char *buffer,
size_t size)
31 static void dealloc(
void * ptr)
33 yaml_emitter_t * emitter;
35 emitter = (yaml_emitter_t *)ptr;
36 yaml_emitter_delete(emitter);
41 static size_t memsize(
const void *ptr)
43 const yaml_emitter_t *emitter = ptr;
53 #ifdef RUBY_TYPED_FREE_IMMEDIATELY 60 yaml_emitter_t * emitter;
63 yaml_emitter_initialize(emitter);
64 yaml_emitter_set_unicode(emitter, 1);
65 yaml_emitter_set_indent(emitter, 2);
76 yaml_emitter_t * emitter;
85 line_width =
rb_funcall(options, id_line_width, 0);
86 indent =
rb_funcall(options, id_indentation, 0);
87 canonical =
rb_funcall(options, id_canonical, 0);
89 yaml_emitter_set_width(emitter,
NUM2INT(line_width));
90 yaml_emitter_set_indent(emitter,
NUM2INT(indent));
91 yaml_emitter_set_canonical(emitter,
Qtrue == canonical ? 1 : 0);
95 yaml_emitter_set_output(emitter, writer, (
void *)
self);
108 yaml_emitter_t * emitter;
113 yaml_stream_start_event_initialize(&event, (yaml_encoding_t)
NUM2INT(encoding));
115 emit(emitter, &event);
128 yaml_emitter_t * emitter;
132 yaml_stream_end_event_initialize(&event);
134 emit(emitter, &event);
148 yaml_emitter_t * emitter;
149 yaml_tag_directive_t * head =
NULL;
150 yaml_tag_directive_t * tail =
NULL;
152 yaml_version_directive_t version_directive;
162 version_directive.major =
NUM2INT(major);
163 version_directive.minor =
NUM2INT(minor);
174 head =
xcalloc((
size_t)len,
sizeof(yaml_tag_directive_t));
177 for(i = 0; i < len && i <
RARRAY_LEN(tags); i++) {
202 yaml_document_start_event_initialize(
210 emit(emitter, &event);
212 if(head)
xfree(head);
225 yaml_emitter_t * emitter;
229 yaml_document_end_event_initialize(&event, imp ? 1 : 0);
231 emit(emitter, &event);
252 yaml_emitter_t * emitter;
273 yaml_scalar_event_initialize(
281 (yaml_scalar_style_t)
NUM2INT(style)
284 emit(emitter, &event);
296 static VALUE start_sequence(
303 yaml_emitter_t * emitter;
320 yaml_sequence_start_event_initialize(
325 (yaml_sequence_style_t)
NUM2INT(style)
328 emit(emitter, &event);
341 yaml_emitter_t * emitter;
345 yaml_sequence_end_event_initialize(&event);
347 emit(emitter, &event);
359 static VALUE start_mapping(
366 yaml_emitter_t * emitter;
384 yaml_mapping_start_event_initialize(
389 (yaml_mapping_style_t)
NUM2INT(style)
392 emit(emitter, &event);
405 yaml_emitter_t * emitter;
409 yaml_mapping_end_event_initialize(&event);
411 emit(emitter, &event);
424 yaml_emitter_t * emitter;
433 yaml_alias_event_initialize(
438 emit(emitter, &event);
449 yaml_emitter_t * emitter;
452 yaml_emitter_set_canonical(emitter,
Qtrue == style ? 1 : 0);
463 yaml_emitter_t * emitter;
476 yaml_emitter_t * emitter;
479 yaml_emitter_set_indent(emitter,
NUM2INT(level));
490 yaml_emitter_t * emitter;
493 return INT2NUM(emitter->best_indent);
502 yaml_emitter_t * emitter;
505 return INT2NUM(emitter->best_width);
514 yaml_emitter_t * emitter;
517 yaml_emitter_set_width(emitter,
NUM2INT(width));
551 id_indentation =
rb_intern(
"indentation");
VALUE rb_ary_entry(VALUE ary, long offset)
#define RUBY_TYPED_FREE_IMMEDIATELY
void Init_psych_emitter(void)
void rb_raise(VALUE exc, const char *fmt,...)
#define TypedData_Get_Struct(obj, type, data_type, sval)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
rb_encoding * rb_utf8_encoding(void)
RUBY_EXTERN VALUE rb_cObject
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_ivar_set(VALUE, ID, VALUE)
register unsigned int len
#define StringValueCStr(v)
#define RARRAY_AREF(a, i)
VALUE rb_str_export_to_enc(VALUE, rb_encoding *)
#define TypedData_Make_Struct(klass, type, data_type, sval)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
#define StringValuePtr(v)
VALUE rb_define_module(const char *name)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_attr_get(VALUE, ID)