summaryrefslogtreecommitdiff
path: root/ext/syck/emitter.c
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-17 17:22:49 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-17 17:22:49 +0000
commitf3d9f34537779e2ed3d29519c6a29346b74409d7 (patch)
tree4998dbfa7c8cab36cc089090e0c9e0e0bd28030f /ext/syck/emitter.c
parent17f4f5f507715b8b832305f71b2375ca9f830ff4 (diff)
* 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
Diffstat (limited to 'ext/syck/emitter.c')
-rw-r--r--ext/syck/emitter.c63
1 files changed, 32 insertions, 31 deletions
diff --git a/ext/syck/emitter.c b/ext/syck/emitter.c
index a4b78b6bb62..6a5e43c9ee1 100644
--- a/ext/syck/emitter.c
+++ b/ext/syck/emitter.c
@@ -339,27 +339,6 @@ syck_emitter_flush( SyckEmitter *e, long check_room )
}
/*
- * 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.
*/
if ( check_room > e->marker - e->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;