aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-01-02 22:52:39 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commitd76b4da8f420a320b830544288c555a284151773 (patch)
tree1dc784440d32338dfe20315274982e56bb4bfca5
parent828c1018f38bab9a930cecce64646366d051d39b (diff)
downloadserd-d76b4da8f420a320b830544288c555a284151773.tar.gz
serd-d76b4da8f420a320b830544288c555a284151773.tar.bz2
serd-d76b4da8f420a320b830544288c555a284151773.zip
Remove datatype arguments from integer and base64 constructors
-rw-r--r--include/serd/node.h8
-rw-r--r--src/node.c20
-rw-r--r--test/test_node.c21
3 files changed, 22 insertions, 27 deletions
diff --git a/include/serd/node.h b/include/serd/node.h
index f745af6d..b308a507 100644
--- a/include/serd/node.h
+++ b/include/serd/node.h
@@ -225,10 +225,9 @@ serd_new_float(float f);
xsd:integer.
@param i Integer value of literal.
- @param datatype Datatype of node, or NULL for xsd:integer.
*/
SERD_API SerdNode* ZIX_ALLOCATED
-serd_new_integer(int64_t i, const SerdNode* ZIX_NULLABLE datatype);
+serd_new_integer(int64_t i);
/**
Create a new canonical xsd:base64Binary literal.
@@ -238,12 +237,9 @@ serd_new_integer(int64_t i, const SerdNode* ZIX_NULLABLE datatype);
@param buf Raw binary data to encode in node.
@param size Size of `buf` in bytes.
- @param datatype Datatype of node, or null for xsd:base64Binary.
*/
SERD_API SerdNode* ZIX_ALLOCATED
-serd_new_base64(const void* ZIX_NONNULL buf,
- size_t size,
- const SerdNode* ZIX_NULLABLE datatype);
+serd_new_base64(const void* ZIX_NONNULL buf, size_t size);
/// Return a deep copy of `node`
SERD_API SerdNode* ZIX_ALLOCATED
diff --git a/src/node.c b/src/node.c
index 189b02d9..d34d4552 100644
--- a/src/node.c
+++ b/src/node.c
@@ -631,26 +631,28 @@ serd_new_decimal(const double d, const SerdNode* const datatype)
}
SerdNode*
-serd_new_integer(const int64_t i, const SerdNode* const datatype)
+serd_new_integer(const int64_t i)
{
// Use given datatype, or xsd:integer as a default if it is null
- const SerdNode* type = datatype ? datatype : &serd_xsd_integer.node;
- const size_t type_size = serd_node_total_size(type);
+ const SerdNode* datatype = &serd_xsd_integer.node;
+ const size_t datatype_size = serd_node_total_size(datatype);
// Measure integer string to know how much space the node will need
ExessResult r = exess_write_long(i, 0, NULL);
assert(!r.status);
// Allocate node with enough space for value and datatype URI
- SerdNode* const node = serd_node_malloc(
- serd_node_pad_length(r.count) + type_size, SERD_HAS_DATATYPE, SERD_LITERAL);
+ SerdNode* const node =
+ serd_node_malloc(serd_node_pad_length(r.count) + datatype_size,
+ SERD_HAS_DATATYPE,
+ SERD_LITERAL);
// Write string directly into node
r = exess_write_long(i, r.count + 1U, serd_node_buffer(node));
assert(!r.status);
node->length = r.count;
- memcpy(serd_node_meta(node), type, type_size);
+ memcpy(serd_node_meta(node), datatype, datatype_size);
serd_node_check_padding(node);
return node;
}
@@ -668,13 +670,13 @@ write_base64_literal(const void* const user_data,
}
SerdNode*
-serd_new_base64(const void* buf, size_t size, const SerdNode* datatype)
+serd_new_base64(const void* buf, size_t size)
{
const size_t len = exess_write_base64(size, buf, 0, NULL).count;
- const SerdNode* type = datatype ? datatype : &serd_xsd_base64Binary.node;
SerdConstBuffer blob = {buf, size};
- return serd_new_custom_literal(&blob, len, write_base64_literal, type);
+ return serd_new_custom_literal(
+ &blob, len, write_base64_literal, &serd_xsd_base64Binary.node);
}
SerdNodeType
diff --git a/test/test_node.c b/test/test_node.c
index 3db0a46f..7d37cfe5 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -197,7 +197,7 @@ test_get_double(void)
assert(isnan(serd_get_double(invalid)));
serd_node_free(invalid);
- SerdNode* const base64 = serd_new_base64(blob, sizeof(blob), NULL);
+ SerdNode* const base64 = serd_new_base64(blob, sizeof(blob));
assert(isnan(serd_get_double(base64)));
serd_node_free(base64);
@@ -280,7 +280,7 @@ test_integer(void)
"0", "0", "-23", "23", "-12340", "1000", "-1000"};
for (size_t i = 0; i < sizeof(test_values) / sizeof(double); ++i) {
- SerdNode* node = serd_new_integer(test_values[i], NULL);
+ SerdNode* node = serd_new_integer(test_values[i]);
const char* node_str = serd_node_string(node);
assert(!strcmp(node_str, test_strings[i]));
const size_t len = strlen(node_str);
@@ -325,7 +325,7 @@ test_get_integer(void)
static void
test_base64(void)
{
- assert(!serd_new_base64(&SERD_URI_NULL, 0, NULL));
+ assert(!serd_new_base64(&SERD_URI_NULL, 0));
// Test valid base64 blobs with a range of sizes
for (size_t size = 1; size < 256; ++size) {
@@ -334,7 +334,7 @@ test_base64(void)
data[i] = (uint8_t)((size + i) % 256);
}
- SerdNode* blob = serd_new_base64(data, size, NULL);
+ SerdNode* blob = serd_new_base64(data, size);
const char* blob_str = serd_node_string(blob);
const size_t max_size = serd_get_base64_size(blob);
uint8_t* out = (uint8_t*)calloc(1, max_size);
@@ -549,12 +549,11 @@ test_compare(void)
SerdNode* hallo =
serd_new_plain_literal(serd_string("Hallo"), serd_string("de"));
- SerdNode* hello = serd_new_string(serd_string("Hello"));
- SerdNode* universe = serd_new_string(serd_string("Universe"));
- SerdNode* integer = serd_new_integer(4, NULL);
- SerdNode* short_int = serd_new_integer(4, xsd_short);
- SerdNode* blank = serd_new_blank(serd_string("b1"));
- SerdNode* uri = serd_new_uri(serd_string("http://example.org/"));
+ SerdNode* hello = serd_new_string(serd_string("Hello"));
+ SerdNode* universe = serd_new_string(serd_string("Universe"));
+ SerdNode* integer = serd_new_integer(4);
+ SerdNode* blank = serd_new_blank(serd_string("b1"));
+ SerdNode* uri = serd_new_uri(serd_string("http://example.org/"));
SerdNode* aardvark = serd_new_typed_literal(
serd_string("alex"), serd_string("http://example.org/Aardvark"));
@@ -572,12 +571,10 @@ test_compare(void)
// If literal strings are the same, languages or datatypes are compared
assert(serd_node_compare(angst, angst_de) < 0);
assert(serd_node_compare(angst_de, angst_en) < 0);
- assert(serd_node_compare(integer, short_int) < 0);
assert(serd_node_compare(aardvark, badger) < 0);
serd_node_free(uri);
serd_node_free(blank);
- serd_node_free(short_int);
serd_node_free(integer);
serd_node_free(badger);
serd_node_free(aardvark);