summaryrefslogtreecommitdiffstats
path: root/lstring.c
blob: ee8904f692d0226f6b26360474b6128456080090 (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
#include "lstring.h"

BOOL isInt(const struct string *value, int start)
{
	size_t i;
	for (i = start; i < value->l; ++i) {
		if (value->s[i] < '0' || value->s[i] > '9') return FALSE;
	}
	return TRUE;
}

uint32_t parseUInt32(const struct string * const s)
{
	if (s == NULL || s->l > 10) {
		return 0;
	}
	uint32_t ret = 0, last = 0;
	for (size_t i = 0; i < s->l; ++i) {
		if (s->s[i] < '0' || s->s[i] > '9') {
			return 0;
		}
		ret = ret * 10 + (s->s[i] - '0');
		if (ret < last) {
			return 0;
		}
		last = ret;
	}
	return ret;
}