diff options
author | David Robillard <d@drobilla.net> | 2018-05-01 14:34:42 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-05-27 18:21:57 +0200 |
commit | b5eeb621520d9c0c2647bfa1bfb53045a75a8b6e (patch) | |
tree | 7fdd27ad8b0e9552be7314039c544ed0ffdef735 | |
parent | aa41376304f135bfc54d2b5c16fa8ecd7302ad24 (diff) | |
download | serd-b5eeb621520d9c0c2647bfa1bfb53045a75a8b6e.tar.gz serd-b5eeb621520d9c0c2647bfa1bfb53045a75a8b6e.tar.bz2 serd-b5eeb621520d9c0c2647bfa1bfb53045a75a8b6e.zip |
Remove syntax assumptions from SerdEnv implementation
-rw-r--r-- | src/env.c | 26 | ||||
-rw-r--r-- | src/writer.c | 16 |
2 files changed, 16 insertions, 26 deletions
@@ -20,7 +20,6 @@ #include <string.h> #include "node.h" -#include "string_utils.h" typedef struct { SerdNode* name; @@ -168,27 +167,6 @@ serd_env_set_prefix_from_strings(SerdEnv* env, return st; } -static inline bool -is_nameChar(const char c) -{ - return is_alpha(c) || is_digit(c) || c == '_'; -} - -/** - Return true iff `buf` is a valid prefixed name suffix. - TODO: This is more strict than it should be. -*/ -static inline bool -is_name(const char* buf, size_t len) -{ - for (size_t i = 0; i < len; ++i) { - if (!is_nameChar(buf[i])) { - return false; - } - } - return true; -} - SERD_API bool serd_env_qualify(const SerdEnv* env, @@ -206,9 +184,7 @@ serd_env_qualify(const SerdEnv* env, *prefix = env->prefixes[i].name; suffix->buf = uri_str + prefix_uri->n_bytes; suffix->len = uri->n_bytes - prefix_uri->n_bytes; - if (is_name(suffix->buf, suffix->len)) { - return true; - } + return true; } } } diff --git a/src/writer.c b/src/writer.c index e14814bb..f75c23a0 100644 --- a/src/writer.c +++ b/src/writer.c @@ -486,6 +486,19 @@ write_literal(SerdWriter* writer, return true; } +// Return true iff `buf` is a valid prefixed name suffix +static inline bool +is_name(const char* buf, const size_t len) +{ + // TODO: This is more strict than it should be. + for (size_t i = 0; i < len; ++i) { + if (!(is_alpha(buf[i]) || is_digit(buf[i]))) { + return false; + } + } + return true; +} + static bool write_uri_node(SerdWriter* const writer, const SerdNode* node, @@ -509,7 +522,8 @@ write_uri_node(SerdWriter* const writer, } else if (supports_abbrev(writer) && !strcmp(node_str, NS_RDF "nil")) { return sink("()", 2, writer) == 2; } else if (has_scheme && (writer->style & SERD_STYLE_CURIED) && - serd_env_qualify(writer->env, node, &prefix, &suffix)) { + serd_env_qualify(writer->env, node, &prefix, &suffix) && + is_name(suffix.buf, suffix.len)) { write_uri_from_node(writer, prefix); sink(":", 1, writer); write_uri(writer, suffix.buf, suffix.len); |