On Mon, 10 Jun 2013 07:58:29 +0100, Richard Frith-Macdonald wrote:
1) it fails if the output buffer is too small - we don't want that
in this case
Well, that depends on what arguments you pass to it ... if you
provide it with a zone in which to allocate memory, it will allocate
memory to make a bigger output buffer if necesary.
Not quite. The caller of getBytes supplies his own buffer.
Should the buffer not be sufficient and GSFromUnicode() allocates own
memory, I'd then have trouble finding out how many bytes to copy to
caller's buffer *without* splitting an UTF-8 character in the middle
(for example).
The way I understand it, -getBytes should convert as many *complete*
characters as possible.
2) it doesn't tell you how many input characters were converted
(which is understandable because of 1)
So I decided to use iconv() directly, which has a pitfall. I'd need
to access static members (EntrySupported) of Unicode.m to know the
iconv encoding's name etc. So I guess the iconv-related code (as
attached) should be moved into Unicode.m.
The problem with using iconv is that on most (all?) platforms, it
doesn't support all the character sets. That's mostly why the
GSFromUnicode() function exists ... to handle the cases that iconv
can't handle directly.
I see. I thought iconv supports all thinkable character sets - at least
on Linux.
It seems to me it would be quite simple to modify GSFromUnicode() to
do what you want ... you'd need to change the source length argument
to be a pointer, so you could pass back the number of bytes actually
converted (which would mean a trivial change everywhere the function
is called of course).
I will (as has been suggested) add a second GS*() function that has
this pointer and doesn't fail if the output buffer becomes full.
Then I'll rewrite GSFromUnicode() to call this function and fail if
output buffer is full and cannot be grown.
--
Luboš Doležel
_______________________________________________
Gnustep-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnustep-dev