From 3bf35cb9e72709fb417cff0d5a2dc9b681e5ecb1 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 6 Oct 2019 20:59:12 +0200 Subject: Add serd_new_float() and serd_new_double() --- src/node.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/node.c') diff --git a/src/node.c b/src/node.c index 0d6eb19a..db183fc0 100644 --- a/src/node.c +++ b/src/node.c @@ -507,6 +507,32 @@ serd_new_custom_literal(const void* const user_data, return node; } +SerdNode* +serd_new_double(const double d) +{ + char buf[EXESS_MAX_DOUBLE_LENGTH + 1] = {0}; + + const ExessResult r = exess_write_double(d, sizeof(buf), buf); + + return r.status + ? NULL + : serd_new_typed_literal(SERD_STRING_VIEW(buf, r.count), + SERD_STATIC_STRING(EXESS_XSD_URI "double")); +} + +SerdNode* +serd_new_float(const float f) +{ + char buf[EXESS_MAX_FLOAT_LENGTH + 1] = {0}; + + const ExessResult r = exess_write_float(f, sizeof(buf), buf); + + return r.status + ? NULL + : serd_new_typed_literal(SERD_STRING_VIEW(buf, r.count), + SERD_STATIC_STRING(EXESS_XSD_URI "float")); +} + static size_t write_variant_literal(const void* const user_data, const size_t buf_size, -- cgit v1.2.1