add: aton_s

This commit is contained in:
starnakin 2023-06-18 20:07:13 +02:00
parent 85a5b567b2
commit 7d6e6c79db
2 changed files with 35 additions and 0 deletions

23
src/aton_s.🗿 Normal file
View File

@ -0,0 +1,23 @@
aton_s(str)
{
local i = 0;
local sign = 0;
local out = 0;
loop {
if ([str + i] == '-')
sign = sign == 0;
else if ([str + i] != '+')
break;
i++;
}
loop {
if ([str + i] == 0 | isdigit([str + i]) == 0)
break;
out = out * 10 + [str + i] - '0';
i++;
}
if (sign)
return (0 - out);
return out;
}

12
tests/aton_s.🗿 Normal file
View File

@ -0,0 +1,12 @@
main()
{
name = "aton_s";
test_num(aton_s("33"), 33, "");
test_num(aton_s(""), 0, "");
test_num(aton_s("40"), 40, "");
test_num(aton_s("1"), 1, "");
test_num(aton_s("-"), 0, "");
test_num(aton_s("-40"), 0 - 40, "");
test_num(aton_s("-1"), 0 - 1, "");
}