I've managed to pin down the cause of #9655. However, in trying to solve
it I've run into what may be a problem with UT_UTF8String_sprintf().
The scenario is as follows:
When the user tries to close abi without saving their changes, we pop up
a message box to ask them if they want to save the document. This is
done by XAP_Frame::createMessageBox() which takes an XAP_String_id
and a variable number of arguments.
createMessageBox() fetches the string "Save changes to %s before
closing?" from the string set. This string is then used as the format
string for vsprintf() which uses the variable arguments to replace the
"%s" with the title of the document.
At the moment, we request the string from the string set to be in the
default locale encoding while the document title is in UTF-8. On a
Chinese installation of XP, that means that the final string is a mix of
GB2312 and UTF-8 encoded text. The resulting message box obviously
displays gibberish.
The big problem is that if we get the string from the string set in
UTF-8 instead of GB2312 then the call the vsprintf() causes an assert.
In fact, the Microsoft C library's implementation of vsprintf() handles
a UTF-8 format string disastrously. It treats every pair of bytes as a
wide character and then misses the terminating \0 and falls off the end
of the string.
I had thought that using UT_UTF8String_sprintf might work. However, that
just calls vsprintf() as well and so also asserts. Is this function meant
to be able to handle UTF-8 format strings?
It is possible to use wprintf() if I first convert the strings using
mbstowcs() and then convert back again afterwards. However, I'm not at
all sure that doing this is sensible and it's not convenient to do the
conversion for the variable arguments (also strings).
The only solution I can think of right now is to write (or find) an
implementation of sprintf() which can handle UTF-8 and add that to the
util module.
Can anyone see a less drastic way out of this mess?
Best wishes,
R.
Received on Fri Oct 21 15:09:40 2005
This archive was generated by hypermail 2.1.8 : Fri Oct 21 2005 - 15:09:41 CEST