summaryrefslogtreecommitdiff
path: root/ext/syck/node.c
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-13 03:58:33 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-09-13 03:58:33 +0000
commitf1827a2fafaa50ba89f35c8c05beffd28b1dd6e6 (patch)
tree095d144b8790cb1d1a99fbe40e0e79e31f65fcac /ext/syck/node.c
parent2007d73102b29e7bf50d08f6690ae5e6ffa5ea9a (diff)
* lib/yaml.rb: reworking YAML::Stream to use the new
emitter. * lib/yaml/stream.rb: ditto. * lib/yaml/rubytypes.rb: added Object#yaml_new. * lib/yaml/tag.rb: the tag_subclasses? method now shows up in the class. allow taguri to be set using an accessor. continue support of Object#to_yaml_type. * ext/syck/rubyext.c: new emitter code. yaml_new and yaml_initialize get called, should they be present. consolidated all the diaspora of internal node types into the family below YAML::Syck::Node -- Map, Seq, Scalar -- all of whom are SyckNode structs pointing to Ruby data. moved Object#yaml_new into the node_import and made it the default behavior. the target_class is always called wih yaml_new, prepended a parameter, which is the klass. loaded nodes through GenericResolver show their style. new Resolver#tagurize converts type ids to taguris. * ext/syck/implicit.re: were 'y' and 'n' seriously omitted?? * ext/syck/emitter.c: renovated emitter, walks the tree in advance. consolidated redundant block_styles struct into the scalar_style struct. (this means loaded nodes can now be sent back to emitter and preserve at least its very basic formatting.) * ext/syck/gram.c: headless documents of any kind allowed. * ext/syck/node.c: new syck_replace_str methods and syck_empty_* methods for rewriting node contents, while keeping the ID and other setup info. added syck_seq_assign. * ext/syck/syck.h: reflect block_styles and new node functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/syck/node.c')
-rw-r--r--ext/syck/node.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/ext/syck/node.c b/ext/syck/node.c
index 500ede2a4c..72db016eda 100644
--- a/ext/syck/node.c
+++ b/ext/syck/node.c
@@ -33,9 +33,15 @@ syck_free_node( SyckNode *n )
{
syck_free_members( n );
if ( n->type_id != NULL )
+ {
S_FREE( n->type_id );
+ n->type_id = NULL;
+ }
if ( n->anchor != NULL )
+ {
S_FREE( n->anchor );
+ n->anchor = NULL;
+ }
S_FREE( n );
}
@@ -46,6 +52,7 @@ syck_alloc_map()
struct SyckMap *m;
m = S_ALLOC( struct SyckMap );
+ m->style = map_none;
m->idx = 0;
m->capa = ALLOC_CT;
m->keys = S_ALLOC_N( SYMID, m->capa );
@@ -64,6 +71,7 @@ syck_alloc_seq()
struct SyckSeq *s;
s = S_ALLOC( struct SyckSeq );
+ s->style = seq_none;
s->idx = 0;
s->capa = ALLOC_CT;
s->items = S_ALLOC_N( SYMID, s->capa );
@@ -113,6 +121,28 @@ syck_new_str2( char *str, long len, enum scalar_style style )
}
void
+syck_replace_str( SyckNode *n, char *str, enum scalar_style style )
+{
+ return syck_replace_str2( n, str, strlen( str ), style );
+}
+
+void
+syck_replace_str2( SyckNode *n, char *str, long len, enum scalar_style style )
+{
+ if ( n->data.str != NULL )
+ {
+ S_FREE( n->data.str->ptr );
+ n->data.str->ptr = NULL;
+ n->data.str->len = 0;
+ }
+ n->data.str->ptr = S_ALLOC_N( char, len + 1 );
+ n->data.str->len = len;
+ n->data.str->style = style;
+ memcpy( n->data.str->ptr, str, len );
+ n->data.str->ptr[len] = '\0';
+}
+
+void
syck_str_blow_away_commas( SyckNode *n )
{
char *go, *end;
@@ -149,6 +179,22 @@ syck_new_map( SYMID key, SYMID value )
}
void
+syck_map_empty( SyckNode *n )
+{
+ struct SyckMap *m;
+ ASSERT( n != NULL );
+ ASSERT( n->data.list != NULL );
+
+ S_FREE( n->data.pairs->keys );
+ S_FREE( n->data.pairs->values );
+ m = n->data.pairs;
+ m->idx = 0;
+ m->capa = ALLOC_CT;
+ m->keys = S_ALLOC_N( SYMID, m->capa );
+ m->values = S_ALLOC_N( SYMID, m->capa );
+}
+
+void
syck_map_add( SyckNode *map, SYMID key, SYMID value )
{
struct SyckMap *m;
@@ -258,6 +304,20 @@ syck_new_seq( SYMID value )
}
void
+syck_seq_empty( SyckNode *n )
+{
+ struct SyckSeq *s;
+ ASSERT( n != NULL );
+ ASSERT( n->data.list != NULL );
+
+ S_FREE( n->data.list->items );
+ s = n->data.list;
+ s->idx = 0;
+ s->capa = ALLOC_CT;
+ s->items = S_ALLOC_N( SYMID, s->capa );
+}
+
+void
syck_seq_add( SyckNode *arr, SYMID value )
{
struct SyckSeq *s;
@@ -285,6 +345,17 @@ syck_seq_count( SyckNode *seq )
return seq->data.list->idx;
}
+void
+syck_seq_assign( SyckNode *seq, long idx, SYMID id )
+{
+ struct SyckSeq *s;
+
+ ASSERT( map != NULL );
+ s = seq->data.list;
+ ASSERT( m != NULL );
+ s->items[idx] = id;
+}
+
SYMID
syck_seq_read( SyckNode *seq, long idx )
{