[RFC PATCH] Warn about commas in floating point values?

Dirk Hohndel dirk at hohndel.org
Thu Mar 7 11:29:18 PST 2013


Linus Torvalds <torvalds at linux-foundation.org> writes:

> It might be a good idea to warn if we see a comma when we expect a
> floating point value. We've had this locale issue several times. We
> had it in our own native format long ago, but more commonly in imports
> from other formats..
>
> We potentially might also want to *parse* such numbers, just to be
> even more permissive. If somebody writes "7,5kg", it's pretty obvious
> what it means, but right now we will parse it as 7.
>
> But that would be slightly more complicated to do, so here's a RFC
> patch for just warning first.
>
> Signed-off-by: LInus Torvalds <torvalds at linux-foundation.org>
> ---
>
> Tested by intentionally corrupting one of my dives, it warned
> properly. Of course, if you don't start subsurface from a terminal,
> you'll never see the stderr warnings, which is part of why I suspect
> we might just want to accept the European format..
>
> Comments?

One of the problems is that people normally don't get to see anything
that is printed to stdout or stderr. Certainly not on Windows (which
covers more than half our users). So if we do this, we should create a
GError instead.

But the more I think about it - as long as it is XML that we are parsing
(and not less-structured text files) the parsing of either comma or dot
shouldn't be THAT hard, should it?

Take your value, count the total number of dots and commas combined and
if it is one than assume that's a dot. If someone writes 3000kg as
3,000kg they get what they deserve...

Thoughts?

/D


More information about the subsurface mailing list