Glynn,

2007/11/25, Glynn Clements <[EMAIL PROTECTED]>:

> > 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 <[EMAIL PROTECTED]> * http://gama.fsv.cvut.cz/~landa *
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to