13 #include <sys/types.h>
47 #define RUBY_DOMAIN "ruby.yaml.org,2002"
52 static ID s_new,
s_utc,
s_at,
s_to_f,
s_to_i,
s_read,
s_binmode,
s_call,
s_cmp,
s_transfer,
s_update,
s_dup,
s_haskey,
s_match,
s_keys,
s_unpack,
s_tr_bang,
s_default_set,
s_tag_read_class,
s_tag_subclasses,
s_resolver,
s_push,
s_emitter,
s_level,
s_detect_implicit,
s_node_import,
s_out,
s_input,
s_intern,
s_transform,
s_yaml_new,
s_yaml_initialize,
s_node_export,
s_to_yaml,
s_write,
s_set_resolver,
s_each;
53 static ID s_tags,
s_kind,
s_name,
s_options,
s_type_id,
s_type_id_set,
s_style,
s_style_set,
s_value,
s_value_set,
s_parse;
57 static VALUE cDate,
cNode,
cMap,
cSeq,
cScalar,
cOut,
cParser,
cResolver,
cPrivateType,
cDomainType,
cYObject,
cBadAlias,
cDefaultKey,
cMergeKey,
cEmitter,
cDateTime;
63 static double S_zero(
void) {
return 0.0; }
64 static double S_one(
void) {
return 1.0; }
123 strcat( ret,
"D\n" );
124 strcat( ret, sav->
buffer );
144 if ( max_size <= 0 ) max_size = 0;
173 VALUE tmp, port = *pport;
220 const char *
str = arg->
str;
222 const char *ptr =
str;
232 if ( ptr[0] !=
'\0' && len > 0 ) {
238 if ( ptr[0] !=
'\0' && len > ptr - str ) {
239 while ( !
ISDIGIT( *ptr ) ) ptr++;
245 if ( ptr[0] !=
'\0' && len > ptr - str ) {
246 while ( !
ISDIGIT( *ptr ) ) ptr++;
252 if ( ptr[0] !=
'\0' && len > ptr - str ) {
253 while ( !
ISDIGIT( *ptr ) ) ptr++;
259 if ( ptr[0] !=
'\0' && len > ptr - str ) {
260 while ( !
ISDIGIT( *ptr ) ) ptr++;
266 if ( ptr[0] !=
'\0' && len > ptr - str ) {
267 while ( !
ISDIGIT( *ptr ) ) ptr++;
273 if ( len > ptr - str && *ptr ==
'.' )
275 char padded[] =
"000000";
276 const int padding = (int)(
sizeof(padded) - 1);
277 const char *end = ptr + 1;
278 const char *begin = end;
280 while ( isdigit( *end ) ) end++;
281 if ((length = (end - begin)) > padding) length = padding;
282 MEMCPY(padded, begin,
char, length);
291 while ( len > ptr - str && *ptr !=
'Z' && *ptr !=
'+' && *ptr !=
'-' && *ptr !=
'\0' ) ptr++;
292 if ( len > ptr - str && ( *ptr ==
'-' || *ptr ==
'+' ) )
297 while ( *ptr !=
':' && *ptr !=
'\0' ) ptr++;
376 if ( type_id !=
NULL && strncmp( type_id,
"tag:yaml.org,2002:", 18 ) == 0 )
385 if ( type_id ==
NULL )
389 else if ( strcmp( type_id,
"null" ) == 0 )
393 else if ( strcmp( type_id,
"binary" ) == 0 )
401 else if ( strcmp( type_id,
"bool#yes" ) == 0 )
405 else if ( strcmp( type_id,
"bool#no" ) == 0 )
409 else if ( strcmp( type_id,
"int#hex" ) == 0 )
414 else if ( strcmp( type_id,
"int#oct" ) == 0 )
419 else if ( strcmp( type_id,
"int#base60" ) == 0 )
430 char *colon = end - 1;
431 while ( colon >= ptr && *colon !=
':' )
435 if ( colon >= ptr && *colon ==
':' ) *colon =
'\0';
438 total += bnum * sixty;
444 else if ( strncmp( type_id,
"int", 3 ) == 0 )
449 else if ( strcmp( type_id,
"float#base60" ) == 0 )
460 char *colon = end - 1;
461 while ( colon >= ptr && *colon !=
':' )
465 if ( colon >= ptr && *colon ==
':' ) *colon =
'\0';
468 total += bnum * sixty;
474 else if ( strcmp( type_id,
"float#nan" ) == 0 )
478 else if ( strcmp( type_id,
"float#inf" ) == 0 )
482 else if ( strcmp( type_id,
"float#neginf" ) == 0 )
486 else if ( strncmp( type_id,
"float", 5 ) == 0 )
493 else if ( strcmp( type_id,
"timestamp#iso8601" ) == 0 )
497 else if ( strcmp( type_id,
"timestamp#spaced" ) == 0 )
501 else if ( strcmp( type_id,
"timestamp#ymd" ) == 0 )
504 VALUE year, mon, day;
512 while ( !
ISDIGIT( *ptr ) ) ptr++;
517 while ( !
ISDIGIT( *ptr ) ) ptr++;
530 else if ( strncmp( type_id,
"timestamp", 9 ) == 0 )
534 else if ( strncmp( type_id,
"merge", 5 ) == 0 )
538 else if ( strncmp( type_id,
"default", 7 ) == 0 )
544 strncmp( n->
data.
str->ptr,
":", 1 ) == 0 )
550 else if ( strcmp( type_id,
"str" ) == 0 )
563 if ( type_id ==
NULL || strcmp( type_id,
"seq" ) == 0 )
568 for ( i = 0; i < n->
data.
list->idx; i++ )
575 if ( type_id ==
NULL || strcmp( type_id,
"map" ) == 0 )
580 for ( i = 0; i < n->
data.
pairs->idx; i++ )
679 while ( *endl !=
'\0' && *endl !=
'\n' )
698 badanc->
type_id =
syck_strndup(
"tag:ruby.yaml.org,2002:object:YAML::Syck::BadAlias", 53 );
719 if (
NIL_P( input ) )
899 if ( parser->
eof == 1 )
980 for ( i = 0; i < n->
data.
list->idx; i++ )
988 for ( i = 0; i < n->
data.
pairs->idx; i++ )
1092 VALUE subclass = target_class;
1098 if (
NIL_P( target_class ) )
1109 if (
NIL_P( target_class ) )
1118 if ( !
NIL_P( target_class ) )
1120 subclass = target_class;
1129 if ( subclass_v !=
Qnil )
1131 subclass = subclass_v;
1163 else if ( !
NIL_P( target_class ) )
1187 if (
rb_str_cmp( scheme, str_xprivate ) == 0 )
1230 const char *type_id;
1404 for ( i = 0; i < n->
data.
list->idx; i++ )
1411 for ( i = 0; i < n->
data.
pairs->idx; i++ )
1462 if (
NIL_P( style ) )
1549 if ( !
NIL_P( val ) ) {
1626 if ( !
NIL_P( val ) )
1660 if ( !
NIL_P( val ) )
1761 if ( !
NIL_P( type_id ) ) {
1782 switch (orig_n->
kind)
1788 for ( i = 0; i < orig_n->
data.
pairs->idx; i++ )
1800 for ( i = 0; i < orig_n->
data.
list->idx; i++ )
1841 for ( i = 0; i < n->
data.
pairs->idx; i++ )
1854 for ( i = 0; i < n->
data.
list->idx; i++ )
2072 VALUE type_id, style, map;
2073 if (
rb_scan_args(argc, argv,
"11", &type_id, &style) == 1) {
2088 VALUE type_id, style, seq;
2089 if (
rb_scan_args(argc, argv,
"11", &type_id, &style) == 1) {
2107 rb_scan_args(argc, argv,
"21", &type_id, &str, &style);