instance method
Psych::Emitter#scalar
emitter.scalar(value, anchor, tag, plain, quoted, style)
ext/psych/psych_emitter.c
View on GitHub ↗
static VALUE scalar(
VALUE self,
VALUE value,
VALUE anchor,
VALUE tag,
VALUE plain,
VALUE quoted,
VALUE style
) {
yaml_emitter_t * emitter;
yaml_event_t event;
rb_encoding *encoding;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
Check_Type(value, T_STRING);
encoding = rb_utf8_encoding();
value = rb_str_export_to_enc(value, encoding);
if(!NIL_P(anchor)) {
Check_Type(anchor, T_STRING);
anchor = rb_str_export_to_enc(anchor, encoding);
}
if(!NIL_P(tag)) {
Check_Type(tag, T_STRING);
tag = rb_str_export_to_enc(tag, encoding);
}
const char *value_ptr = StringValuePtr(value);
yaml_scalar_event_initialize(
&event,
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
(yaml_char_t*)value_ptr,
(int)RSTRING_LEN(value),
plain ? 1 : 0,
quoted ? 1 : 0,
(yaml_scalar_style_t)NUM2INT(style)
);
emit(emitter, &event);
return self;
}
Emit a scalar with value, anchor, tag, and a plain or quoted string type with style.
See also
#line_width=
#start_document
#line_width
#start_mapping
also in
4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0