[Openmcl-devel] cocoa and unicode

Raffael Cavallaro raffaelcavallaro at mac.com
Wed Sep 22 16:30:44 UTC 2004


On Sep 21, 2004, at 11:09 PM, alex crain wrote:

> Can someone put together an example for me on how I would complete  
> this expression:
>
> (make-instance 'ns:ns-attributed-string
> 					 :with-string (make-instance 'ns:ns-string :with-characters  
> ??????)
> 					 :attributes some-attributes))
>
> The question marks refer to an ojb-c unichar *
>
> Alternate approaches would be well received as well.

How are you going to create these unicode characters? Are they fixed at  
compile time, or are you getting them from user input?

If these strings are fixed at compile time, they are supposed to be in  
a string table (which you can create in XCode or Project Builder). The  
strings for each language live in the file:
YourApp.app/Contents/Resources/SpecificLanguage.lproj/ 
Localizable.strings
wherre YourApp.app is your application's app bundle, and  
SpecificLanguage is French, Italian, Danish, etc.

Then you should use [NSBundle mainBundle]  
localizedStringForKey:value:table:

to retrieve the unicode string that corresponds to the english string  
key. This approach requires that the localized language be set to  
something other than english for it to work (i.e., the localized  
language on the machine running your app must be French to get the  
French unicode string).

If you don't want this sort of localization behavior, or if you're not  
creating an app bundle,  you could create a file with the strings (or  
characters) that you want to use, and read them in with:

- (id)initWithContentsOfFile:(NSString *)path

but make sure that the file you're reading from has been saved in UTF8.  
If it is plain ASCII, then the string will be read in as a plain old c  
string, which is not what you want.


If you know the bytes that the string is composed of, and the unicode  
encoding (for example, NSUTF8Encoding) then you could use

– initWithBytes:length:encoding

or

– initWithBytesNoCopy:length:encoding:freeWhenDone:




Finally, if you're getting these Unicode characters/strings from user  
input in an NSTextField, it should just work - i.e., the user will be  
able to enter any unicode characters they want by setting the  
appropriate preferences in the International prefpane. Then you get the  
NSString (which is unicode) by sending your NSTextField instance:

stringValue



I've never tried any of this from OpenMCL so I don't know how well this  
corner of Cocoa  is supported yet - Gary and Randall might know.

regards,
Ralph

Raffael Cavallaro, Ph.D.
raffaelcavallaro at mac.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2560 bytes
Desc: not available
URL: <http://lists.clozure.com/pipermail/openmcl-devel/attachments/20040922/69bcec1e/attachment.bin>


More information about the Openmcl-devel mailing list