summaryrefslogtreecommitdiffstats
path: root/libnumtext_num2text.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-09-02 22:17:14 +0200
committerMattias Andrée <maandree@kth.se>2021-09-02 22:28:08 +0200
commite4a1686d5ca41ad02672c6530588f94c34a1c678 (patch)
treecd143c5dcbc5b8182ce7df521bf48f4de2617628 /libnumtext_num2text.c
downloadlibnumtext-e4a1686d5ca41ad02672c6530588f94c34a1c678.tar.gz
libnumtext-e4a1686d5ca41ad02672c6530588f94c34a1c678.tar.bz2
libnumtext-e4a1686d5ca41ad02672c6530588f94c34a1c678.tar.xz
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libnumtext_num2text.c')
-rw-r--r--libnumtext_num2text.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/libnumtext_num2text.c b/libnumtext_num2text.c
new file mode 100644
index 0000000..09605a7
--- /dev/null
+++ b/libnumtext_num2text.c
@@ -0,0 +1,36 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+
+#define UNICODE_MINUS "−"
+
+
+ssize_t
+libnumtext_num2text(char outbuf[], size_t outbuf_size, const char *num, size_t num_len,
+ enum libnumtext_language lang, uint32_t flags, ...)
+{
+ size_t i;
+
+ i = 0;
+ if (i < num_len) {
+ if (num[i] == '+' || num[i] == '-')
+ i += 1;
+ else if (!strncmp(&num[0], UNICODE_MINUS, sizeof(UNICODE_MINUS) - 1))
+ i += sizeof(UNICODE_MINUS) - 1;
+ }
+ if (i == num_len)
+ goto einval;
+ for (; i < num_len; i++)
+ if (!isdigit(num[i]))
+ goto einval;
+
+ switch (lang) {
+
+ case LIBNUMTEXT_SWEDISH:
+ return libnumtext_num2text_swedish__(outbuf, outbuf_size, num, num_len, flags);
+
+ default:
+ einval:
+ errno = EINVAL;
+ return -1;
+ }
+}