From 2469c739d87d6a2bb0c9b9c1e2b2c69b0e981b97 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 19 Dec 2011 02:59:31 +0000 Subject: Add serd_strtod(), serd_node_new_decimal(), and serd_node_new_integer() for locale-independent numeric node parsing/serialising. git-svn-id: http://svn.drobilla.net/serd/trunk@260 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- serd/serd.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'serd/serd.h') diff --git a/serd/serd.h b/serd/serd.h index b20dacf2..eebfa113 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -266,6 +266,17 @@ SERD_API size_t serd_strlen(const uint8_t* str, size_t* n_bytes, SerdNodeFlags* 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* str, char** endptr); + /** @} @name URI @@ -379,6 +390,31 @@ SERD_API SerdNode serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out); +/** + Create a new node by serialising @c d into an xsd:decimal string. + + The resulting node will always contain a `.', start with a digit, and end + with a digit (i.e. will have a leading and/or trailing `0' if necessary). + It will never be in scientific notation. A maximum of @c frac_digits digits + will be written after the decimal point, but trailing zeros will + automatically be omitted (except one if @c d is a round integer). + + Note that about 16 and 8 fractional digits are required to precisely + represent a double and float, respectively. + + @param frac_digits The maximum number of digits after the decimal place. +*/ +SERD_API +SerdNode +serd_node_new_decimal(double d, unsigned frac_digits); + +/** + Create a new node by serialising @c d into an xsd:integer string. +*/ +SERD_API +SerdNode +serd_node_new_integer(long i); + /** Free any data owned by @c node. -- cgit v1.2.1