50 lines
850 B
C
50 lines
850 B
C
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
|
|
#include "hydroforth/number.h"
|
|
|
|
bool hydroforth__number__is_digit(char c)
|
|
{
|
|
return '0' <= c && c <= '9';
|
|
}
|
|
|
|
bool hydroforth__number__parse_number(const char *const start, unsigned char len, int *const val)
|
|
{
|
|
int num;
|
|
if (start[0] == '0')
|
|
{
|
|
if (len > 1)
|
|
{
|
|
switch (start[1])
|
|
{
|
|
case 'X':
|
|
case 'x':
|
|
return false;
|
|
|
|
default:
|
|
return hydroforth__number__parse_number(start + 1, len - 1, val);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
*val = 0;
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int n = start[0] - '0';
|
|
for (unsigned char i = 1; i < len; i++)
|
|
{
|
|
n *= 10;
|
|
n += start[i] - '0';
|
|
}
|
|
*val = n;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
bool hydroforth__number__parse_number_with_sign(const char *const start, unsigned char len, int *const val)
|
|
{
|
|
}
|