aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/serd/serd.h20
-rw-r--r--src/node.c53
-rw-r--r--src/nodes.c21
-rw-r--r--test/test_model.c8
-rw-r--r--test/test_node.c21
-rw-r--r--test/test_node_syntax.c24
-rw-r--r--test/test_nodes.c26
7 files changed, 50 insertions, 123 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 2300a1a4..49046054 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -938,8 +938,7 @@ serd_node_construct_float(size_t buf_size,
SerdWriteResult
serd_node_construct_integer(size_t buf_size,
void* SERD_NULLABLE buf,
- int64_t value,
- SerdStringView datatype);
+ int64_t value);
/**
Construct a canonical xsd:base64Binary literal.
@@ -951,8 +950,7 @@ SerdWriteResult
serd_node_construct_base64(size_t buf_size,
void* SERD_NULLABLE buf,
size_t value_size,
- const void* SERD_NONNULL value,
- SerdStringView datatype);
+ const void* SERD_NONNULL value);
/**
@}
@@ -1133,9 +1131,7 @@ serd_new_float(SerdAllocator* SERD_NULLABLE allocator, float f);
*/
SERD_API
SerdNode* SERD_ALLOCATED
-serd_new_integer(SerdAllocator* SERD_NULLABLE allocator,
- int64_t i,
- SerdStringView datatype);
+serd_new_integer(SerdAllocator* SERD_NULLABLE allocator, int64_t i);
/**
Create a new canonical xsd:base64Binary literal.
@@ -1150,8 +1146,7 @@ SERD_API
SerdNode* SERD_ALLOCATED
serd_new_base64(SerdAllocator* SERD_NULLABLE allocator,
const void* SERD_NONNULL buf,
- size_t size,
- SerdStringView datatype);
+ size_t size);
/**
@}
@@ -1478,9 +1473,7 @@ serd_nodes_float(SerdNodes* SERD_NONNULL nodes, float value);
*/
SERD_API
const SerdNode* SERD_ALLOCATED
-serd_nodes_integer(SerdNodes* SERD_NONNULL nodes,
- int64_t value,
- SerdStringView datatype);
+serd_nodes_integer(SerdNodes* SERD_NONNULL nodes, int64_t value);
/**
Make a canonical xsd:base64Binary node.
@@ -1492,8 +1485,7 @@ SERD_API
const SerdNode* SERD_ALLOCATED
serd_nodes_base64(SerdNodes* SERD_NONNULL nodes,
const void* SERD_NONNULL value,
- size_t value_size,
- SerdStringView datatype);
+ size_t value_size);
/**
Make a blank node.
diff --git a/src/node.c b/src/node.c
index 0436c4fb..2d92e07d 100644
--- a/src/node.c
+++ b/src/node.c
@@ -350,45 +350,37 @@ serd_node_construct_float(const size_t buf_size,
}
SerdWriteResult
-serd_node_construct_integer(const size_t buf_size,
- void* const buf,
- const int64_t value,
- const SerdStringView datatype)
+serd_node_construct_integer(const size_t buf_size,
+ void* const buf,
+ const int64_t value)
{
- if (datatype.len && !serd_uri_string_has_scheme(datatype.buf)) {
- return result(SERD_BAD_ARG, 0);
- }
-
char temp[24] = {0};
const ExessResult r = exess_write_long(value, sizeof(temp), temp);
MUST_SUCCEED(r.status); // The only error is buffer overrun
- return serd_node_construct_literal(
- buf_size,
- buf,
- SERD_SUBSTRING(temp, r.count),
- SERD_HAS_DATATYPE,
- datatype.len ? datatype : SERD_STRING(NS_XSD "integer"));
+ return serd_node_construct_literal(buf_size,
+ buf,
+ SERD_SUBSTRING(temp, r.count),
+ SERD_HAS_DATATYPE,
+ SERD_STRING(NS_XSD "integer"));
}
SerdWriteResult
-serd_node_construct_base64(const size_t buf_size,
- void* const buf,
- const size_t value_size,
- const void* const value,
- const SerdStringView datatype)
+serd_node_construct_base64(const size_t buf_size,
+ void* const buf,
+ const size_t value_size,
+ const void* const value)
{
static const SerdStringView xsd_base64Binary =
SERD_STRING(NS_XSD "base64Binary");
// Verify argument sanity
- if (!value || !value_size ||
- (datatype.len && !serd_uri_string_has_scheme(datatype.buf))) {
+ if (!value || !value_size) {
return result(SERD_BAD_ARG, 0);
}
// Determine the type to use (default to xsd:base64Binary)
- const SerdStringView type = datatype.len ? datatype : xsd_base64Binary;
+ const SerdStringView type = xsd_base64Binary;
const size_t type_length = serd_node_pad_length(type.len);
const size_t type_size = sizeof(SerdNode) + type_length;
@@ -856,15 +848,13 @@ serd_new_decimal(SerdAllocator* const allocator, const double d)
}
SerdNode*
-serd_new_integer(SerdAllocator* const allocator,
- const int64_t i,
- const SerdStringView datatype)
+serd_new_integer(SerdAllocator* const allocator, const int64_t i)
{
- SerdWriteResult r = serd_node_construct_integer(0, NULL, i, datatype);
+ SerdWriteResult r = serd_node_construct_integer(0, NULL, i);
SerdNode* const node = serd_node_try_malloc(allocator, r);
if (node) {
- r = serd_node_construct_integer(r.count, node, i, datatype);
+ r = serd_node_construct_integer(r.count, node, i);
MUST_SUCCEED(r.status);
assert(serd_node_length(node) == strlen(serd_node_string(node)));
serd_node_check_padding(node);
@@ -874,16 +864,13 @@ serd_new_integer(SerdAllocator* const allocator,
}
SerdNode*
-serd_new_base64(SerdAllocator* const allocator,
- const void* buf,
- size_t size,
- const SerdStringView datatype)
+serd_new_base64(SerdAllocator* const allocator, const void* buf, size_t size)
{
- SerdWriteResult r = serd_node_construct_base64(0, NULL, size, buf, datatype);
+ SerdWriteResult r = serd_node_construct_base64(0, NULL, size, buf);
SerdNode* const node = serd_node_try_malloc(allocator, r);
if (node) {
- r = serd_node_construct_base64(r.count, node, size, buf, datatype);
+ r = serd_node_construct_base64(r.count, node, size, buf);
MUST_SUCCEED(r.status);
assert(serd_node_length(node) == strlen(serd_node_string(node)));
serd_node_check_padding(node);
diff --git a/src/nodes.c b/src/nodes.c
index 09b63f2a..90dd4f2c 100644
--- a/src/nodes.c
+++ b/src/nodes.c
@@ -451,23 +451,18 @@ serd_nodes_float(SerdNodes* const nodes, const float value)
}
const SerdNode*
-serd_nodes_integer(SerdNodes* const nodes,
- const int64_t value,
- const SerdStringView datatype)
+serd_nodes_integer(SerdNodes* const nodes, const int64_t value)
{
StaticNode key = empty_static_node;
return try_intern(
- nodes,
- serd_node_construct_integer(sizeof(key), &key, value, datatype),
- &key.node);
+ nodes, serd_node_construct_integer(sizeof(key), &key, value), &key.node);
}
const SerdNode*
-serd_nodes_base64(SerdNodes* const nodes,
- const void* const value,
- const size_t value_size,
- const SerdStringView datatype)
+serd_nodes_base64(SerdNodes* const nodes,
+ const void* const value,
+ const size_t value_size)
{
assert(nodes);
assert(value);
@@ -482,14 +477,12 @@ serd_nodes_base64(SerdNodes* const nodes,
like a Real Database(TM) would largely avoid this problem. */
// Determine how much space the node needs
- SerdWriteResult r =
- serd_node_construct_base64(0, NULL, value_size, value, datatype);
+ SerdWriteResult r = serd_node_construct_base64(0, NULL, value_size, value);
// Allocate a new entry to and construct the node into it
NodesEntry* const entry = new_entry(nodes->allocator, r.count);
if (entry) {
- r = serd_node_construct_base64(
- r.count, &entry->node, value_size, value, datatype);
+ r = serd_node_construct_base64(r.count, &entry->node, value_size, value);
assert(!r.status);
(void)r;
diff --git a/test/test_model.c b/test/test_model.c
index 827bd638..59fbbe2a 100644
--- a/test/test_model.c
+++ b/test/test_model.c
@@ -1300,9 +1300,9 @@ test_write_error_in_list_subject(SerdWorld* world, const unsigned n_quads)
const SerdNode* o = serd_nodes_uri(nodes, SERD_STRING("urn:o"));
const SerdNode* l1 = serd_nodes_blank(nodes, SERD_STRING("l1"));
- const SerdNode* one = serd_nodes_integer(nodes, 1, SERD_EMPTY_STRING());
+ const SerdNode* one = serd_nodes_integer(nodes, 1);
const SerdNode* l2 = serd_nodes_blank(nodes, SERD_STRING("l2"));
- const SerdNode* two = serd_nodes_integer(nodes, 2, SERD_EMPTY_STRING());
+ const SerdNode* two = serd_nodes_integer(nodes, 2);
const SerdNode* rdf_first = serd_nodes_uri(nodes, SERD_STRING(RDF_FIRST));
const SerdNode* rdf_rest = serd_nodes_uri(nodes, SERD_STRING(RDF_REST));
@@ -1356,9 +1356,9 @@ test_write_error_in_list_object(SerdWorld* world, const unsigned n_quads)
const SerdNode* p = serd_nodes_uri(nodes, SERD_STRING("urn:p"));
const SerdNode* l1 = serd_nodes_blank(nodes, SERD_STRING("l1"));
- const SerdNode* one = serd_nodes_integer(nodes, 1, SERD_EMPTY_STRING());
+ const SerdNode* one = serd_nodes_integer(nodes, 1);
const SerdNode* l2 = serd_nodes_blank(nodes, SERD_STRING("l2"));
- const SerdNode* two = serd_nodes_integer(nodes, 2, SERD_EMPTY_STRING());
+ const SerdNode* two = serd_nodes_integer(nodes, 2);
const SerdNode* rdf_first = serd_nodes_uri(nodes, SERD_STRING(RDF_FIRST));
const SerdNode* rdf_rest = serd_nodes_uri(nodes, SERD_STRING(RDF_REST));
diff --git a/test/test_node.c b/test/test_node.c
index 5c053294..c1d39053 100644
--- a/test/test_node.c
+++ b/test/test_node.c
@@ -207,8 +207,7 @@ test_get_double(void)
assert(isnan(serd_get_double(invalid)));
serd_node_free(NULL, invalid);
- SerdNode* const base64 =
- serd_new_base64(NULL, blob, sizeof(blob), SERD_EMPTY_STRING());
+ SerdNode* const base64 = serd_new_base64(NULL, blob, sizeof(blob));
assert(isnan(serd_get_double(base64)));
serd_node_free(NULL, base64);
@@ -288,15 +287,12 @@ test_get_float(void)
static void
test_integer(void)
{
- assert(!serd_new_integer(NULL, 42, SERD_STRING("notauri")));
-
const int64_t test_values[] = {0, -0, -23, 23, -12340, 1000, -1000};
const char* test_strings[] = {
"0", "0", "-23", "23", "-12340", "1000", "-1000"};
for (size_t i = 0; i < sizeof(test_values) / sizeof(double); ++i) {
- SerdNode* node =
- serd_new_integer(NULL, test_values[i], SERD_EMPTY_STRING());
+ SerdNode* node = serd_new_integer(NULL, 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);
@@ -341,8 +337,7 @@ test_get_integer(void)
static void
test_base64(void)
{
- assert(!serd_new_base64(NULL, &SERD_URI_NULL, 1, SERD_STRING("notauri")));
- assert(!serd_new_base64(NULL, &SERD_URI_NULL, 0, SERD_EMPTY_STRING()));
+ assert(!serd_new_base64(NULL, &SERD_URI_NULL, 0));
// Test valid base64 blobs with a range of sizes
for (size_t size = 1; size < 256; ++size) {
@@ -351,7 +346,7 @@ test_base64(void)
data[i] = (uint8_t)((size + i) % 256);
}
- SerdNode* blob = serd_new_base64(NULL, data, size, SERD_EMPTY_STRING());
+ SerdNode* blob = serd_new_base64(NULL, 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);
@@ -599,10 +594,8 @@ test_compare(void)
SerdNode* hello = serd_new_string(NULL, SERD_STRING("Hello"));
SerdNode* universe = serd_new_string(NULL, SERD_STRING("Universe"));
- SerdNode* integer = serd_new_integer(NULL, 4, SERD_EMPTY_STRING());
- SerdNode* short_integer =
- serd_new_integer(NULL, 4, SERD_STRING(NS_XSD "short"));
- SerdNode* blank = serd_new_token(NULL, SERD_BLANK, SERD_STRING("b1"));
+ SerdNode* integer = serd_new_integer(NULL, 4);
+ SerdNode* blank = serd_new_token(NULL, SERD_BLANK, SERD_STRING("b1"));
SerdNode* uri = serd_new_uri(NULL, SERD_STRING("http://example.org/"));
@@ -627,12 +620,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_integer) < 0);
assert(serd_node_compare(aardvark, badger) < 0);
serd_node_free(NULL, uri);
serd_node_free(NULL, blank);
- serd_node_free(NULL, short_integer);
serd_node_free(NULL, integer);
serd_node_free(NULL, badger);
serd_node_free(NULL, aardvark);
diff --git a/test/test_node_syntax.c b/test/test_node_syntax.c
index 582ba8aa..09037363 100644
--- a/test/test_node_syntax.c
+++ b/test/test_node_syntax.c
@@ -92,9 +92,6 @@ test_common(SerdWorld* const world, const SerdSyntax syntax)
static const SerdStringView datatype =
SERD_STRING("http://example.org/Datatype");
- static const SerdStringView num_type =
- SERD_STRING("http://example.org/Decimal");
-
assert(check(
world, syntax, serd_new_string(NULL, SERD_STRING("node")), "\"node\""));
@@ -141,15 +138,10 @@ test_common(SerdWorld* const world, const SerdSyntax syntax)
serd_new_float(NULL, 1.25),
"\"1.25E0\"^^<http://www.w3.org/2001/XMLSchema#float>"));
- assert(check(world,
- syntax,
- serd_new_integer(NULL, 1234, num_type),
- "\"1234\"^^<http://example.org/Decimal>"));
-
assert(
check(world,
syntax,
- serd_new_base64(NULL, data, sizeof(data), SERD_EMPTY_STRING()),
+ serd_new_base64(NULL, data, sizeof(data)),
"\"BAAAAAIAAAA=\"^^<http://www.w3.org/2001/XMLSchema#base64Binary>"));
}
@@ -189,7 +181,7 @@ test_ntriples(void)
assert(check(world,
SERD_NTRIPLES,
- serd_new_integer(NULL, 1234, SERD_EMPTY_STRING()),
+ serd_new_integer(NULL, 1234),
"\"1234\"^^<http://www.w3.org/2001/XMLSchema#integer>"));
assert(check(world,
@@ -208,9 +200,6 @@ test_ntriples(void)
static void
test_turtle(void)
{
- static const SerdStringView xsd_integer =
- SERD_STRING("http://www.w3.org/2001/XMLSchema#integer");
-
SerdWorld* const world = serd_world_new(NULL);
test_common(world, SERD_TURTLE);
@@ -221,14 +210,7 @@ test_turtle(void)
"<rel/uri>");
assert(check(world, SERD_TURTLE, serd_new_decimal(NULL, 1.25), "1.25"));
-
- assert(check(world,
- SERD_TURTLE,
- serd_new_integer(NULL, 1234, SERD_EMPTY_STRING()),
- "1234"));
-
- assert(check(
- world, SERD_TURTLE, serd_new_integer(NULL, 1234, xsd_integer), "1234"));
+ assert(check(world, SERD_TURTLE, serd_new_integer(NULL, 1234), "1234"));
assert(check(world, SERD_TURTLE, serd_new_boolean(NULL, true), "true"));
assert(check(world, SERD_TURTLE, serd_new_boolean(NULL, false), "false"));
diff --git a/test/test_nodes.c b/test/test_nodes.c
index 2cdfbc3c..19dcee01 100644
--- a/test/test_nodes.c
+++ b/test/test_nodes.c
@@ -321,11 +321,8 @@ test_integer(void)
SerdNodes* const nodes = serd_nodes_new(allocator);
- const SerdNode* const a =
- serd_nodes_integer(nodes, -1234567890, SERD_EMPTY_STRING());
-
- const SerdNode* const b =
- serd_nodes_integer(nodes, -1234567890, SERD_EMPTY_STRING());
+ const SerdNode* const a = serd_nodes_integer(nodes, -1234567890);
+ const SerdNode* const b = serd_nodes_integer(nodes, -1234567890);
assert(a == b);
assert(!strcmp(serd_node_string(a), "-1234567890"));
@@ -348,11 +345,8 @@ test_base64(void)
SerdNodes* const nodes = serd_nodes_new(allocator);
- const SerdNode* const a =
- serd_nodes_base64(nodes, &data, sizeof(data), SERD_EMPTY_STRING());
-
- const SerdNode* const b =
- serd_nodes_base64(nodes, &data, sizeof(data), SERD_EMPTY_STRING());
+ const SerdNode* const a = serd_nodes_base64(nodes, &data, sizeof(data));
+ const SerdNode* const b = serd_nodes_base64(nodes, &data, sizeof(data));
assert(a == b);
assert(!strcmp(serd_node_string(a), "Zm9vYmFy"));
@@ -363,18 +357,6 @@ test_base64(void)
assert(default_datatype);
assert(!strcmp(serd_node_string(default_datatype), NS_XSD "base64Binary"));
- const SerdStringView user_datatype =
- SERD_STRING("http://example.org/UserDatatype");
-
- const SerdNode* const custom =
- serd_nodes_base64(nodes, &data, sizeof(data), user_datatype);
- assert(custom);
- assert(!strcmp(serd_node_string(custom), "Zm9vYmFy"));
-
- const SerdNode* const custom_datatype = serd_node_datatype(custom);
- assert(custom_datatype);
- assert(!strcmp(serd_node_string(custom_datatype), user_datatype.buf));
-
serd_nodes_free(nodes);
}