Hi Sherm, Thanks for the very informative reply!
On Thursday, January 30, 2003, at 02:08 PM, Sherm Pendley wrote:
On Thursday, January 30, 2003, at 12:31 PM, Dan Mills wrote:Now, everything is fine and dandy as long as I'm using plain ol' ascii text. I set the NSText contents using the 'setString' function. But, if the text is some japanese, say, euc-jp or shift-jis or utf-8 encoded, then all I get is garbage.For compatibility, this will continue to be the case in the next version of CB - at least on the surface. But, in the next version, the scalars you get from Cocoa will be tied to their NSString counterparts instead of merely copied, so you'll be able to get at the underlying NSString object using the "tied" function. This will give the best of both worlds; Perl string handling wherever that's appropriate, and Cocoa's NSString object methods when you need them.
This seems to me like a great way to do it, I approve 100% :-)
As I said, you'll be able to create NSString objects and work with them directly, instead of relying on automatic conversion back and forth. Another nice benefit of that is, if you have a chunk of bytes that aren't encoded with UTF8, you'll be able to create an NSString object with the initWithData:encoding: method. Conversely, if you need to convert an NSString object you receive to a particular encoding, you'll be able to use the dataUsingEncoding: method to do that.Truly excellent. So in the common case, I just make sure my strings are all utf-8, and then NSText::setString will Just Work(tm). Sweet.
But, for now, I *could* just change my default locale, right? I'm gonna try that and see what happens.
Um, is there any way for me to try it out before it's released? (as in, can I check it out of cvs and play around with it?). I have no idea how hard it is to set up or anything, but I don't want to lose steam now that I'm hacking on this.For right now, I'm afraid you can't. Like I said above, though, you'll be able to use the initWithData:encoding: method to create an NSString object in the next CB version, and pass that to NSText's setString: method.Now, finally, my questions ;-) a) How can I explicitly tell the NSText object what encoding to use?
Well, it is, but all from one file which I then split into little chunks and feed it to the NSTextView. I briefly considered having one rtf file per "card", but it just feels.. icky. Plus, then I wouldn't be able to use emacs to easily make a bunch of cards just by editing a file.b) How can I shove RTF data into an NSText obj. using CB? (w/o using the 'readRTFDFromFile' function).Well, the glib answer to that is to use replaceCharactersInRange:withRTF: - but the only way to create an NSData object at the moment is to use NSData's initWithContentsOfFile: method, and from your comment I assume your data isn't coming from a file.
The next version of CB (I'll bet you're tired of hearing that...) will support raw pointers - i.e. "void *". Whenever a method needs a raw pointer, you'll pass it a scalar, and the ObjC method will get a pointer to the data area of the scalar. So, you'll be able to construct an NSData object from the bytes in a scalar with NSData's initWithBytes:length: or initWithBytesNoCopy:length: methods.interesting, that would work. What happens with those funky scalars that have separate integer and string values?
c) Is there more detailed documentation on CB itself? All I can find are short tutorials on the web.
Soon!
Hehe, ok, ok! :) -Dan
