diff options
-rw-r--r-- | sord/sord.h | 11 | ||||
-rw-r--r-- | sord/sordmm.hpp | 2 | ||||
-rw-r--r-- | src/sord.c | 40 | ||||
-rw-r--r-- | src/sord_internal.h | 13 | ||||
-rw-r--r-- | src/sordi.c | 9 | ||||
-rw-r--r-- | src/syntax.c | 9 |
6 files changed, 55 insertions, 29 deletions
diff --git a/sord/sord.h b/sord/sord.h index 8159170..68c0289 100644 --- a/sord/sord.h +++ b/sord/sord.h @@ -209,8 +209,8 @@ sord_new_literal_counted(SordWorld* world, SordNode* datatype, const uint8_t* str, size_t str_len, - const char* lang, - uint8_t lang_len); + SerdNodeFlags flags, + const char* lang); /** Copy a node (i.e. obtain a reference). @@ -265,6 +265,13 @@ SordNode* sord_node_get_datatype(const SordNode* node); /** + Return the flags (string attributes) of a node. +*/ +SORD_API +SerdNodeFlags +sord_node_get_flags(const SordNode* node); + +/** Return true iff @c a is equal to @c b. Note this is much faster than comparing the node's strings. diff --git a/sord/sordmm.hpp b/sord/sordmm.hpp index 5345b92..d37d6e5 100644 --- a/sord/sordmm.hpp +++ b/sord/sordmm.hpp @@ -67,7 +67,7 @@ public: static inline SerdNode string_to_node(SerdType type, const std::string& s) { SerdNode ret = { - (const uint8_t*)s.c_str(), s.length() + 1, s.length(), type }; + (const uint8_t*)s.c_str(), s.length() + 1, s.length(), 0, type }; return ret; } @@ -763,7 +763,8 @@ sord_lookup_name(SordWorld* world, const uint8_t* str, size_t str_len) } static SordNode* -sord_new_node(SordNodeType type, const uint8_t* data, size_t n_bytes) +sord_new_node(SordNodeType type, const uint8_t* data, + size_t n_bytes, SerdNodeFlags flags) { SordNode* node = malloc(sizeof(struct SordNodeImpl)); node->type = type; @@ -771,6 +772,7 @@ sord_new_node(SordNodeType type, const uint8_t* data, size_t n_bytes) node->refs = 1; node->datatype = 0; node->lang = 0; + node->flags = flags; node->buf = (uint8_t*)g_strdup((const char*)data); // TODO: no-copy return node; } @@ -792,10 +794,10 @@ sord_intern_lang(SordWorld* world, const char* lang) static SordNode* sord_new_literal_node(SordWorld* world, SordNode* datatype, - const uint8_t* str, int str_len, - const char* lang, uint8_t lang_len) + const uint8_t* str, size_t str_len, SerdNodeFlags flags, + const char* lang) { - SordNode* node = sord_new_node(SORD_LITERAL, str, str_len + 1); + SordNode* node = sord_new_node(SORD_LITERAL, str, str_len + 1, flags); node->datatype = sord_node_copy(datatype); node->lang = sord_intern_lang(world, lang); return node; @@ -803,8 +805,8 @@ sord_new_literal_node(SordWorld* world, SordNode* datatype, static SordNode* sord_lookup_literal(SordWorld* world, SordNode* type, - const uint8_t* str, int str_len, - const char* lang, uint8_t lang_len) + const uint8_t* str, size_t str_len, + const char* lang) { // Make search key (FIXME: ick) struct SordNodeImpl key; @@ -814,6 +816,7 @@ sord_lookup_literal(SordWorld* world, SordNode* type, key.datatype = type; key.lang = sord_intern_lang(world, lang); key.buf = (uint8_t*)str; + key.flags = 0; SordNode* id = g_hash_table_lookup(world->literals, &key); if (id) { @@ -854,6 +857,12 @@ sord_node_get_datatype(const SordNode* ref) return ref->datatype; } +SerdNodeFlags +sord_node_get_flags(const SordNode* node) +{ + return node->flags; +} + static void sord_add_node(SordWorld* world, SordNode* node) { @@ -869,7 +878,7 @@ sord_new_uri_counted(SordWorld* world, const uint8_t* str, size_t str_len) return node; } - node = sord_new_node(SORD_URI, str, str_len + 1); + node = sord_new_node(SORD_URI, str, str_len + 1, 0); assert(!g_hash_table_lookup(world->names, node->buf)); g_hash_table_insert(world->names, node->buf, node); sord_add_node(world, node); @@ -891,7 +900,7 @@ sord_new_blank_counted(SordWorld* world, const uint8_t* str, size_t str_len) return node; } - node = sord_new_node(SORD_BLANK, str, str_len + 1); + node = sord_new_node(SORD_BLANK, str, str_len + 1, 0); g_hash_table_insert(world->names, node->buf, node); sord_add_node(world, node); return node; @@ -905,16 +914,16 @@ sord_new_blank(SordWorld* world, const uint8_t* str) SordNode* sord_new_literal_counted(SordWorld* world, SordNode* datatype, - const uint8_t* str, size_t str_len, - const char* lang, uint8_t lang_len) + const uint8_t* str, size_t str_len, SerdNodeFlags flags, + const char* lang) { - SordNode* node = sord_lookup_literal(world, datatype, str, str_len, lang, lang_len); + SordNode* node = sord_lookup_literal(world, datatype, str, str_len, lang); if (node) { ++node->refs; return node; } - node = sord_new_literal_node(world, datatype, str, str_len, lang, lang_len); + node = sord_new_literal_node(world, datatype, str, str_len, flags, lang); g_hash_table_insert(world->literals, node, node); // FIXME: correct? sord_add_node(world, node); assert(node->refs == 1); @@ -925,9 +934,12 @@ SordNode* sord_new_literal(SordWorld* world, SordNode* datatype, const uint8_t* str, const char* lang) { + SerdNodeFlags flags = 0; + size_t n_bytes = 0; + size_t n_chars = serd_strlen(str, &n_bytes, &flags); return sord_new_literal_counted(world, datatype, - str, strlen((const char*)str), - lang, lang ? strlen(lang) : 0); + str, n_bytes - 1, flags, + lang); } void diff --git a/src/sord_internal.h b/src/sord_internal.h index 727701f..6935de8 100644 --- a/src/sord_internal.h +++ b/src/sord_internal.h @@ -24,12 +24,13 @@ /** Node */ struct SordNodeImpl { - uint8_t* buf; ///< Value (string) - const char* lang; ///< Literal language (interned string) - SordNode* datatype; ///< Literal data type (ID of a URI node, or 0) - size_t n_bytes; ///< Length of data in bytes (including NULL) - size_t refs; ///< Reference count (# of containing quads) - SordNodeType type; ///< SordNodeType + uint8_t* buf; ///< Value (string) + const char* lang; ///< Literal language (interned string) + SordNode* datatype; ///< Literal data type (ID of a URI node, or 0) + size_t n_bytes; ///< Length of data in bytes (including NULL) + size_t refs; ///< Reference count (# of containing quads) + SerdNodeFlags flags; ///< String properties + SordNodeType type; ///< SordNodeType }; const char* diff --git a/src/sordi.c b/src/sordi.c index 78f8690..1f663ea 100644 --- a/src/sordi.c +++ b/src/sordi.c @@ -65,7 +65,9 @@ serd_node_from_sord_node(const SordNode* n) { size_t n_bytes = 0; const uint8_t* buf = sord_node_get_string_counted(n, &n_bytes); - SerdNode sn = { (const uint8_t*)buf, n_bytes, n_bytes - 1, SERD_NOTHING }; + SerdNode sn = { + (const uint8_t*)buf, n_bytes, n_bytes - 1, sord_node_get_flags(n), SERD_NOTHING + }; // FIXME: UTF-8 switch (sord_node_get_type(n)) { case SORD_URI: @@ -130,8 +132,9 @@ main(int argc, char** argv) } SerdEnv* env = serd_env_new(); - SerdWriter* writer = serd_writer_new(SERD_TURTLE, SERD_STYLE_ABBREVIATED, - env, &base_uri, file_sink, stdout); + SerdWriter* writer = serd_writer_new( + SERD_TURTLE, SERD_STYLE_ABBREVIATED|SERD_STYLE_RESOLVED, + env, &base_uri, file_sink, stdout); // Query SordQuad pat = { 0, 0, 0, 0 }; diff --git a/src/syntax.c b/src/syntax.c index 937de7d..1964d24 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -73,10 +73,12 @@ sord_node_from_serd_node(ReadState* state, const SerdNode* sn, return NULL; case SERD_LITERAL: datatype_node = sord_node_from_serd_node(state, datatype, NULL, NULL), - ret = sord_new_literal( + ret = sord_new_literal_counted( state->world, datatype_node, sn->buf, + sn->n_bytes - 1, + sn->flags, sord_intern_lang(state->world, (const char*)lang->buf)); sord_node_free(state->world, datatype_node); return ret; @@ -86,7 +88,8 @@ sord_node_from_serd_node(ReadState* state, const SerdNode* sn, SerdURI abs_uri; SerdNode abs_uri_node = serd_node_new_uri_from_node( sn, &base_uri, &abs_uri); - SordNode* ret = sord_new_uri(state->world, abs_uri_node.buf); + SordNode* ret = sord_new_uri_counted(state->world, abs_uri_node.buf, + abs_uri_node.n_bytes - 1); serd_node_free(&abs_uri_node); return ret; } @@ -110,7 +113,7 @@ sord_node_from_serd_node(ReadState* state, const SerdNode* sn, case SERD_BLANK_ID: case SERD_ANON_BEGIN: case SERD_ANON: - return sord_new_blank(state->world, sn->buf); + return sord_new_blank_counted(state->world, sn->buf, sn->n_bytes - 1); } return NULL; } |