Byte swapping problem with TextField using API
Matthew Jew
mjew at icnc.com
Thu Jul 3 01:09:46 CDT 2008
Hello,
I have been successfully using Valentina 3.5.2, using the API in the C+
+ SDK.
I recently switched from using a PowerPC Mac (Big Endian byte order)
to using an Intel Mac (Little Endian byte order).
*Almost* everything is working perfectly.
My trouble is accessing string values that I have stored in a
TextField and putting them into an NSString.
(I have written to the list before about this subject, and have those
problems have been solved.)
This is my first encounter with byte order/byte swapping issues.
I have tried to access my string values two ways.
My old way:
I_FldBlob_Ptr pBlobField = QI( aHTMLTemplateTable->valueText,
I_FldBlob );
unsigned long dataLength = pBlobField->get_DataSize();
NSMutableData *aMutableData = [[NSMutableData alloc]
initWithLength:dataLength];
pBlobField->ReadData( (char *) [aMutableData mutableBytes],
dataLength );
NSString *value = [[[NSString alloc] initWithData:aMutableData
encoding:NSUnicodeStringEncoding] autorelease];
[aMutableData release];
I was told that since I was accessing the data as a blob, that I would
not gain byte-swapping as needed.
So, I changed to this:
Const_I_Value_Ptr myStringValue = aHTMLTemplateTable->valueText-
>get_Value();
unsigned long myStringLength = myStringValue->get_Length();
NSMutableData *aMutableData = [[NSMutableData alloc]
initWithLength:myStringLength];
myStringValue->get_String( (UChar *) [aMutableData mutableBytes],
myStringLength );
NSString *value = [[[NSString alloc] initWithData:aMutableData
encoding:NSUnicodeStringEncoding] autorelease];
[aMutableData release];
Here I access the value as a string. However, I do NOT get byte-
swapping. (The string ends up garbled).
How am I supposed to access my TextField value and put it into an
NSString?
- Matthew
More information about the Valentina
mailing list