/** * librdf_stream_write: * @stream: the stream object * @iostr: the iostream to write to * * Write a stream of triples to an iostream in a debug format. * * This prints the remaining statements of the stream to the given * #raptor_iostream in a debug format. * * Note that after this method is called the stream will be empty so * that librdf_stream_end() will always be true and * librdf_stream_next() will always return NULL. The only useful * operation is to dispose of the stream with the * librdf_free_stream() destructor. * * This method is for debugging and the format of the output should * not be relied on. In particular, when contexts are used the * result may be 4 nodes. * * Return value: non-0 on failure **/ int librdf_stream_write(librdf_stream *stream, raptor_iostream *iostr) { LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(stream, librdf_stream, 1); LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(iostr, raptor_iostream, 1); while(!librdf_stream_end(stream)) { librdf_statement* statement; librdf_node* context_node; statement = librdf_stream_get_object(stream); if(!statement) break; raptor_iostream_counted_string_write(" ", 2, iostr); if(librdf_statement_write(statement, iostr)) return 1; context_node = librdf_stream_get_context2(stream); if(context_node) { raptor_iostream_counted_string_write(" with context ", 14, iostr); librdf_node_write(context_node, iostr); } raptor_iostream_counted_string_write(". \n", 3, iostr); librdf_stream_next(stream); } return 0; }
/** * librdf_statement_write: * @statement: the statement * @iostr: raptor iostream to write to * * Write the statement to an iostream * * This method is for debugging and the format of the output should * not be relied on. * * Return value: non-0 on failure **/ int librdf_statement_write(librdf_statement *statement, raptor_iostream *iostr) { LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(statement, librdf_statement, 1); if(!statement) return 1; if(librdf_node_write(statement->subject, iostr)) return 1; raptor_iostream_write_byte(' ', iostr); if(librdf_node_write(statement->predicate, iostr)) return 1; raptor_iostream_write_byte(' ', iostr); if(librdf_node_write(statement->object, iostr)) return 1; return 0; }
/* * Return the specified +node+ as an NTriples string. */ VALUE rleaf_librdf_node_to_string( librdf_node *node ) { raptor_iostream *stream = NULL; void *dumped_node = NULL; int ret; stream = raptor_new_iostream_to_string( node->world, &dumped_node, NULL, NULL ); if ( !stream ) { rb_sys_fail( "raptor_new_iostream_to_string" ); } ret = librdf_node_write( node, stream ); raptor_free_iostream( stream ); if ( ret != 0 ) rb_fatal( "librdf_node_write failed." ); return rb_str_new2( (char *)dumped_node ); }