summaryrefslogtreecommitdiff
path: root/ext/syck/emitter.c
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-20 06:46:45 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-20 06:46:45 +0000
commitb36eba6e8752f794d898b9543e40868ad46c2ea9 (patch)
treee1dd7146e9bc2cfb3f97950abb16ce6f78b9d943 /ext/syck/emitter.c
parent56a97f11d039e2fd9107ea76ec2d0af2e447136e (diff)
* ext/syck/emitter.c (syck_scan_scalar): prevent indicators from
appearing alone or at the end of plain scalars. [ruby-core:5826] * ext/syck/emitter.c (syck_emit_scalar): treat typed scalar nodes as complex keys. * lib/syck.h: version 0.60. * lib/yaml/basenode.rb (YAML::BaseNode#at): transform keys during key searches. * ext/syck/rubyext.c: loading of binary-typed nodes. prevent emission of plain strings that look like symbols, but which aren't. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/syck/emitter.c')
-rw-r--r--ext/syck/emitter.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/ext/syck/emitter.c b/ext/syck/emitter.c
index 5cc0906296..f5de4b841a 100644
--- a/ext/syck/emitter.c
+++ b/ext/syck/emitter.c
@@ -560,7 +560,8 @@ syck_scan_scalar( int req_width, char *cursor, long len )
}
if ( ( cursor[0] == '-' || cursor[0] == ':' ||
cursor[0] == '?' || cursor[0] == ',' ) &&
- cursor[1] == ' ' ) {
+ ( cursor[1] == ' ' || cursor[1] == '\n' || len == 1 ) )
+ {
flags |= SCAN_INDIC_S;
}
@@ -619,11 +620,13 @@ syck_scan_scalar( int req_width, char *cursor, long len )
}
/* remember, if plain collections get implemented, to add nb-plain-flow-char */
else if ( ( cursor[i] == ' ' && cursor[i+1] == '#' ) ||
- ( cursor[i] == ':' && cursor[i+1] == ' ' ) )
+ ( cursor[i] == ':' &&
+ ( cursor[i+1] == ' ' || cursor[i+1] == '\n' || i == len - 1 ) ) )
{
flags |= SCAN_INDIC_C;
}
- else if ( cursor[i] == ',' && cursor[i+1] == ' ' )
+ else if ( cursor[i] == ',' &&
+ ( cursor[i+1] == ' ' || cursor[i+1] == '\n' || i == len - 1 ) )
{
flags |= SCAN_FLOWMAP;
flags |= SCAN_FLOWSEQ;
@@ -643,7 +646,7 @@ void syck_emit_scalar( SyckEmitter *e, char *tag, enum scalar_style force_style,
enum scalar_style favor_style = scalar_literal;
SyckLevel *parent = syck_emitter_parent_level( e );
SyckLevel *lvl = syck_emitter_current_level( e );
- int scan;
+ int scan = 0;
char *implicit;
if ( str == NULL ) str = "";
@@ -664,6 +667,14 @@ void syck_emit_scalar( SyckEmitter *e, char *tag, enum scalar_style force_style,
if ( syck_tagcmp( tag, implicit ) != 0 && syck_tagcmp( tag, "tag:yaml.org,2002:str" ) == 0 ) {
force_style = scalar_2quote;
} else {
+ /* complex key */
+ if ( parent->status == syck_lvl_map && parent->ncount % 2 == 1 &&
+ ( !( tag == NULL ||
+ ( implicit != NULL && syck_tagcmp( tag, implicit ) == 0 && e->explicit_typing == 0 ) ) ) )
+ {
+ syck_emitter_write( e, "? ", 2 );
+ parent->status = syck_lvl_mapx;
+ }
syck_emit_tag( e, tag, implicit );
}
S_FREE( implicit );
@@ -711,7 +722,7 @@ void syck_emit_scalar( SyckEmitter *e, char *tag, enum scalar_style force_style,
}
/* For now, all ambiguous keys are going to be double-quoted */
- if ( parent->status == syck_lvl_map && parent->ncount % 2 == 1 ) {
+ if ( ( parent->status == syck_lvl_map || parent->status == syck_lvl_mapx ) && parent->ncount % 2 == 1 ) {
if ( force_style != scalar_plain ) {
force_style = scalar_2quote;
}
@@ -738,6 +749,7 @@ void syck_emit_scalar( SyckEmitter *e, char *tag, enum scalar_style force_style,
syck_emit_1quoted( e, force_width, str, len );
break;
+ case scalar_none:
case scalar_2quote:
syck_emit_2quoted( e, force_width, str, len );
break;
@@ -754,6 +766,11 @@ void syck_emit_scalar( SyckEmitter *e, char *tag, enum scalar_style force_style,
syck_emitter_write( e, str, len );
break;
}
+
+ if ( parent->status == syck_lvl_mapx )
+ {
+ syck_emitter_write( e, "\n", 1 );
+ }
}
void
@@ -1123,6 +1140,8 @@ void syck_emit_item( SyckEmitter *e, st_data_t n )
}
}
break;
+
+ default: break;
}
lvl->ncount++;
@@ -1163,6 +1182,8 @@ void syck_emit_end( SyckEmitter *e )
case syck_lvl_imap:
syck_emitter_write( e, "}\n", 1 );
break;
+
+ default: break;
}
}