On Apr 10, 2012, at 10:48 AM, Deep wrote: > On 10/04/2012 18:33, Max Taylor wrote: >> Is the any reason why we can't read file data directly into a CFString >> as per below? >> I haven't actually tried it. Unless there is some underlying carbon reason. >> >> dim as CFStringRef tempStr >> line input #2, tempStr >> Max > > The reason is because CFStrings do not behave like FB strings. FB strings were modelled on Pascal strings. CFStrings are pointers to datablocks of character data, which has the advantage of allowing different text encodings such as the traditional MacRoman, but also more modern UTF-8 or double byte characters such as UTF-16. > > To achieve the above, you need to continue to read into a normal string, and then place that data into the CFString: > > dim as CFStringRef tempStr > dim as str255 myTempReadStr > > line input #2, myTempReadStr > > tempStr = fn CFStringCreateWithCharacters( _kCFAllocatorDefault, @myTempReadStr+1, len( myTempReadStr ) ) > > ... do your stuff here with the CFString > > ... then remember to Release the CFString: > > fn CFRelease( tempStr ) I can see the above working fine but I am thinking in terms of my pre-compiler for Objective-X, "COORS". My major goals is the elimination of whatever carbon dependence I can do. Obviously Objective-C and Xcode projects have to have the ability to read in 'text' files in ascii formats but it is my guess, since I have not done it, that any ascii text is read directly into either "C" string or NSString formats instead of using the pascal strings we deal with in FB. Maybe some embedded 'BeginC.../EndC routines that directly read an ascii FB source file directly into 'NSString/CFString' format, modify the original source and output the modified contents back into an FB ascii file that FBtoC can read and deal with. This would get rid of having to use pascal strings and their associated left$, mid$, right$, etc. and replace them with their CFString counterparts. Something like "(NSString *) substringFromIndex: (NSInteger) anIndex" that could replace the code for left$ in its own special function like: "CFStr = leftString( CFString, 10 )" or in Objective-X maybe something like: "CFStr = [ CFString leftString (short) 10 ] This is not just about me here but all of us because we're all in this boat together at this time without enough fingers to plug the upcoming holes that will eventually sink it. Maybe there is no carbon dependencies using pascal strings. That would be great. I'm just trying to think ahead enough to get a head start on the day when carbon is no more. Sort of like planning for Y2K. Maybe if we had a list of FB internal functions that were carbon dependent many of us could start chipping away at rewriting them one at a time and within a year we might win that fight before we lose we reach the 'event horizon'. Max