discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString methods returns GSUnicodeString, why?


From: Richard Frith-Macdonald
Subject: Re: NSString methods returns GSUnicodeString, why?
Date: Mon, 2 Jul 2001 17:15:27 +0100

On Monday, July 2, 2001, at 04:32 PM, Laurent Julliard wrote:

All,

I'm in the process of writing a Ruby to GNUstep binding. And I have
difficutlies to understand the following problem. A simple piece of Ruby
code illustrates the problem (irb is the Ruby interactive shell):

irb> a = NSString.new    # create a new NSString object
irb> a.initWithCString("GNUstep forever")
irb> a.length
15

Everything seems to be working fine. But...

irb> a.cString
Uncaught exception NSCharacterConversionException, reason: Can't get
cString from Unicode string.

Right after the initWithCString method call I have put some logs showing
that initWithCString actually returns a GSUnicodeString object instead
of a NSString object as you would expect. It looks like GSUnicodeString
is a subclass of GSString which in turn is a subclass of NSString. So
why isn't the cString method call working?

Any idea is welcome.

Assuming that the line -

irb> a = NSString.new    # create a new NSString object

is calling the 'new' method (a cover for an alloc followed by an init),
what is actually happening is that you are doing -

[NSString alloc]  (returns a placeholder string)
init    (transmutes placeholder to a concrete unicode string)
initWithCString:  (illegal ... already initialised)


So theres's a problem in GNUstep ... it should really have raised an exception when you tried to do the initWithCString:, and a problem in your code ... it
should have done alloc rather than new.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]