From f3d9f34537779e2ed3d29519c6a29346b74409d7 Mon Sep 17 00:00:00 2001 From: why Date: Sat, 17 Sep 2005 17:22:49 +0000 Subject: * lib/yaml/rubytypes.rb: remove comments that are bungling up the rdoc and ri output. output symbols as plain scalars. * ext/syck/rubyext.c (syck_emitter_reset): emit headless documents always. * ext/syck/emitter.c (syck_scan_scalar): quote scalars with any kind of surrounding line space, tabs or spaces alike. * ext/syck/token.c: accept tabs as whitespace, not for indentation, but strip from plain scalars. * test/yaml/test_yaml.rb: remove outdated tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9207 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/syck/emitter.c | 63 +++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'ext/syck/emitter.c') diff --git a/ext/syck/emitter.c b/ext/syck/emitter.c index a4b78b6bb6..6a5e43c9ee 100644 --- a/ext/syck/emitter.c +++ b/ext/syck/emitter.c @@ -338,27 +338,6 @@ syck_emitter_flush( SyckEmitter *e, long check_room ) check_room = e->bufsize; } - /* - * Determine headers. - */ - if ( ( e->stage == doc_open && ( e->headless == 0 || e->use_header == 1 ) ) || - e->stage == doc_need_header ) - { - if ( e->use_version == 1 ) - { - char *header = S_ALLOC_N( char, 64 ); - S_MEMZERO( header, char, 64 ); - sprintf( header, "--- %%YAML:%d.%d ", SYCK_YAML_MAJOR, SYCK_YAML_MINOR ); - (e->output_handler)( e, header, strlen( header ) ); - S_FREE( header ); - } - else - { - (e->output_handler)( e, "--- ", 4 ); - } - e->stage = doc_processing; - } - /* * Commit buffer. */ @@ -383,6 +362,26 @@ syck_emit( SyckEmitter *e, st_data_t n ) int indent = 0, x = 0; SyckLevel *lvl = syck_emitter_current_level( e ); + /* + * Determine headers. + */ + if ( e->stage == doc_open && ( e->headless == 0 || e->use_header == 1 ) ) + { + if ( e->use_version == 1 ) + { + char *header = S_ALLOC_N( char, 64 ); + S_MEMZERO( header, char, 64 ); + sprintf( header, "--- %%YAML:%d.%d ", SYCK_YAML_MAJOR, SYCK_YAML_MINOR ); + syck_emitter_write( e, header, strlen( header ) ); + S_FREE( header ); + } + else + { + syck_emitter_write( e, "--- ", 4 ); + } + e->stage = doc_processing; + } + /* Add new level */ if ( lvl->spaces >= 0 ) { indent = lvl->spaces + e->indent; @@ -429,6 +428,7 @@ end_emit: syck_emitter_pop_level( e ); if ( e->lvl_idx == 1 ) { syck_emitter_write( e, "\n", 1 ); + e->headless = 0; e->stage = doc_open; } } @@ -493,6 +493,7 @@ void syck_emit_indent( SyckEmitter *e ) { int i; SyckLevel *lvl = syck_emitter_current_level( e ); + if ( e->bufpos == 0 && ( e->marker - e->buffer ) == 0 ) return; if ( lvl->spaces >= 0 ) { char *spcs = S_ALLOC_N( char, lvl->spaces + 2 ); @@ -511,8 +512,8 @@ void syck_emit_indent( SyckEmitter *e ) #define SCAN_INDENTED 2 /* Larger than the requested width? */ #define SCAN_WIDE 4 -/* Opens with whitespace? */ -#define SCAN_WHITESTART 8 +/* Opens or closes with whitespace? */ +#define SCAN_WHITEEDGE 8 /* Contains a newline */ #define SCAN_NEWLINE 16 /* Contains a single quote */ @@ -562,12 +563,18 @@ syck_scan_scalar( int req_width, char *cursor, long len ) flags |= SCAN_INDIC_S; } - /* ending newlines */ + /* whitespace edges */ if ( cursor[len-1] != '\n' ) { flags |= SCAN_NONL_E; } else if ( len > 1 && cursor[len-2] == '\n' ) { flags |= SCAN_MANYNL_E; } + if ( + ( len > 0 && ( cursor[0] == ' ' || cursor[0] == '\t' ) ) || + ( len > 1 && ( cursor[len-1] == ' ' || cursor[len-1] == '\t' ) ) + ) { + flags |= SCAN_WHITEEDGE; + } /* opening doc sep */ if ( len >= 3 && strncmp( cursor, "---", 3 ) == 0 ) @@ -620,12 +627,6 @@ syck_scan_scalar( int req_width, char *cursor, long len ) flags |= SCAN_FLOWMAP; flags |= SCAN_FLOWSEQ; } - - if ( i == 0 && - ( cursor[i] == ' ' || cursor[i] == '\t' ) - ) { - flags |= SCAN_WHITESTART; - } } /* printf( "---STR---\n%s\nFLAGS: %d\n", cursor, flags ); */ @@ -682,7 +683,7 @@ void syck_emit_scalar( SyckEmitter *e, char *tag, enum scalar_style force_style, /* Determine block style */ if ( scan & SCAN_NONPRINT ) { force_style = scalar_2quote; - } else if ( scan & SCAN_WHITESTART ) { + } else if ( scan & SCAN_WHITEEDGE ) { force_style = scalar_2quote; } else if ( force_style != scalar_fold && ( scan & SCAN_INDENTED ) ) { force_style = scalar_literal; -- cgit v1.2.3