|Subject:||Re: Implementing NSString getBytes|
|Date:||Sun, 9 Jun 2013 13:19:10 -0500|
I like the idea of adding this functionality. You actual implementation wont do as you already noticed. We also cannot use iconv() unconditionally. I remember back in time when I first added a call to iconv() to GNUstep we also had to introduce the configure checks for it. And of course provide a fall back implementation for that rare case where it isn't available. You should also have a second look at GSFromUnicode() to notice it is trying a much better job at providing a lossy conversion.
You already pointed out the difference that you need to the current implementation of GSFromUnicode(). You don't want your function to allocate extra memory, you need it to return the index up to which it was able to convert characters and you need a different return code that states whether any characters where converted. Although the last could possibly be determined by checking the returned index.
Now this sounds like a strict extension of GSFromUnicode() and I think that in the long run these two functions should share their implementation code. But we also need to make sure that GSFromUnicode() is rock solid and fast, maybe we first keep them separate.
Maybe it is best if you first write your new function by extracting all the code from GSFromUnicode() that doesn't handle memory management and add the different return values there. Next we could think about rewriting GSFromUnicode() on top of that. Adding the memory management and using some pointer arithmetic. And then we test whether this is fast enough.
On 09.06.2013 00:06, Luboš Doležel wrote:
GNUstep's NSString currently lacks
(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
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.
So I have a question: is it OK to write a function with declaration:
BOOL GSFromUnicodePartial(NSStringEncoding enc, int options, unichar
**inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
that wouldn't suffer from 1) and 2) and add it into
Source/Additions/Unicode.m next to GSFromUnicode()?
Gnustep-dev mailing list
|[Prev in Thread]||Current Thread||[Next in Thread]|