cannam@110
|
1 /*
|
cannam@110
|
2 Copyright 2011-2012 David Robillard <http://drobilla.net>
|
cannam@110
|
3
|
cannam@110
|
4 Permission to use, copy, modify, and/or distribute this software for any
|
cannam@110
|
5 purpose with or without fee is hereby granted, provided that the above
|
cannam@110
|
6 copyright notice and this permission notice appear in all copies.
|
cannam@110
|
7
|
cannam@110
|
8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
cannam@110
|
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
cannam@110
|
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
cannam@110
|
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
cannam@110
|
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
cannam@110
|
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
cannam@110
|
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
cannam@110
|
15 */
|
cannam@110
|
16
|
cannam@110
|
17 /**
|
cannam@110
|
18 @file serd.h API for Serd, a lightweight RDF syntax library.
|
cannam@110
|
19 */
|
cannam@110
|
20
|
cannam@110
|
21 #ifndef SERD_SERD_H
|
cannam@110
|
22 #define SERD_SERD_H
|
cannam@110
|
23
|
cannam@110
|
24 #include <stdarg.h>
|
cannam@110
|
25 #include <stddef.h>
|
cannam@110
|
26 #include <stdint.h>
|
cannam@110
|
27 #include <stdio.h>
|
cannam@110
|
28
|
cannam@110
|
29 #ifdef SERD_SHARED
|
cannam@110
|
30 # ifdef _WIN32
|
cannam@110
|
31 # define SERD_LIB_IMPORT __declspec(dllimport)
|
cannam@110
|
32 # define SERD_LIB_EXPORT __declspec(dllexport)
|
cannam@110
|
33 # else
|
cannam@110
|
34 # define SERD_LIB_IMPORT __attribute__((visibility("default")))
|
cannam@110
|
35 # define SERD_LIB_EXPORT __attribute__((visibility("default")))
|
cannam@110
|
36 # endif
|
cannam@110
|
37 # ifdef SERD_INTERNAL
|
cannam@110
|
38 # define SERD_API SERD_LIB_EXPORT
|
cannam@110
|
39 # else
|
cannam@110
|
40 # define SERD_API SERD_LIB_IMPORT
|
cannam@110
|
41 # endif
|
cannam@110
|
42 #else
|
cannam@110
|
43 # define SERD_API
|
cannam@110
|
44 #endif
|
cannam@110
|
45
|
cannam@110
|
46 #ifdef __cplusplus
|
cannam@110
|
47 extern "C" {
|
cannam@110
|
48 #else
|
cannam@110
|
49 # include <stdbool.h>
|
cannam@110
|
50 #endif
|
cannam@110
|
51
|
cannam@110
|
52 /**
|
cannam@110
|
53 @defgroup serd Serd
|
cannam@110
|
54 A lightweight RDF syntax library.
|
cannam@110
|
55 @{
|
cannam@110
|
56 */
|
cannam@110
|
57
|
cannam@110
|
58 /**
|
cannam@110
|
59 Environment.
|
cannam@110
|
60
|
cannam@110
|
61 Represents the state required to resolve a CURIE or relative URI, e.g. the
|
cannam@110
|
62 base URI and set of namespace prefixes at a particular point.
|
cannam@110
|
63 */
|
cannam@110
|
64 typedef struct SerdEnvImpl SerdEnv;
|
cannam@110
|
65
|
cannam@110
|
66 /**
|
cannam@110
|
67 RDF reader.
|
cannam@110
|
68
|
cannam@110
|
69 Parses RDF by calling user-provided sink functions as input is consumed
|
cannam@110
|
70 (much like an XML SAX parser).
|
cannam@110
|
71 */
|
cannam@110
|
72 typedef struct SerdReaderImpl SerdReader;
|
cannam@110
|
73
|
cannam@110
|
74 /**
|
cannam@110
|
75 RDF writer.
|
cannam@110
|
76
|
cannam@110
|
77 Provides a number of functions to allow writing RDF syntax out to some
|
cannam@110
|
78 stream. These functions are deliberately compatible with the sink functions
|
cannam@110
|
79 used by SerdReader, so a reader can be directly connected to a writer to
|
cannam@110
|
80 re-serialise a document with minimal overhead.
|
cannam@110
|
81 */
|
cannam@110
|
82 typedef struct SerdWriterImpl SerdWriter;
|
cannam@110
|
83
|
cannam@110
|
84 /**
|
cannam@110
|
85 Return status code.
|
cannam@110
|
86 */
|
cannam@110
|
87 typedef enum {
|
cannam@110
|
88 SERD_SUCCESS, /**< No error */
|
cannam@110
|
89 SERD_FAILURE, /**< Non-fatal failure */
|
cannam@110
|
90 SERD_ERR_UNKNOWN, /**< Unknown error */
|
cannam@110
|
91 SERD_ERR_BAD_SYNTAX, /**< Invalid syntax */
|
cannam@110
|
92 SERD_ERR_BAD_ARG, /**< Invalid argument */
|
cannam@110
|
93 SERD_ERR_NOT_FOUND, /**< Not found */
|
cannam@110
|
94 SERD_ERR_ID_CLASH, /**< Encountered clashing blank node IDs */
|
cannam@110
|
95 SERD_ERR_BAD_CURIE, /**< Invalid CURIE (e.g. prefix does not exist) */
|
cannam@110
|
96 SERD_ERR_INTERNAL /**< Unexpected internal error (should not happen) */
|
cannam@110
|
97 } SerdStatus;
|
cannam@110
|
98
|
cannam@110
|
99 /**
|
cannam@110
|
100 RDF syntax type.
|
cannam@110
|
101 */
|
cannam@110
|
102 typedef enum {
|
cannam@110
|
103 /**
|
cannam@110
|
104 Turtle - Terse RDF Triple Language (UTF-8).
|
cannam@110
|
105 @see <a href="http://www.w3.org/TeamSubmission/turtle/">Turtle</a>
|
cannam@110
|
106 */
|
cannam@110
|
107 SERD_TURTLE = 1,
|
cannam@110
|
108
|
cannam@110
|
109 /**
|
cannam@110
|
110 NTriples - Line-based RDF triples (ASCII).
|
cannam@110
|
111 @see <a href="http://www.w3.org/TR/rdf-testcases#ntriples">NTriples</a>
|
cannam@110
|
112 */
|
cannam@110
|
113 SERD_NTRIPLES = 2
|
cannam@110
|
114 } SerdSyntax;
|
cannam@110
|
115
|
cannam@110
|
116 /**
|
cannam@110
|
117 Flags indication inline abbreviation information for a statement.
|
cannam@110
|
118 */
|
cannam@110
|
119 typedef enum {
|
cannam@110
|
120 SERD_EMPTY_S = 1 << 1, /**< Empty blank node subject */
|
cannam@110
|
121 SERD_EMPTY_O = 1 << 2, /**< Empty blank node object */
|
cannam@110
|
122 SERD_ANON_S_BEGIN = 1 << 3, /**< Start of anonymous subject */
|
cannam@110
|
123 SERD_ANON_O_BEGIN = 1 << 4, /**< Start of anonymous object */
|
cannam@110
|
124 SERD_ANON_CONT = 1 << 5, /**< Continuation of anonymous node */
|
cannam@110
|
125 SERD_LIST_S_BEGIN = 1 << 6, /**< Start of list subject */
|
cannam@110
|
126 SERD_LIST_O_BEGIN = 1 << 7, /**< Start of list object */
|
cannam@110
|
127 SERD_LIST_CONT = 1 << 8 /**< Continuation of list */
|
cannam@110
|
128 } SerdStatementFlag;
|
cannam@110
|
129
|
cannam@110
|
130 /**
|
cannam@110
|
131 Bitwise OR of SerdNodeFlag values.
|
cannam@110
|
132 */
|
cannam@110
|
133 typedef uint32_t SerdStatementFlags;
|
cannam@110
|
134
|
cannam@110
|
135 /**
|
cannam@110
|
136 Type of a syntactic RDF node.
|
cannam@110
|
137
|
cannam@110
|
138 This is more precise than the type of an abstract RDF node. An abstract
|
cannam@110
|
139 node is either a resource, literal, or blank. In syntax there are two ways
|
cannam@110
|
140 to refer to a resource (by URI or CURIE) and two ways to refer to a blank
|
cannam@110
|
141 (by ID or anonymously). Anonymous (inline) blank nodes are expressed using
|
cannam@110
|
142 SerdStatementFlags rather than this type.
|
cannam@110
|
143 */
|
cannam@110
|
144 typedef enum {
|
cannam@110
|
145 /**
|
cannam@110
|
146 The type of a nonexistent node.
|
cannam@110
|
147
|
cannam@110
|
148 This type is useful as a sentinel, but is never emitted by the reader.
|
cannam@110
|
149 */
|
cannam@110
|
150 SERD_NOTHING = 0,
|
cannam@110
|
151
|
cannam@110
|
152 /**
|
cannam@110
|
153 Literal value.
|
cannam@110
|
154
|
cannam@110
|
155 A literal optionally has either a language, or a datatype (not both).
|
cannam@110
|
156 */
|
cannam@110
|
157 SERD_LITERAL = 1,
|
cannam@110
|
158
|
cannam@110
|
159 /**
|
cannam@110
|
160 URI (absolute or relative).
|
cannam@110
|
161
|
cannam@110
|
162 Value is an unquoted URI string, which is either a relative reference
|
cannam@110
|
163 with respect to the current base URI (e.g. "foo/bar"), or an absolute
|
cannam@110
|
164 URI (e.g. "http://example.org/foo").
|
cannam@110
|
165 @see <a href="http://tools.ietf.org/html/rfc3986">RFC3986</a>.
|
cannam@110
|
166 */
|
cannam@110
|
167 SERD_URI = 2,
|
cannam@110
|
168
|
cannam@110
|
169 /**
|
cannam@110
|
170 CURIE, a shortened URI.
|
cannam@110
|
171
|
cannam@110
|
172 Value is an unquoted CURIE string relative to the current environment,
|
cannam@110
|
173 e.g. "rdf:type".
|
cannam@110
|
174 @see <a href="http://www.w3.org/TR/curie">CURIE Syntax 1.0</a>
|
cannam@110
|
175 */
|
cannam@110
|
176 SERD_CURIE = 3,
|
cannam@110
|
177
|
cannam@110
|
178 /**
|
cannam@110
|
179 A blank node.
|
cannam@110
|
180
|
cannam@110
|
181 Value is a blank node ID, e.g. "id3", which is meaningful only within
|
cannam@110
|
182 this serialisation.
|
cannam@110
|
183 @see <a href="http://www.w3.org/TeamSubmission/turtle#nodeID">Turtle
|
cannam@110
|
184 <tt>nodeID</tt></a>
|
cannam@110
|
185 */
|
cannam@110
|
186 SERD_BLANK = 4,
|
cannam@110
|
187
|
cannam@110
|
188 } SerdType;
|
cannam@110
|
189
|
cannam@110
|
190 /**
|
cannam@110
|
191 Flags indicating certain string properties relevant to serialisation.
|
cannam@110
|
192 */
|
cannam@110
|
193 typedef enum {
|
cannam@110
|
194 SERD_HAS_NEWLINE = 1, /**< Contains line breaks ('\\n' or '\\r') */
|
cannam@110
|
195 SERD_HAS_QUOTE = 1 << 1 /**< Contains quotes ('"') */
|
cannam@110
|
196 } SerdNodeFlag;
|
cannam@110
|
197
|
cannam@110
|
198 /**
|
cannam@110
|
199 Bitwise OR of SerdNodeFlag values.
|
cannam@110
|
200 */
|
cannam@110
|
201 typedef uint32_t SerdNodeFlags;
|
cannam@110
|
202
|
cannam@110
|
203 /**
|
cannam@110
|
204 A syntactic RDF node.
|
cannam@110
|
205 */
|
cannam@110
|
206 typedef struct {
|
cannam@110
|
207 const uint8_t* buf; /**< Value string */
|
cannam@110
|
208 size_t n_bytes; /**< Size in bytes (not including null) */
|
cannam@110
|
209 size_t n_chars; /**< Length in characters (not including null)*/
|
cannam@110
|
210 SerdNodeFlags flags; /**< Node flags (e.g. string properties) */
|
cannam@110
|
211 SerdType type; /**< Node type */
|
cannam@110
|
212 } SerdNode;
|
cannam@110
|
213
|
cannam@110
|
214 /**
|
cannam@110
|
215 An unterminated string fragment.
|
cannam@110
|
216 */
|
cannam@110
|
217 typedef struct {
|
cannam@110
|
218 const uint8_t* buf; /**< Start of chunk */
|
cannam@110
|
219 size_t len; /**< Length of chunk in bytes */
|
cannam@110
|
220 } SerdChunk;
|
cannam@110
|
221
|
cannam@110
|
222 /**
|
cannam@110
|
223 An error description.
|
cannam@110
|
224 */
|
cannam@110
|
225 typedef struct {
|
cannam@110
|
226 SerdStatus status; /**< Error code */
|
cannam@110
|
227 const uint8_t* filename; /**< File where error was encountered, or NULL */
|
cannam@110
|
228 unsigned line; /**< Line where error was encountered, or 0 */
|
cannam@110
|
229 unsigned col; /**< Column where error was encountered */
|
cannam@110
|
230 const char* fmt; /**< Message format string (printf style) */
|
cannam@110
|
231 va_list* args; /**< Arguments for fmt */
|
cannam@110
|
232 } SerdError;
|
cannam@110
|
233
|
cannam@110
|
234 /**
|
cannam@110
|
235 A parsed URI.
|
cannam@110
|
236
|
cannam@110
|
237 This struct directly refers to chunks in other strings, it does not own any
|
cannam@110
|
238 memory itself. Thus, URIs can be parsed and/or resolved against a base URI
|
cannam@110
|
239 in-place without allocating memory.
|
cannam@110
|
240 */
|
cannam@110
|
241 typedef struct {
|
cannam@110
|
242 SerdChunk scheme; /**< Scheme */
|
cannam@110
|
243 SerdChunk authority; /**< Authority */
|
cannam@110
|
244 SerdChunk path_base; /**< Path prefix if relative */
|
cannam@110
|
245 SerdChunk path; /**< Path suffix */
|
cannam@110
|
246 SerdChunk query; /**< Query */
|
cannam@110
|
247 SerdChunk fragment; /**< Fragment */
|
cannam@110
|
248 } SerdURI;
|
cannam@110
|
249
|
cannam@110
|
250 /**
|
cannam@110
|
251 Syntax style options.
|
cannam@110
|
252
|
cannam@110
|
253 The style of the writer output can be controlled by ORing together
|
cannam@110
|
254 values from this enumeration. Note that some options are only supported
|
cannam@110
|
255 for some syntaxes (e.g. NTriples does not support abbreviation and is
|
cannam@110
|
256 always ASCII).
|
cannam@110
|
257 */
|
cannam@110
|
258 typedef enum {
|
cannam@110
|
259 SERD_STYLE_ABBREVIATED = 1, /**< Abbreviate triples when possible. */
|
cannam@110
|
260 SERD_STYLE_ASCII = 1 << 1, /**< Escape all non-ASCII characters. */
|
cannam@110
|
261 SERD_STYLE_RESOLVED = 1 << 2, /**< Resolve URIs against base URI. */
|
cannam@110
|
262 SERD_STYLE_CURIED = 1 << 3, /**< Shorten URIs into CURIEs. */
|
cannam@110
|
263 SERD_STYLE_BULK = 1 << 4 /**< Write output in pages. */
|
cannam@110
|
264 } SerdStyle;
|
cannam@110
|
265
|
cannam@110
|
266 /**
|
cannam@110
|
267 @name String Utilities
|
cannam@110
|
268 @{
|
cannam@110
|
269 */
|
cannam@110
|
270
|
cannam@110
|
271 /**
|
cannam@110
|
272 Return a string describing a status code.
|
cannam@110
|
273 */
|
cannam@110
|
274 SERD_API
|
cannam@110
|
275 const uint8_t*
|
cannam@110
|
276 serd_strerror(SerdStatus status);
|
cannam@110
|
277
|
cannam@110
|
278 /**
|
cannam@110
|
279 Measure a UTF-8 string.
|
cannam@110
|
280 @return Length of @c str in characters (except NULL).
|
cannam@110
|
281 @param str A null-terminated UTF-8 string.
|
cannam@110
|
282 @param n_bytes (Output) Set to the size of @c str in bytes (except NULL).
|
cannam@110
|
283 @param flags (Output) Set to the applicable flags.
|
cannam@110
|
284 */
|
cannam@110
|
285 SERD_API
|
cannam@110
|
286 size_t
|
cannam@110
|
287 serd_strlen(const uint8_t* str, size_t* n_bytes, SerdNodeFlags* flags);
|
cannam@110
|
288
|
cannam@110
|
289 /**
|
cannam@110
|
290 Parse a string to a double.
|
cannam@110
|
291
|
cannam@110
|
292 The API of this function is identical to the standard C strtod function,
|
cannam@110
|
293 except this function is locale-independent and always matches the lexical
|
cannam@110
|
294 format used in the Turtle grammar (the decimal point is always ".").
|
cannam@110
|
295 */
|
cannam@110
|
296 SERD_API
|
cannam@110
|
297 double
|
cannam@110
|
298 serd_strtod(const char* str, char** endptr);
|
cannam@110
|
299
|
cannam@110
|
300 /**
|
cannam@110
|
301 Decode a base64 string.
|
cannam@110
|
302 This function can be used to deserialise a blob node created with
|
cannam@110
|
303 serd_node_new_blob().
|
cannam@110
|
304
|
cannam@110
|
305 @param str Base64 string to decode.
|
cannam@110
|
306 @param len The length of @c str.
|
cannam@110
|
307 @param size Set to the size of the returned blob in bytes.
|
cannam@110
|
308 @return A newly allocated blob which must be freed with free().
|
cannam@110
|
309 */
|
cannam@110
|
310 SERD_API
|
cannam@110
|
311 void*
|
cannam@110
|
312 serd_base64_decode(const uint8_t* str, size_t len, size_t* size);
|
cannam@110
|
313
|
cannam@110
|
314 /**
|
cannam@110
|
315 @}
|
cannam@110
|
316 @name URI
|
cannam@110
|
317 @{
|
cannam@110
|
318 */
|
cannam@110
|
319
|
cannam@110
|
320 static const SerdURI SERD_URI_NULL = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
|
cannam@110
|
321
|
cannam@110
|
322 /**
|
cannam@110
|
323 Return the local path for @c uri, or NULL if @c uri is not a file URI.
|
cannam@110
|
324 Note this (inappropriately named) function only removes the file scheme if
|
cannam@110
|
325 necessary, and returns @c uri unmodified if it is an absolute path. Percent
|
cannam@110
|
326 encoding and other issues are not handled, to properly convert a file URI to
|
cannam@110
|
327 a path, use serd_file_uri_parse().
|
cannam@110
|
328 */
|
cannam@110
|
329 SERD_API
|
cannam@110
|
330 const uint8_t*
|
cannam@110
|
331 serd_uri_to_path(const uint8_t* uri);
|
cannam@110
|
332
|
cannam@110
|
333 /**
|
cannam@110
|
334 Get the unescaped path and hostname from a file URI.
|
cannam@110
|
335 @param uri A file URI.
|
cannam@110
|
336 @param hostname If non-NULL, set to the hostname, if present.
|
cannam@110
|
337 @return The path component of the URI.
|
cannam@110
|
338
|
cannam@110
|
339 Both the returned path and @c hostname (if applicable) are owned by the
|
cannam@110
|
340 caller and must be freed with free().
|
cannam@110
|
341 */
|
cannam@110
|
342 SERD_API
|
cannam@110
|
343 uint8_t*
|
cannam@110
|
344 serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname);
|
cannam@110
|
345
|
cannam@110
|
346 /**
|
cannam@110
|
347 Return true iff @c utf8 starts with a valid URI scheme.
|
cannam@110
|
348 */
|
cannam@110
|
349 SERD_API
|
cannam@110
|
350 bool
|
cannam@110
|
351 serd_uri_string_has_scheme(const uint8_t* utf8);
|
cannam@110
|
352
|
cannam@110
|
353 /**
|
cannam@110
|
354 Parse @c utf8, writing result to @c out.
|
cannam@110
|
355 */
|
cannam@110
|
356 SERD_API
|
cannam@110
|
357 SerdStatus
|
cannam@110
|
358 serd_uri_parse(const uint8_t* utf8, SerdURI* out);
|
cannam@110
|
359
|
cannam@110
|
360 /**
|
cannam@110
|
361 Set @c out to @c uri resolved against @c base.
|
cannam@110
|
362 */
|
cannam@110
|
363 SERD_API
|
cannam@110
|
364 void
|
cannam@110
|
365 serd_uri_resolve(const SerdURI* uri, const SerdURI* base, SerdURI* out);
|
cannam@110
|
366
|
cannam@110
|
367 /**
|
cannam@110
|
368 Sink function for raw string output.
|
cannam@110
|
369 */
|
cannam@110
|
370 typedef size_t (*SerdSink)(const void* buf, size_t len, void* stream);
|
cannam@110
|
371
|
cannam@110
|
372 /**
|
cannam@110
|
373 Serialise @c uri with a series of calls to @c sink.
|
cannam@110
|
374 */
|
cannam@110
|
375 SERD_API
|
cannam@110
|
376 size_t
|
cannam@110
|
377 serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream);
|
cannam@110
|
378
|
cannam@110
|
379 /**
|
cannam@110
|
380 Serialise @c uri relative to @c base with a series of calls to @c sink.
|
cannam@110
|
381
|
cannam@110
|
382 The @c uri is written as a relative URI iff if it a child of @c base and @c
|
cannam@110
|
383 root. The optional @c root parameter must be a prefix of @c base and can be
|
cannam@110
|
384 used keep up-references ("../") within a certain namespace.
|
cannam@110
|
385 */
|
cannam@110
|
386 SERD_API
|
cannam@110
|
387 size_t
|
cannam@110
|
388 serd_uri_serialise_relative(const SerdURI* uri,
|
cannam@110
|
389 const SerdURI* base,
|
cannam@110
|
390 const SerdURI* root,
|
cannam@110
|
391 SerdSink sink,
|
cannam@110
|
392 void* stream);
|
cannam@110
|
393
|
cannam@110
|
394 /**
|
cannam@110
|
395 @}
|
cannam@110
|
396 @name Node
|
cannam@110
|
397 @{
|
cannam@110
|
398 */
|
cannam@110
|
399
|
cannam@110
|
400 static const SerdNode SERD_NODE_NULL = { 0, 0, 0, 0, SERD_NOTHING };
|
cannam@110
|
401
|
cannam@110
|
402 /**
|
cannam@110
|
403 Make a (shallow) node from @c str.
|
cannam@110
|
404
|
cannam@110
|
405 This measures, but does not copy, @c str. No memory is allocated.
|
cannam@110
|
406 */
|
cannam@110
|
407 SERD_API
|
cannam@110
|
408 SerdNode
|
cannam@110
|
409 serd_node_from_string(SerdType type, const uint8_t* str);
|
cannam@110
|
410
|
cannam@110
|
411 /**
|
cannam@110
|
412 Make a deep copy of @c node.
|
cannam@110
|
413
|
cannam@110
|
414 @return a node that the caller must free with @ref serd_node_free.
|
cannam@110
|
415 */
|
cannam@110
|
416 SERD_API
|
cannam@110
|
417 SerdNode
|
cannam@110
|
418 serd_node_copy(const SerdNode* node);
|
cannam@110
|
419
|
cannam@110
|
420 /**
|
cannam@110
|
421 Return true iff @c a is equal to @c b.
|
cannam@110
|
422 */
|
cannam@110
|
423 SERD_API
|
cannam@110
|
424 bool
|
cannam@110
|
425 serd_node_equals(const SerdNode* a, const SerdNode* b);
|
cannam@110
|
426
|
cannam@110
|
427 /**
|
cannam@110
|
428 Simple wrapper for serd_node_new_uri to resolve a URI node.
|
cannam@110
|
429 */
|
cannam@110
|
430 SERD_API
|
cannam@110
|
431 SerdNode
|
cannam@110
|
432 serd_node_new_uri_from_node(const SerdNode* uri_node,
|
cannam@110
|
433 const SerdURI* base,
|
cannam@110
|
434 SerdURI* out);
|
cannam@110
|
435
|
cannam@110
|
436 /**
|
cannam@110
|
437 Simple wrapper for serd_node_new_uri to resolve a URI string.
|
cannam@110
|
438 */
|
cannam@110
|
439 SERD_API
|
cannam@110
|
440 SerdNode
|
cannam@110
|
441 serd_node_new_uri_from_string(const uint8_t* str,
|
cannam@110
|
442 const SerdURI* base,
|
cannam@110
|
443 SerdURI* out);
|
cannam@110
|
444
|
cannam@110
|
445 /**
|
cannam@110
|
446 Create a new file URI node from a file system path and optional hostname.
|
cannam@110
|
447
|
cannam@110
|
448 Backslashes in Windows paths will be converted and '%' will always be
|
cannam@110
|
449 percent encoded. If @c escape is true, all other invalid characters will be
|
cannam@110
|
450 percent encoded as well.
|
cannam@110
|
451
|
cannam@110
|
452 If @c path is relative, @c hostname is ignored.
|
cannam@110
|
453 If @c out is not NULL, it will be set to the parsed URI.
|
cannam@110
|
454 */
|
cannam@110
|
455 SERD_API
|
cannam@110
|
456 SerdNode
|
cannam@110
|
457 serd_node_new_file_uri(const uint8_t* path,
|
cannam@110
|
458 const uint8_t* hostname,
|
cannam@110
|
459 SerdURI* out,
|
cannam@110
|
460 bool escape);
|
cannam@110
|
461
|
cannam@110
|
462 /**
|
cannam@110
|
463 Create a new node by serialising @c uri into a new string.
|
cannam@110
|
464
|
cannam@110
|
465 @param uri The URI to parse and serialise.
|
cannam@110
|
466
|
cannam@110
|
467 @param base Base URI to resolve @c uri against (or NULL for no resolution).
|
cannam@110
|
468
|
cannam@110
|
469 @param out Set to the parsing of the new URI (i.e. points only to
|
cannam@110
|
470 memory owned by the new returned node).
|
cannam@110
|
471 */
|
cannam@110
|
472 SERD_API
|
cannam@110
|
473 SerdNode
|
cannam@110
|
474 serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out);
|
cannam@110
|
475
|
cannam@110
|
476 /**
|
cannam@110
|
477 Create a new node by serialising @c d into an xsd:decimal string.
|
cannam@110
|
478
|
cannam@110
|
479 The resulting node will always contain a `.', start with a digit, and end
|
cannam@110
|
480 with a digit (i.e. will have a leading and/or trailing `0' if necessary).
|
cannam@110
|
481 It will never be in scientific notation. A maximum of @c frac_digits digits
|
cannam@110
|
482 will be written after the decimal point, but trailing zeros will
|
cannam@110
|
483 automatically be omitted (except one if @c d is a round integer).
|
cannam@110
|
484
|
cannam@110
|
485 Note that about 16 and 8 fractional digits are required to precisely
|
cannam@110
|
486 represent a double and float, respectively.
|
cannam@110
|
487
|
cannam@110
|
488 @param d The value for the new node.
|
cannam@110
|
489 @param frac_digits The maximum number of digits after the decimal place.
|
cannam@110
|
490 */
|
cannam@110
|
491 SERD_API
|
cannam@110
|
492 SerdNode
|
cannam@110
|
493 serd_node_new_decimal(double d, unsigned frac_digits);
|
cannam@110
|
494
|
cannam@110
|
495 /**
|
cannam@110
|
496 Create a new node by serialising @c i into an xsd:integer string.
|
cannam@110
|
497 */
|
cannam@110
|
498 SERD_API
|
cannam@110
|
499 SerdNode
|
cannam@110
|
500 serd_node_new_integer(int64_t i);
|
cannam@110
|
501
|
cannam@110
|
502 /**
|
cannam@110
|
503 Create a node by serialising @c buf into an xsd:base64Binary string.
|
cannam@110
|
504 This function can be used to make a serialisable node out of arbitrary
|
cannam@110
|
505 binary data, which can be decoded using serd_base64_decode().
|
cannam@110
|
506
|
cannam@110
|
507 @param buf Raw binary input data.
|
cannam@110
|
508 @param size Size of @c buf.
|
cannam@110
|
509 @param wrap_lines Wrap lines at 76 characters to conform to RFC 2045.
|
cannam@110
|
510 */
|
cannam@110
|
511 SERD_API
|
cannam@110
|
512 SerdNode
|
cannam@110
|
513 serd_node_new_blob(const void* buf, size_t size, bool wrap_lines);
|
cannam@110
|
514
|
cannam@110
|
515 /**
|
cannam@110
|
516 Free any data owned by @c node.
|
cannam@110
|
517
|
cannam@110
|
518 Note that if @c node is itself dynamically allocated (which is not the case
|
cannam@110
|
519 for nodes created internally by serd), it will not be freed.
|
cannam@110
|
520 */
|
cannam@110
|
521 SERD_API
|
cannam@110
|
522 void
|
cannam@110
|
523 serd_node_free(SerdNode* node);
|
cannam@110
|
524
|
cannam@110
|
525 /**
|
cannam@110
|
526 @}
|
cannam@110
|
527 @name Event Handlers
|
cannam@110
|
528 @{
|
cannam@110
|
529 */
|
cannam@110
|
530
|
cannam@110
|
531 /**
|
cannam@110
|
532 Sink (callback) for errors.
|
cannam@110
|
533
|
cannam@110
|
534 @param handle Handle for user data.
|
cannam@110
|
535 @param error Error description.
|
cannam@110
|
536 */
|
cannam@110
|
537 typedef SerdStatus (*SerdErrorSink)(void* handle,
|
cannam@110
|
538 const SerdError* error);
|
cannam@110
|
539
|
cannam@110
|
540 /**
|
cannam@110
|
541 Sink (callback) for base URI changes.
|
cannam@110
|
542
|
cannam@110
|
543 Called whenever the base URI of the serialisation changes.
|
cannam@110
|
544 */
|
cannam@110
|
545 typedef SerdStatus (*SerdBaseSink)(void* handle,
|
cannam@110
|
546 const SerdNode* uri);
|
cannam@110
|
547
|
cannam@110
|
548 /**
|
cannam@110
|
549 Sink (callback) for namespace definitions.
|
cannam@110
|
550
|
cannam@110
|
551 Called whenever a prefix is defined in the serialisation.
|
cannam@110
|
552 */
|
cannam@110
|
553 typedef SerdStatus (*SerdPrefixSink)(void* handle,
|
cannam@110
|
554 const SerdNode* name,
|
cannam@110
|
555 const SerdNode* uri);
|
cannam@110
|
556
|
cannam@110
|
557 /**
|
cannam@110
|
558 Sink (callback) for statements.
|
cannam@110
|
559
|
cannam@110
|
560 Called for every RDF statement in the serialisation.
|
cannam@110
|
561 */
|
cannam@110
|
562 typedef SerdStatus (*SerdStatementSink)(void* handle,
|
cannam@110
|
563 SerdStatementFlags flags,
|
cannam@110
|
564 const SerdNode* graph,
|
cannam@110
|
565 const SerdNode* subject,
|
cannam@110
|
566 const SerdNode* predicate,
|
cannam@110
|
567 const SerdNode* object,
|
cannam@110
|
568 const SerdNode* object_datatype,
|
cannam@110
|
569 const SerdNode* object_lang);
|
cannam@110
|
570
|
cannam@110
|
571 /**
|
cannam@110
|
572 Sink (callback) for anonymous node end markers.
|
cannam@110
|
573
|
cannam@110
|
574 This is called to indicate that the anonymous node with the given
|
cannam@110
|
575 @c value will no longer be referred to by any future statements
|
cannam@110
|
576 (i.e. the anonymous serialisation of the node is finished).
|
cannam@110
|
577 */
|
cannam@110
|
578 typedef SerdStatus (*SerdEndSink)(void* handle,
|
cannam@110
|
579 const SerdNode* node);
|
cannam@110
|
580
|
cannam@110
|
581 /**
|
cannam@110
|
582 @}
|
cannam@110
|
583 @name Environment
|
cannam@110
|
584 @{
|
cannam@110
|
585 */
|
cannam@110
|
586
|
cannam@110
|
587 /**
|
cannam@110
|
588 Create a new environment.
|
cannam@110
|
589 */
|
cannam@110
|
590 SERD_API
|
cannam@110
|
591 SerdEnv*
|
cannam@110
|
592 serd_env_new(const SerdNode* base_uri);
|
cannam@110
|
593
|
cannam@110
|
594 /**
|
cannam@110
|
595 Free @c ns.
|
cannam@110
|
596 */
|
cannam@110
|
597 SERD_API
|
cannam@110
|
598 void
|
cannam@110
|
599 serd_env_free(SerdEnv* env);
|
cannam@110
|
600
|
cannam@110
|
601 /**
|
cannam@110
|
602 Get the current base URI.
|
cannam@110
|
603 */
|
cannam@110
|
604 SERD_API
|
cannam@110
|
605 const SerdNode*
|
cannam@110
|
606 serd_env_get_base_uri(const SerdEnv* env,
|
cannam@110
|
607 SerdURI* out);
|
cannam@110
|
608
|
cannam@110
|
609 /**
|
cannam@110
|
610 Set the current base URI.
|
cannam@110
|
611 */
|
cannam@110
|
612 SERD_API
|
cannam@110
|
613 SerdStatus
|
cannam@110
|
614 serd_env_set_base_uri(SerdEnv* env,
|
cannam@110
|
615 const SerdNode* uri);
|
cannam@110
|
616
|
cannam@110
|
617 /**
|
cannam@110
|
618 Set a namespace prefix.
|
cannam@110
|
619 */
|
cannam@110
|
620 SERD_API
|
cannam@110
|
621 SerdStatus
|
cannam@110
|
622 serd_env_set_prefix(SerdEnv* env,
|
cannam@110
|
623 const SerdNode* name,
|
cannam@110
|
624 const SerdNode* uri);
|
cannam@110
|
625
|
cannam@110
|
626 /**
|
cannam@110
|
627 Set a namespace prefix.
|
cannam@110
|
628 */
|
cannam@110
|
629 SERD_API
|
cannam@110
|
630 SerdStatus
|
cannam@110
|
631 serd_env_set_prefix_from_strings(SerdEnv* env,
|
cannam@110
|
632 const uint8_t* name,
|
cannam@110
|
633 const uint8_t* uri);
|
cannam@110
|
634
|
cannam@110
|
635 /**
|
cannam@110
|
636 Qualify @c uri into a CURIE if possible.
|
cannam@110
|
637 */
|
cannam@110
|
638 SERD_API
|
cannam@110
|
639 bool
|
cannam@110
|
640 serd_env_qualify(const SerdEnv* env,
|
cannam@110
|
641 const SerdNode* uri,
|
cannam@110
|
642 SerdNode* prefix,
|
cannam@110
|
643 SerdChunk* suffix);
|
cannam@110
|
644
|
cannam@110
|
645 /**
|
cannam@110
|
646 Expand @c curie.
|
cannam@110
|
647 */
|
cannam@110
|
648 SERD_API
|
cannam@110
|
649 SerdStatus
|
cannam@110
|
650 serd_env_expand(const SerdEnv* env,
|
cannam@110
|
651 const SerdNode* curie,
|
cannam@110
|
652 SerdChunk* uri_prefix,
|
cannam@110
|
653 SerdChunk* uri_suffix);
|
cannam@110
|
654
|
cannam@110
|
655 /**
|
cannam@110
|
656 Expand @c node, which must be a CURIE or URI, to a full URI.
|
cannam@110
|
657 */
|
cannam@110
|
658 SERD_API
|
cannam@110
|
659 SerdNode
|
cannam@110
|
660 serd_env_expand_node(const SerdEnv* env,
|
cannam@110
|
661 const SerdNode* node);
|
cannam@110
|
662
|
cannam@110
|
663 /**
|
cannam@110
|
664 Call @c func for each prefix defined in @c env.
|
cannam@110
|
665 */
|
cannam@110
|
666 SERD_API
|
cannam@110
|
667 void
|
cannam@110
|
668 serd_env_foreach(const SerdEnv* env,
|
cannam@110
|
669 SerdPrefixSink func,
|
cannam@110
|
670 void* handle);
|
cannam@110
|
671
|
cannam@110
|
672 /**
|
cannam@110
|
673 @}
|
cannam@110
|
674 @name Reader
|
cannam@110
|
675 @{
|
cannam@110
|
676 */
|
cannam@110
|
677
|
cannam@110
|
678 /**
|
cannam@110
|
679 Create a new RDF reader.
|
cannam@110
|
680 */
|
cannam@110
|
681 SERD_API
|
cannam@110
|
682 SerdReader*
|
cannam@110
|
683 serd_reader_new(SerdSyntax syntax,
|
cannam@110
|
684 void* handle,
|
cannam@110
|
685 void (*free_handle)(void*),
|
cannam@110
|
686 SerdBaseSink base_sink,
|
cannam@110
|
687 SerdPrefixSink prefix_sink,
|
cannam@110
|
688 SerdStatementSink statement_sink,
|
cannam@110
|
689 SerdEndSink end_sink);
|
cannam@110
|
690
|
cannam@110
|
691 /**
|
cannam@110
|
692 Set a function to be called when errors occur during reading.
|
cannam@110
|
693
|
cannam@110
|
694 The @p error_sink will be called with @p handle as its first argument. If
|
cannam@110
|
695 no error function is set, errors are printed to stderr in GCC style.
|
cannam@110
|
696 */
|
cannam@110
|
697 SERD_API
|
cannam@110
|
698 void
|
cannam@110
|
699 serd_reader_set_error_sink(SerdReader* reader,
|
cannam@110
|
700 SerdErrorSink error_sink,
|
cannam@110
|
701 void* handle);
|
cannam@110
|
702
|
cannam@110
|
703 /**
|
cannam@110
|
704 Return the @c handle passed to @ref serd_reader_new.
|
cannam@110
|
705 */
|
cannam@110
|
706 SERD_API
|
cannam@110
|
707 void*
|
cannam@110
|
708 serd_reader_get_handle(const SerdReader* reader);
|
cannam@110
|
709
|
cannam@110
|
710 /**
|
cannam@110
|
711 Set a prefix to be added to all blank node identifiers.
|
cannam@110
|
712
|
cannam@110
|
713 This is useful when multiple files are to be parsed into the same output
|
cannam@110
|
714 (e.g. a store, or other files). Since Serd preserves blank node IDs, this
|
cannam@110
|
715 could cause conflicts where two non-equivalent blank nodes are merged,
|
cannam@110
|
716 resulting in corrupt data. By setting a unique blank node prefix for each
|
cannam@110
|
717 parsed file, this can be avoided, while preserving blank node names.
|
cannam@110
|
718 */
|
cannam@110
|
719 SERD_API
|
cannam@110
|
720 void
|
cannam@110
|
721 serd_reader_add_blank_prefix(SerdReader* reader,
|
cannam@110
|
722 const uint8_t* prefix);
|
cannam@110
|
723
|
cannam@110
|
724 /**
|
cannam@110
|
725 Set the URI of the default graph.
|
cannam@110
|
726
|
cannam@110
|
727 If this is set, the reader will emit quads with the graph set to the given
|
cannam@110
|
728 node for any statements that are not in a named graph (which is currently
|
cannam@110
|
729 all of them since Serd currently does not support any graph syntaxes).
|
cannam@110
|
730 */
|
cannam@110
|
731 SERD_API
|
cannam@110
|
732 void
|
cannam@110
|
733 serd_reader_set_default_graph(SerdReader* reader,
|
cannam@110
|
734 const SerdNode* graph);
|
cannam@110
|
735
|
cannam@110
|
736 /**
|
cannam@110
|
737 Read a file at a given @c uri.
|
cannam@110
|
738 */
|
cannam@110
|
739 SERD_API
|
cannam@110
|
740 SerdStatus
|
cannam@110
|
741 serd_reader_read_file(SerdReader* reader,
|
cannam@110
|
742 const uint8_t* uri);
|
cannam@110
|
743
|
cannam@110
|
744 /**
|
cannam@110
|
745 Start an incremental read from a file handle.
|
cannam@110
|
746
|
cannam@110
|
747 Iff @p bulk is true, @p file will be read a page at a time. This is more
|
cannam@110
|
748 efficient, but uses a page of memory and means that an entire page of input
|
cannam@110
|
749 must be ready before any callbacks will fire. To react as soon as input
|
cannam@110
|
750 arrives, set @p bulk to false.
|
cannam@110
|
751 */
|
cannam@110
|
752 SERD_API
|
cannam@110
|
753 SerdStatus
|
cannam@110
|
754 serd_reader_start_stream(SerdReader* me,
|
cannam@110
|
755 FILE* file,
|
cannam@110
|
756 const uint8_t* name,
|
cannam@110
|
757 bool bulk);
|
cannam@110
|
758
|
cannam@110
|
759 /**
|
cannam@110
|
760 Read a single "chunk" of data during an incremental read.
|
cannam@110
|
761
|
cannam@110
|
762 This function will read a single top level description, and return. This
|
cannam@110
|
763 may be a directive, statement, or several statements; essentially it reads
|
cannam@110
|
764 until a '.' is encountered. This is particularly useful for reading
|
cannam@110
|
765 directly from a pipe or socket.
|
cannam@110
|
766 */
|
cannam@110
|
767 SERD_API
|
cannam@110
|
768 SerdStatus
|
cannam@110
|
769 serd_reader_read_chunk(SerdReader* me);
|
cannam@110
|
770
|
cannam@110
|
771 /**
|
cannam@110
|
772 Finish an incremental read from a file handle.
|
cannam@110
|
773 */
|
cannam@110
|
774 SERD_API
|
cannam@110
|
775 SerdStatus
|
cannam@110
|
776 serd_reader_end_stream(SerdReader* me);
|
cannam@110
|
777
|
cannam@110
|
778 /**
|
cannam@110
|
779 Read @c file.
|
cannam@110
|
780 */
|
cannam@110
|
781 SERD_API
|
cannam@110
|
782 SerdStatus
|
cannam@110
|
783 serd_reader_read_file_handle(SerdReader* reader,
|
cannam@110
|
784 FILE* file,
|
cannam@110
|
785 const uint8_t* name);
|
cannam@110
|
786
|
cannam@110
|
787 /**
|
cannam@110
|
788 Read @c utf8.
|
cannam@110
|
789 */
|
cannam@110
|
790 SERD_API
|
cannam@110
|
791 SerdStatus
|
cannam@110
|
792 serd_reader_read_string(SerdReader* me, const uint8_t* utf8);
|
cannam@110
|
793
|
cannam@110
|
794 /**
|
cannam@110
|
795 Free @c reader.
|
cannam@110
|
796 */
|
cannam@110
|
797 SERD_API
|
cannam@110
|
798 void
|
cannam@110
|
799 serd_reader_free(SerdReader* reader);
|
cannam@110
|
800
|
cannam@110
|
801 /**
|
cannam@110
|
802 @}
|
cannam@110
|
803 @name Writer
|
cannam@110
|
804 @{
|
cannam@110
|
805 */
|
cannam@110
|
806
|
cannam@110
|
807 /**
|
cannam@110
|
808 Create a new RDF writer.
|
cannam@110
|
809 */
|
cannam@110
|
810 SERD_API
|
cannam@110
|
811 SerdWriter*
|
cannam@110
|
812 serd_writer_new(SerdSyntax syntax,
|
cannam@110
|
813 SerdStyle style,
|
cannam@110
|
814 SerdEnv* env,
|
cannam@110
|
815 const SerdURI* base_uri,
|
cannam@110
|
816 SerdSink sink,
|
cannam@110
|
817 void* stream);
|
cannam@110
|
818
|
cannam@110
|
819 /**
|
cannam@110
|
820 Free @c writer.
|
cannam@110
|
821 */
|
cannam@110
|
822 SERD_API
|
cannam@110
|
823 void
|
cannam@110
|
824 serd_writer_free(SerdWriter* writer);
|
cannam@110
|
825
|
cannam@110
|
826 /**
|
cannam@110
|
827 Return the env used by @c writer.
|
cannam@110
|
828 */
|
cannam@110
|
829 SERD_API
|
cannam@110
|
830 SerdEnv*
|
cannam@110
|
831 serd_writer_get_env(SerdWriter* writer);
|
cannam@110
|
832
|
cannam@110
|
833 /**
|
cannam@110
|
834 A convenience sink function for writing to a FILE*.
|
cannam@110
|
835
|
cannam@110
|
836 This function can be used as a SerdSink when writing to a FILE*. The
|
cannam@110
|
837 @c stream parameter must be a FILE* opened for writing.
|
cannam@110
|
838 */
|
cannam@110
|
839 SERD_API
|
cannam@110
|
840 size_t
|
cannam@110
|
841 serd_file_sink(const void* buf, size_t len, void* stream);
|
cannam@110
|
842
|
cannam@110
|
843 /**
|
cannam@110
|
844 A convenience sink function for writing to a string.
|
cannam@110
|
845
|
cannam@110
|
846 This function can be used as a SerdSink to write to a SerdChunk which is
|
cannam@110
|
847 resized as necessary with realloc(). The @c stream parameter must point to
|
cannam@110
|
848 an initialized SerdChunk. When the write is finished, the string should be
|
cannam@110
|
849 retrieved with serd_chunk_sink_finish().
|
cannam@110
|
850 */
|
cannam@110
|
851 SERD_API
|
cannam@110
|
852 size_t
|
cannam@110
|
853 serd_chunk_sink(const void* buf, size_t len, void* stream);
|
cannam@110
|
854
|
cannam@110
|
855 /**
|
cannam@110
|
856 Finish a serialisation to a chunk with serd_chunk_sink().
|
cannam@110
|
857
|
cannam@110
|
858 The returned string is the result of the serialisation, which is NULL
|
cannam@110
|
859 terminated (by this function) and owned by the caller.
|
cannam@110
|
860 */
|
cannam@110
|
861 SERD_API
|
cannam@110
|
862 uint8_t*
|
cannam@110
|
863 serd_chunk_sink_finish(SerdChunk* stream);
|
cannam@110
|
864
|
cannam@110
|
865 /**
|
cannam@110
|
866 Set a function to be called when errors occur during writing.
|
cannam@110
|
867
|
cannam@110
|
868 The @p error_sink will be called with @p handle as its first argument. If
|
cannam@110
|
869 no error function is set, errors are printed to stderr.
|
cannam@110
|
870 */
|
cannam@110
|
871 SERD_API
|
cannam@110
|
872 void
|
cannam@110
|
873 serd_writer_set_error_sink(SerdWriter* writer,
|
cannam@110
|
874 SerdErrorSink error_sink,
|
cannam@110
|
875 void* handle);
|
cannam@110
|
876
|
cannam@110
|
877 /**
|
cannam@110
|
878 Set a prefix to be removed from matching blank node identifiers.
|
cannam@110
|
879 */
|
cannam@110
|
880 SERD_API
|
cannam@110
|
881 void
|
cannam@110
|
882 serd_writer_chop_blank_prefix(SerdWriter* writer,
|
cannam@110
|
883 const uint8_t* prefix);
|
cannam@110
|
884
|
cannam@110
|
885 /**
|
cannam@110
|
886 Set the current output base URI (and emit directive if applicable).
|
cannam@110
|
887
|
cannam@110
|
888 Note this function can be safely casted to SerdBaseSink.
|
cannam@110
|
889 */
|
cannam@110
|
890 SERD_API
|
cannam@110
|
891 SerdStatus
|
cannam@110
|
892 serd_writer_set_base_uri(SerdWriter* writer,
|
cannam@110
|
893 const SerdNode* uri);
|
cannam@110
|
894
|
cannam@110
|
895 /**
|
cannam@110
|
896 Set the current root URI.
|
cannam@110
|
897
|
cannam@110
|
898 The root URI should be a prefix of the base URI. The path of the root URI
|
cannam@110
|
899 is the highest path any relative up-reference can refer to. For example,
|
cannam@110
|
900 with root <file:///foo/root> and base <file:///foo/root/base>,
|
cannam@110
|
901 <file:///foo/root> will be written as <../>, but <file:///foo> will be
|
cannam@110
|
902 written non-relatively as <file:///foo>. If the root is not explicitly set,
|
cannam@110
|
903 it defaults to the base URI, so no up-references will be created at all.
|
cannam@110
|
904 */
|
cannam@110
|
905 SERD_API
|
cannam@110
|
906 SerdStatus
|
cannam@110
|
907 serd_writer_set_root_uri(SerdWriter* writer,
|
cannam@110
|
908 const SerdNode* uri);
|
cannam@110
|
909
|
cannam@110
|
910 /**
|
cannam@110
|
911 Set a namespace prefix (and emit directive if applicable).
|
cannam@110
|
912
|
cannam@110
|
913 Note this function can be safely casted to SerdPrefixSink.
|
cannam@110
|
914 */
|
cannam@110
|
915 SERD_API
|
cannam@110
|
916 SerdStatus
|
cannam@110
|
917 serd_writer_set_prefix(SerdWriter* writer,
|
cannam@110
|
918 const SerdNode* name,
|
cannam@110
|
919 const SerdNode* uri);
|
cannam@110
|
920
|
cannam@110
|
921 /**
|
cannam@110
|
922 Write a statement.
|
cannam@110
|
923
|
cannam@110
|
924 Note this function can be safely casted to SerdStatementSink.
|
cannam@110
|
925 */
|
cannam@110
|
926 SERD_API
|
cannam@110
|
927 SerdStatus
|
cannam@110
|
928 serd_writer_write_statement(SerdWriter* writer,
|
cannam@110
|
929 SerdStatementFlags flags,
|
cannam@110
|
930 const SerdNode* graph,
|
cannam@110
|
931 const SerdNode* subject,
|
cannam@110
|
932 const SerdNode* predicate,
|
cannam@110
|
933 const SerdNode* object,
|
cannam@110
|
934 const SerdNode* object_datatype,
|
cannam@110
|
935 const SerdNode* object_lang);
|
cannam@110
|
936
|
cannam@110
|
937 /**
|
cannam@110
|
938 Mark the end of an anonymous node's description.
|
cannam@110
|
939
|
cannam@110
|
940 Note this function can be safely casted to SerdEndSink.
|
cannam@110
|
941 */
|
cannam@110
|
942 SERD_API
|
cannam@110
|
943 SerdStatus
|
cannam@110
|
944 serd_writer_end_anon(SerdWriter* writer,
|
cannam@110
|
945 const SerdNode* node);
|
cannam@110
|
946
|
cannam@110
|
947 /**
|
cannam@110
|
948 Finish a write.
|
cannam@110
|
949 */
|
cannam@110
|
950 SERD_API
|
cannam@110
|
951 SerdStatus
|
cannam@110
|
952 serd_writer_finish(SerdWriter* writer);
|
cannam@110
|
953
|
cannam@110
|
954 /**
|
cannam@110
|
955 @}
|
cannam@110
|
956 @}
|
cannam@110
|
957 */
|
cannam@110
|
958
|
cannam@110
|
959 #ifdef __cplusplus
|
cannam@110
|
960 } /* extern "C" */
|
cannam@110
|
961 #endif
|
cannam@110
|
962
|
cannam@110
|
963 #endif /* SERD_SERD_H */
|