diff options
author | David Robillard <d@drobilla.net> | 2020-11-13 11:22:18 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-07 15:32:23 -0500 |
commit | c0410fab52f4e2e36c2779a6ec8dc9ef89a8ee58 (patch) | |
tree | d23d782c96ae4ed4e26bdb3a8c9343175364986d | |
parent | 3ec66799f0b9be2f83251721f91a8b913abd29ec (diff) | |
download | serd-c0410fab52f4e2e36c2779a6ec8dc9ef89a8ee58.tar.gz serd-c0410fab52f4e2e36c2779a6ec8dc9ef89a8ee58.tar.bz2 serd-c0410fab52f4e2e36c2779a6ec8dc9ef89a8ee58.zip |
Shorten node constructor names
-rw-r--r-- | include/serd/serd.h | 44 | ||||
-rw-r--r-- | src/env.c | 6 | ||||
-rw-r--r-- | src/node.c | 38 | ||||
-rw-r--r-- | src/serdi.c | 4 | ||||
-rw-r--r-- | test/test_node.c | 6 | ||||
-rw-r--r-- | test/test_uri.c | 22 |
6 files changed, 58 insertions, 62 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h index dcc872ef..c1dcd2f6 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -325,7 +325,7 @@ serd_strtod(const char* SERD_NONNULL str, Decode a base64 string. This function can be used to deserialise a blob node created with - serd_node_new_blob(). + serd_new_blob(). @param str Base64 string to decode. @param len The length of `str`. @@ -470,19 +470,19 @@ serd_node_from_substring(SerdNodeType type, const char* SERD_NULLABLE str, size_t len); -/// Simple wrapper for serd_node_new_uri() to resolve a URI node +/// Simple wrapper for serd_new_uri() to resolve a URI node SERD_API SerdNode -serd_node_new_uri_from_node(const SerdNode* SERD_NONNULL uri_node, - const SerdURIView* SERD_NULLABLE base, - SerdURIView* SERD_NULLABLE out); +serd_new_uri_from_node(const SerdNode* SERD_NONNULL uri_node, + const SerdURIView* SERD_NULLABLE base, + SerdURIView* SERD_NULLABLE out); -/// Simple wrapper for serd_node_new_uri() to resolve a URI string +/// Simple wrapper for serd_new_uri() to resolve a URI string SERD_API SerdNode -serd_node_new_uri_from_string(const char* SERD_NULLABLE str, - const SerdURIView* SERD_NULLABLE base, - SerdURIView* SERD_NULLABLE out); +serd_new_uri_from_string(const char* SERD_NULLABLE str, + const SerdURIView* SERD_NULLABLE base, + SerdURIView* SERD_NULLABLE out); /** Create a new file URI node from a file system path and optional hostname. @@ -495,9 +495,9 @@ serd_node_new_uri_from_string(const char* SERD_NULLABLE str, */ SERD_API SerdNode -serd_node_new_file_uri(const char* SERD_NONNULL path, - const char* SERD_NULLABLE hostname, - SerdURIView* SERD_NULLABLE out); +serd_new_file_uri(const char* SERD_NONNULL path, + const char* SERD_NULLABLE hostname, + SerdURIView* SERD_NULLABLE out); /** Create a new node by serialising `uri` into a new string. @@ -511,9 +511,9 @@ serd_node_new_file_uri(const char* SERD_NONNULL path, */ SERD_API SerdNode -serd_node_new_uri(const SerdURIView* SERD_NONNULL uri, - const SerdURIView* SERD_NULLABLE base, - SerdURIView* SERD_NULLABLE out); +serd_new_uri(const SerdURIView* SERD_NONNULL uri, + const SerdURIView* SERD_NULLABLE base, + SerdURIView* SERD_NULLABLE out); /** Create a new node by serialising `uri` into a new relative URI. @@ -529,10 +529,10 @@ serd_node_new_uri(const SerdURIView* SERD_NONNULL uri, */ SERD_API SerdNode -serd_node_new_relative_uri(const SerdURIView* SERD_NONNULL uri, - const SerdURIView* SERD_NULLABLE base, - const SerdURIView* SERD_NULLABLE root, - SerdURIView* SERD_NULLABLE out); +serd_new_relative_uri(const SerdURIView* SERD_NONNULL uri, + const SerdURIView* SERD_NULLABLE base, + const SerdURIView* SERD_NULLABLE root, + SerdURIView* SERD_NULLABLE out); /** Create a new node by serialising `d` into an xsd:decimal string @@ -551,12 +551,12 @@ serd_node_new_relative_uri(const SerdURIView* SERD_NONNULL uri, */ SERD_API SerdNode -serd_node_new_decimal(double d, unsigned frac_digits); +serd_new_decimal(double d, unsigned frac_digits); /// Create a new node by serialising `i` into an xsd:integer string SERD_API SerdNode -serd_node_new_integer(int64_t i); +serd_new_integer(int64_t i); /** Create a node by serialising `buf` into an xsd:base64Binary string @@ -570,7 +570,7 @@ serd_node_new_integer(int64_t i); */ SERD_API SerdNode -serd_node_new_blob(const void* SERD_NONNULL buf, size_t size, bool wrap_lines); +serd_new_blob(const void* SERD_NONNULL buf, size_t size, bool wrap_lines); /** Make a deep copy of `node`. @@ -88,7 +88,7 @@ serd_env_set_base_uri(SerdEnv* env, const SerdNode* uri) // Resolve base URI and create a new node and URI for it SerdURIView base_uri; SerdNode base_uri_node = - serd_node_new_uri_from_node(uri, &env->base_uri, &base_uri); + serd_new_uri_from_node(uri, &env->base_uri, &base_uri); // Replace the current base URI serd_node_free(&env->base_uri_node); @@ -145,7 +145,7 @@ serd_env_set_prefix(SerdEnv* env, const SerdNode* name, const SerdNode* uri) // Resolve relative URI and create a new node and URI for it SerdURIView abs_uri; SerdNode abs_uri_node = - serd_node_new_uri_from_node(uri, &env->base_uri, &abs_uri); + serd_new_uri_from_node(uri, &env->base_uri, &abs_uri); // Set prefix to resolved (absolute) URI serd_env_add(env, name, &abs_uri_node); @@ -219,7 +219,7 @@ serd_env_expand_node(const SerdEnv* env, const SerdNode* node) break; case SERD_URI: { SerdURIView ignored; - return serd_node_new_uri_from_node(node, &env->base_uri, &ignored); + return serd_new_uri_from_node(node, &env->base_uri, &ignored); } case SERD_CURIE: { SerdStringView prefix; @@ -115,28 +115,28 @@ string_sink(const void* buf, size_t len, void* stream) } SerdNode -serd_node_new_uri_from_node(const SerdNode* uri_node, - const SerdURIView* base, - SerdURIView* out) +serd_new_uri_from_node(const SerdNode* uri_node, + const SerdURIView* base, + SerdURIView* out) { return (uri_node->type == SERD_URI && uri_node->buf) - ? serd_node_new_uri_from_string(uri_node->buf, base, out) + ? serd_new_uri_from_string(uri_node->buf, base, out) : SERD_NODE_NULL; } SerdNode -serd_node_new_uri_from_string(const char* str, - const SerdURIView* base, - SerdURIView* out) +serd_new_uri_from_string(const char* str, + const SerdURIView* base, + SerdURIView* out) { if (!str || str[0] == '\0') { // Empty URI => Base URI, or nothing if no base is given - return base ? serd_node_new_uri(base, NULL, out) : SERD_NODE_NULL; + return base ? serd_new_uri(base, NULL, out) : SERD_NODE_NULL; } SerdURIView uri; serd_uri_parse(str, &uri); - return serd_node_new_uri(&uri, base, out); // Resolve/Serialise + return serd_new_uri(&uri, base, out); // Resolve/Serialise } static inline bool @@ -176,7 +176,7 @@ is_uri_path_char(const char c) } SerdNode -serd_node_new_file_uri(const char* path, const char* hostname, SerdURIView* out) +serd_new_file_uri(const char* path, const char* hostname, SerdURIView* out) { const size_t path_len = strlen(path); const size_t hostname_len = hostname ? strlen(hostname) : 0; @@ -224,9 +224,7 @@ serd_node_new_file_uri(const char* path, const char* hostname, SerdURIView* out) } SerdNode -serd_node_new_uri(const SerdURIView* uri, - const SerdURIView* base, - SerdURIView* out) +serd_new_uri(const SerdURIView* uri, const SerdURIView* base, SerdURIView* out) { SerdURIView abs_uri = *uri; if (base) { @@ -250,10 +248,10 @@ serd_node_new_uri(const SerdURIView* uri, } SerdNode -serd_node_new_relative_uri(const SerdURIView* uri, - const SerdURIView* base, - const SerdURIView* root, - SerdURIView* out) +serd_new_relative_uri(const SerdURIView* uri, + const SerdURIView* base, + const SerdURIView* root, + SerdURIView* out) { const size_t uri_len = serd_uri_string_length(uri); const size_t base_len = serd_uri_string_length(base); @@ -281,7 +279,7 @@ serd_digits(double abs) } SerdNode -serd_node_new_decimal(double d, unsigned frac_digits) +serd_new_decimal(double d, unsigned frac_digits) { if (isnan(d) || isinf(d)) { return SERD_NODE_NULL; @@ -336,7 +334,7 @@ serd_node_new_decimal(double d, unsigned frac_digits) } SerdNode -serd_node_new_integer(int64_t i) +serd_new_integer(int64_t i) { uint64_t abs_i = (i < 0) ? -i : i; const unsigned digits = serd_digits((double)abs_i); @@ -361,7 +359,7 @@ serd_node_new_integer(int64_t i) } SerdNode -serd_node_new_blob(const void* buf, size_t size, bool wrap_lines) +serd_new_blob(const void* buf, size_t size, bool wrap_lines) { const size_t len = serd_base64_get_length(size, wrap_lines); uint8_t* str = (uint8_t*)calloc(len + 2, 1); diff --git a/src/serdi.c b/src/serdi.c index 68b1a497..f075ce13 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -311,9 +311,9 @@ main(int argc, char** argv) SerdURIView base_uri = SERD_URI_NULL; SerdNode base = SERD_NODE_NULL; if (a < argc) { // Base URI given on command line - base = serd_node_new_uri_from_string((const char*)argv[a], NULL, &base_uri); + base = serd_new_uri_from_string((const char*)argv[a], NULL, &base_uri); } else if (from_file && in_fd != stdin) { // Use input file URI - base = serd_node_new_file_uri(input, NULL, &base_uri); + base = serd_new_file_uri(input, NULL, &base_uri); } FILE* const out_fd = stdout; diff --git a/test/test_node.c b/test/test_node.c index ac0a02ae..52a98740 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -91,7 +91,7 @@ test_double_to_node(void) NULL}; for (size_t i = 0; i < sizeof(dbl_test_nums) / sizeof(double); ++i) { - SerdNode node = serd_node_new_decimal(dbl_test_nums[i], 8); + SerdNode node = serd_new_decimal(dbl_test_nums[i], 8); const bool pass = (node.buf && dbl_test_strs[i]) ? !strcmp(node.buf, dbl_test_strs[i]) : (node.buf == dbl_test_strs[i]); @@ -111,7 +111,7 @@ test_integer_to_node(void) "0", "0", "-23", "23", "-12340", "1000", "-1000"}; for (size_t i = 0; i < sizeof(int_test_nums) / sizeof(double); ++i) { - SerdNode node = serd_node_new_integer(int_test_nums[i]); + SerdNode node = serd_new_integer(int_test_nums[i]); assert(!strcmp(node.buf, int_test_strs[i])); assert(node.n_bytes == strlen(node.buf)); serd_node_free(&node); @@ -127,7 +127,7 @@ test_blob_to_node(void) data[i] = (uint8_t)((size + i) % 256); } - SerdNode blob = serd_node_new_blob(data, size, size % 5); + SerdNode blob = serd_new_blob(data, size, size % 5); assert(blob.n_bytes == strlen(blob.buf)); diff --git a/test/test_uri.c b/test/test_uri.c index e6933759..8f3b559b 100644 --- a/test/test_uri.c +++ b/test/test_uri.c @@ -32,7 +32,7 @@ test_file_uri(const char* hostname, expected_path = path; } - SerdNode node = serd_node_new_file_uri(path, hostname, 0); + SerdNode node = serd_new_file_uri(path, hostname, 0); char* out_hostname = NULL; char* out_path = serd_file_uri_parse(node.buf, &out_hostname); assert(!strcmp(node.buf, expected_uri)); @@ -66,14 +66,14 @@ test_uri_parsing(void) static void test_uri_from_string(void) { - SerdNode nonsense = serd_node_new_uri_from_string(NULL, NULL, NULL); + SerdNode nonsense = serd_new_uri_from_string(NULL, NULL, NULL); assert(nonsense.type == SERD_NOTHING); SerdURIView base_uri; SerdNode base = - serd_node_new_uri_from_string("http://example.org/", NULL, &base_uri); - SerdNode nil = serd_node_new_uri_from_string(NULL, &base_uri, NULL); - SerdNode nil2 = serd_node_new_uri_from_string("", &base_uri, NULL); + serd_new_uri_from_string("http://example.org/", NULL, &base_uri); + SerdNode nil = serd_new_uri_from_string(NULL, &base_uri, NULL); + SerdNode nil2 = serd_new_uri_from_string("", &base_uri, NULL); assert(nil.type == SERD_URI); assert(!strcmp(nil.buf, base.buf)); assert(nil2.type == SERD_URI); @@ -89,29 +89,27 @@ test_relative_uri(void) { SerdURIView base_uri; SerdNode base = - serd_node_new_uri_from_string("http://example.org/", NULL, &base_uri); + serd_new_uri_from_string("http://example.org/", NULL, &base_uri); SerdNode abs = serd_node_from_string(SERD_URI, "http://example.org/foo/bar"); SerdURIView abs_uri; serd_uri_parse(abs.buf, &abs_uri); SerdURIView rel_uri; - SerdNode rel = - serd_node_new_relative_uri(&abs_uri, &base_uri, NULL, &rel_uri); + SerdNode rel = serd_new_relative_uri(&abs_uri, &base_uri, NULL, &rel_uri); assert(!strcmp(rel.buf, "/foo/bar")); - SerdNode up = serd_node_new_relative_uri(&base_uri, &abs_uri, NULL, NULL); + SerdNode up = serd_new_relative_uri(&base_uri, &abs_uri, NULL, NULL); assert(!strcmp(up.buf, "../")); - SerdNode noup = - serd_node_new_relative_uri(&base_uri, &abs_uri, &abs_uri, NULL); + SerdNode noup = serd_new_relative_uri(&base_uri, &abs_uri, &abs_uri, NULL); assert(!strcmp(noup.buf, "http://example.org/")); SerdNode x = serd_node_from_string(SERD_URI, "http://example.org/foo/x"); SerdURIView x_uri; serd_uri_parse(x.buf, &x_uri); - SerdNode x_rel = serd_node_new_relative_uri(&x_uri, &abs_uri, &abs_uri, NULL); + SerdNode x_rel = serd_new_relative_uri(&x_uri, &abs_uri, &abs_uri, NULL); assert(!strcmp(x_rel.buf, "x")); serd_node_free(&x_rel); |