[GRASS-dev] G_is_double()

Martin Landa landa.martin at gmail.com
Wed Nov 28 06:12:07 EST 2007


Glynn,

2007/11/25, Glynn Clements <glynn at gclements.plus.com>:

> > I would like to add to the GIS library (strings.c) new fns
> > G_is_double(char *str) and G_is_int(char *str). Any objections?
>
> With what definition? E.g. does G_is_double() recognise numbers
> without a point? Does it use the locale's decimal separator or always
> a dot? Does G_is_int() recognise octal/hex? What about a leading "+"
> sign?
>
> Personally, I suggest leaving this to the modules. Otherwise,
> whichever syntax you choose, code well tend to use the library
> functions regardless of whether their syntax is appropriate for the
> specific purpose.

hm, I was thinking simply about

int G_is_double(char *str)
{
    char *tail;

    if (strtod (str, &tail),
	tail == str || *tail != '\0') {
	/* doesn't look like a number,
	   or has extra characters after what looks to be a number */
	return 0;
    }

    return 1;
}

int G_is_int(char *str, int base)
{
    char *tail;

    if (strtol (str, &tail, base),
	tail == str || *tail != '\0') {
	/* doesn't look like a number,
	   or has extra characters after what looks to be a number */
	return 0;
    }

    return 1;
}

Maybe doesn't make sense so much.

Martin

-- 
Martin Landa <landa.martin at gmail.com> * http://gama.fsv.cvut.cz/~landa *


More information about the grass-dev mailing list