Re: dealing with different types of strings
Re: dealing with different types of strings
- Subject: Re: dealing with different types of strings
- From: Bill Bumgarner <email@hidden>
- Date: Wed, 16 Jan 2002 15:29:46 -0500
I had to deal with exactly this problem in SSHPassKey. The key is to
remember that an (NSString *) is the same as a (CFStringRef) for all
intents and purposes.
- (Str255 *) pascalStringFromString: (NSString *) aString
{
if (aString) {
Str255 *returnString = malloc(sizeof(Str255));
if ( !CFStringGetPascalString( (CFStringRef) aString,
*returnString, sizeof(*returnString), CFStringGetSystemEncoding())) {
free(returnString);
[NSException raise: NSInternalInconsistencyException
format: @"Failed to convert NSString '%@' to
pascal string.", aString];
}
return returnString;
}
return NULL;
}
Works like a charm [as far as I can tell]. Remember that the caller is
responsible for freeing the returned string (assuming a string is returned)
.
b.bum
On Wednesday, January 16, 2002, at 02:54 PM, email@hidden.
com wrote:
I'm trying to find the best method of taking input from a TextField and
converting it to a Pascal String to be inserted as parameters in a
library function. I can't find a way to get the value from the text
field as a Pascal string, so I thought of storing it to an NSString,
then using the getCString (or just cString) method to store it to a char
* (this may be an extra step), then using CopyCStringToPascal() to copy
the char * to a Str255 *... I was hoping there was an easier method for
accomplishing this...anyone have any ideas? I come from a Unix /
Windows background, so dealing with Pascal strings is totally foreign to
me...
b.bum
Wake up. Breathe....
.... keep breathing.