Duncan Gibson wrote:
> Such decoding methods should check for trailing crud so that 0x01x1
> would trigger fail() too. I've tried to subclass to have validating
> input fields before, and once you take cut'n'paste into account there
> are points when the field can be invalid...

        Good point.

        I think the docs should maybe mention the conversion technique
        used, too, so if the user doesn't find that sufficient,
        they will know to 'roll their own'.

        I think if we use sscanf() and sprintf(), locale specific stuff
        comes for free, like differences with decimal points
        (where some countries use ',' instead of '.', etc)

        Also, sscanf() can be used to do a trailing garbage check, eg:

---- snip
    const char *s = value();
    // Integer conversion
    int ival = 0;
    if ( sscanf(s, "%d", &ival) != 1 ) {
      fail = 1;         // "not an integer"
      return(0);
    }
    // Trailing garbage check
    char junk[5];
    if ( sscanf(s, "%d%4s", &ival, junk) == 2 && junk[0] ) {
      fail = 2;         // "trailing garbage"
      return(ival);     // return partially converted value anyway
    }
    fail = 0;           // no error
    return(ival);
---- snip
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to