diff options
author | David Robillard <d@drobilla.net> | 2021-02-25 20:08:20 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-08 23:23:05 -0500 |
commit | 01a76c7d703650df7f39d21c704f5b7c4f41ca14 (patch) | |
tree | 0d662aaceb9b6dee2cc2f566cd67aa20fa0939ca /include | |
parent | 3bf35cb9e72709fb417cff0d5a2dc9b681e5ecb1 (diff) | |
download | serd-01a76c7d703650df7f39d21c704f5b7c4f41ca14.tar.gz serd-01a76c7d703650df7f39d21c704f5b7c4f41ca14.tar.bz2 serd-01a76c7d703650df7f39d21c704f5b7c4f41ca14.zip |
Add numeric node construction and access API
Diffstat (limited to 'include')
-rw-r--r-- | include/serd/serd.h | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h index e1a28fdf..2f349e90 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -315,18 +315,6 @@ size_t serd_strlen(const char* SERD_NONNULL str, SerdNodeFlags* SERD_NULLABLE flags); /** - Parse a string to a double. - - The API of this function is identical to the standard C strtod function, - except this function is locale-independent and always matches the lexical - format used in the Turtle grammar (the decimal point is always "."). -*/ -SERD_API -double -serd_strtod(const char* SERD_NONNULL str, - const char* SERD_NONNULL* SERD_NULLABLE endptr); - -/** Decode a base64 string. This function can be used to deserialise a blob node created with @@ -649,7 +637,7 @@ serd_new_double(double d); Uses identical formatting to serd_new_double(), except with at most 9 significant digits (under 14 characters total). - @param f Float value to serialise. + @param f Float value of literal. @return A literal node with datatype xsd:float. */ SERD_API @@ -657,9 +645,9 @@ SerdNode* SERD_ALLOCATED serd_new_float(float f); /** - Create a new node by serialising `i` into an xsd:integer string + Create a new node by writing `i` as an xsd:integer string. - @param i Integer value to serialise. + @param i Integer value of literal. @param datatype Datatype of node, or NULL for xsd:integer. */ SERD_API @@ -682,6 +670,51 @@ serd_new_blob(const void* SERD_NONNULL buf, size_t size, const SerdNode* SERD_NULLABLE datatype); +/** + Return the value of `node` as a boolean. + + This will work for booleans, and numbers of any datatype if they are 0 or + 1. + + @return The value of `node` as a `bool`, or `false` on error. +*/ +SERD_API +bool +serd_get_boolean(const SerdNode* SERD_NONNULL node); + +/** + Return the value of `node` as a double. + + This will coerce numbers of any datatype to double, if the value fits. + + @return The value of `node` as a `double`, or NaN on error. +*/ +SERD_API +double +serd_get_double(const SerdNode* SERD_NONNULL node); + +/** + Return the value of `node` as a float. + + This will coerce numbers of any datatype to float, if the value fits. + + @return The value of `node` as a `float`, or NaN on error. +*/ +SERD_API +float +serd_get_float(const SerdNode* SERD_NONNULL node); + +/** + Return the value of `node` as a long (signed 64-bit integer). + + This will coerce numbers of any datatype to long, if the value fits. + + @return The value of `node` as a `int64_t`, or 0 on error. +*/ +SERD_API +int64_t +serd_get_integer(const SerdNode* SERD_NONNULL node); + /// Return a deep copy of `node` SERD_API SerdNode* SERD_ALLOCATED |