aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/env.c3
-rw-r--r--src/reader.c9
-rw-r--r--src/serdi.c6
-rw-r--r--src/uri.c85
-rw-r--r--src/writer.c9
5 files changed, 58 insertions, 54 deletions
diff --git a/src/env.c b/src/env.c
index d53ef73e..aaa910e1 100644
--- a/src/env.c
+++ b/src/env.c
@@ -266,7 +266,8 @@ serd_env_expand_node(const SerdEnv* env,
0,
SERD_URI };
ret.buf = malloc(ret.n_bytes + 1);
- snprintf((char*)ret.buf, ret.n_bytes + 1, "%s%s", prefix.buf, suffix.buf);
+ snprintf((char*)ret.buf, ret.n_bytes + 1,
+ "%s%s", prefix.buf, suffix.buf);
return ret;
} else if (node->type == SERD_URI) {
SerdURI ignored;
diff --git a/src/reader.c b/src/reader.c
index 3cb2e3db..70bdd1a1 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -67,7 +67,7 @@ static const Node INTERNAL_NODE_NULL = { 0, 0 };
struct SerdReaderImpl {
void* handle;
- void (*free_handle)(void*);
+ void (*free_handle)(void* ptr);
SerdBaseSink base_sink;
SerdPrefixSink prefix_sink;
SerdStatementSink statement_sink;
@@ -330,8 +330,11 @@ emit_statement(SerdReader* reader, SerdStatementFlags* flags,
return ret;
}
-static bool read_collection(SerdReader* reader, ReadContext ctx, Node* dest);
-static bool read_predicateObjectList(SerdReader* reader, ReadContext ctx, bool blank);
+static bool
+read_collection(SerdReader* reader, ReadContext ctx, Node* dest);
+
+static bool
+read_predicateObjectList(SerdReader* reader, ReadContext ctx, bool blank);
// [40] hex ::= [#x30-#x39] | [#x41-#x46]
static inline uint8_t
diff --git a/src/serdi.c b/src/serdi.c
index c3f7aa2e..ef7d72cb 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -74,7 +74,7 @@ set_syntax(SerdSyntax* syntax, const char* name)
}
return true;
}
-
+
int
main(int argc, char** argv)
{
@@ -142,7 +142,7 @@ main(int argc, char** argv)
fprintf(stderr, "Missing input\n");
return 1;
}
-
+
const uint8_t* input = (const uint8_t*)argv[a++];
if (from_file) {
in_name = in_name ? in_name : input;
@@ -183,7 +183,7 @@ main(int argc, char** argv)
SerdURI base_uri = SERD_URI_NULL;
SerdNode base_uri_node = serd_node_new_uri_from_string(
base_uri_str, &base_uri, &base_uri);
-
+
if (!base_uri_node.buf) {
fprintf(stderr, "Invalid base URI <%s>\n", base_uri_str);
return 1;
diff --git a/src/uri.c b/src/uri.c
index 04ca8c84..61fb35ce 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -292,68 +292,67 @@ serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream)
if (uri->path_base.len) {
if (!uri->path.buf && (uri->fragment.buf || uri->query.buf)) {
WRITE_COMPONENT("", uri->path_base, "");
- } else {
+ } else if (uri->path.buf) {
/* Merge paths, removing dot components.
See http://tools.ietf.org/html/rfc3986#section-5.2.3
*/
const uint8_t* begin = uri->path.buf;
size_t up = 1;
- if (begin) {
- // Count and skip leading dot components
- const uint8_t* end = uri->path.buf + uri->path.len;
- for (bool done = false; !done && (begin < end);) {
- switch (begin[0]) {
+ // Count and skip leading dot components
+ const uint8_t* end = uri->path.buf + uri->path.len;
+ for (bool done = false; !done && (begin < end);) {
+ switch (begin[0]) {
+ case '.':
+ switch (begin[1]) {
+ case '/':
+ begin += 2; // Chop leading "./"
+ break;
case '.':
- switch (begin[1]) {
+ ++up;
+ switch (begin[2]) {
case '/':
- begin += 2; // Chop leading "./"
- break;
- case '.':
- ++up;
- switch (begin[2]) {
- case '/':
- begin += 3; // Chop lading "../"
- break;
- default:
- begin += 2; // Chop leading ".."
- }
+ begin += 3; // Chop lading "../"
break;
default:
- ++begin; // Chop leading "."
+ begin += 2; // Chop leading ".."
}
break;
- case '/':
- if (begin[1] == '/') {
- ++begin; // Replace leading "//" with "/"
- break;
- } // else fall through
default:
- done = true; // Finished chopping dot components
+ ++begin; // Chop leading "."
}
+ break;
+ case '/':
+ if (begin[1] == '/') {
+ ++begin; // Replace leading "//" with "/"
+ break;
+ } // else fall through
+ default:
+ done = true; // Finished chopping dot components
}
+ }
- if (uri->path.buf && uri->path_base.buf) {
- // Find the up'th last slash
- const uint8_t* base_last = uri->path_base.buf + uri->path_base.len - 1;
- do {
- if (*base_last == '/') {
- --up;
- }
- } while (up > 0 && (--base_last > uri->path_base.buf));
-
- // Write base URI prefix
- const size_t base_len = base_last - uri->path_base.buf + 1;
- WRITE(uri->path_base.buf, base_len);
+ if (uri->path.buf && uri->path_base.buf) {
+ // Find the up'th last slash
+ const uint8_t* base_last = (uri->path_base.buf
+ + uri->path_base.len - 1);
+ do {
+ if (*base_last == '/') {
+ --up;
+ }
+ } while (up > 0 && (--base_last > uri->path_base.buf));
- } else {
- // Relative path is just query or fragment, append it to full base URI
- WRITE_COMPONENT("", uri->path_base, "");
- }
+ // Write base URI prefix
+ const size_t base_len = base_last - uri->path_base.buf + 1;
+ WRITE(uri->path_base.buf, base_len);
- // Write URI suffix
- WRITE(begin, end - begin);
+ } else {
+ // Relative path is just query or fragment, append to base URI
+ WRITE_COMPONENT("", uri->path_base, "");
}
+
+ // Write URI suffix
+ WRITE(begin, end - begin);
}
} else {
WRITE_COMPONENT("", uri->path, "");
diff --git a/src/writer.c b/src/writer.c
index cb68ed46..a3cb5eab 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -213,9 +213,9 @@ write_node(SerdWriter* writer,
writer->sink("[]", 2, writer->stream);
} else {
writer->sink("_:", 2, writer->stream);
- if (writer->bprefix
- && !strncmp((const char*)node->buf, (const char*)writer->bprefix,
- writer->bprefix_len)) {
+ if (writer->bprefix && !strncmp((const char*)node->buf,
+ (const char*)writer->bprefix,
+ writer->bprefix_len)) {
writer->sink(node->buf + writer->bprefix_len,
node->n_bytes - writer->bprefix_len,
writer->stream);
@@ -254,7 +254,8 @@ write_node(SerdWriter* writer,
&& ((node->flags & SERD_HAS_NEWLINE)
|| (node->flags & SERD_HAS_QUOTE))) {
writer->sink("\"\"\"", 3, writer->stream);
- write_text(writer, WRITE_LONG_STRING, node->buf, node->n_bytes, '\0');
+ write_text(writer, WRITE_LONG_STRING,
+ node->buf, node->n_bytes, '\0');
writer->sink("\"\"\"", 3, writer->stream);
} else {
writer->sink("\"", 1, writer->stream);