diff options
author | David Robillard <d@drobilla.net> | 2019-10-06 20:59:12 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-08 23:23:05 -0500 |
commit | 3bf35cb9e72709fb417cff0d5a2dc9b681e5ecb1 (patch) | |
tree | 722bf1099a386a048ea0419ae1be720c8da31eb0 /src | |
parent | 8de05b1e2f7849e47c8ac82452a2e038664e510e (diff) | |
download | serd-3bf35cb9e72709fb417cff0d5a2dc9b681e5ecb1.tar.gz serd-3bf35cb9e72709fb417cff0d5a2dc9b681e5ecb1.tar.bz2 serd-3bf35cb9e72709fb417cff0d5a2dc9b681e5ecb1.zip |
Add serd_new_float() and serd_new_double()
Diffstat (limited to 'src')
-rw-r--r-- | src/node.c | 26 | ||||
-rw-r--r-- | src/static_nodes.h | 2 | ||||
-rw-r--r-- | src/string.c | 2 |
3 files changed, 30 insertions, 0 deletions
@@ -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, diff --git a/src/static_nodes.h b/src/static_nodes.h index 952c0634..adbb5849 100644 --- a/src/static_nodes.h +++ b/src/static_nodes.h @@ -34,6 +34,8 @@ typedef struct StaticNode { DEFINE_XSD_NODE(base64Binary) DEFINE_XSD_NODE(boolean) DEFINE_XSD_NODE(decimal) +DEFINE_XSD_NODE(double) +DEFINE_XSD_NODE(float) DEFINE_XSD_NODE(integer) #endif // SERD_STATIC_NODES_H diff --git a/src/string.c b/src/string.c index 00b1e91a..6e28778b 100644 --- a/src/string.c +++ b/src/string.c @@ -21,6 +21,8 @@ #include <assert.h> #include <math.h> +#include <stdbool.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> |