[Qt-interest] Does Qt support Unicode 5.1?

Shaun Cummins cumminss at gmail.com
Fri Mar 6 08:56:25 CET 2009


"The only acceptable behavior when passed a character outside the valid
Unicode range is to fail. There's no valid return value.

Since both functions return "ushort", there's no room for "invalid return
value". So the only alternatives are to throw an exception or abort the
program.

Or do like both solutions do: GIGO (garbage in, garbage out)"

Of course both functions give garbage out when given bad data. What I
meant was that the only way I could see that the two functions would
return different values is if bad data was given (with Qt giving pure
garbage and the other giving the portion of the value that would 'fit'
within the available range). For example, if the value 0x44444444 was
passed Qt's highSurrogate() function would return 0xe8d1 while the
other version would return 0xd8d1. Both are garbage of course. However
Qt's function would likely directly cause a formatting error due to
there not being a matching high surrogate value to the encoded low
surrogate value while the other would not cause an error (at least not
without additional error checking). In my opinion Qt's behavior is
more desirable since there should not be an attempt to fit bad data
within the valid range which can allow silent errors to occur.

So long as valid data is given to either function they will always
return the same, correct high surrogate values (and no matter what is
passed to the low surrogate function the return value would be the
same of course).



More information about the Qt-interest-old mailing list