On 8 Jun 2013, at 23:06, Luboš Doležel <[email protected]> wrote:

> Hi,
> 
> GNUstep's NSString currently lacks 
> getBytes:maxLength:usedLength:encoding:options:range:remainingRange:
> 
> (added in OS X 10.5).
> 
> I wanted to implement this function, but GSFromUnicode()'s behavior is not 
> the best fit for this method:
> 
> 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.

> 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.

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).
_______________________________________________
Gnustep-dev mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to