summaryrefslogtreecommitdiffstats
path: root/libnumtext_remove_separators.c
blob: cbeb80a0ba11d5fdd4672ea6d515550fb1db04be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* See LICENSE file for copyright and license details. */
#include "common.h"


ssize_t
libnumtext_remove_separators(char *outbuf, size_t outbuf_size, const char *num, size_t num_len, enum libnumtext_language lang)
{
	char *p = outbuf;
	ssize_t len = 0;

	switch (lang) {

	case LIBNUMTEXT_SWEDISH:
		for (; num_len--; num++) {
			if (*num != ' ' && *num != '\'' && *num != '.') {
				if (IS_UNICODE_NBSP(num, num_len)) {
					num = &num[sizeof(UNICODE_NBSP) - 2];
					num_len -= sizeof(UNICODE_NBSP) - 2;
					continue;
				}
				if (outbuf_size) {
					*p++ = *num;
					outbuf_size--;
				}
				len += 1;
			}
		}
		return len;

	default:
		errno = EINVAL;
		return -1;
	}
}