aboutsummaryrefslogtreecommitdiffstats
path: root/serd
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-19 02:59:31 +0000
committerDavid Robillard <d@drobilla.net>2011-12-19 02:59:31 +0000
commit2469c739d87d6a2bb0c9b9c1e2b2c69b0e981b97 (patch)
treeac764f783837a0fe2e1ec56a439e3acb318dd918 /serd
parent085fe30c4c8dcdd2e2d38451813e0d7d5543acfc (diff)
downloadserd-2469c739d87d6a2bb0c9b9c1e2b2c69b0e981b97.tar.gz
serd-2469c739d87d6a2bb0c9b9c1e2b2c69b0e981b97.tar.bz2
serd-2469c739d87d6a2bb0c9b9c1e2b2c69b0e981b97.zip
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
Diffstat (limited to 'serd')
-rw-r--r--serd/serd.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h
index b20dacf2..eebfa113 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -267,6 +267,17 @@ 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
@{
@@ -380,6 +391,31 @@ 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.
Note that if @c node is itself dynamically allocated (which is not the case