[futurebasic] Re: [FB] Save unicode text

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2009 : Group Archive : Group : All Groups

From: Brian Stevens <bstevens33@...>
Date: Thu, 10 Dec 2009 11:33:52 -0700
On Dec 10, 2009, at 9:35 AM, Bernie wrote:

> I wonder if your app could dispense with containers and work with  
> CFStrings only?


I assume Bernie has noticed that container runtime support uses pascal  
strings. Anything using pascal strings won't work with unicode  
characters.


This line in FB:   gC = "ƒøµ"   // gC is dimmed container

becomes:

CtnrStoreString( &gC, "\pƒøµ" );


Maybe Eugene's code isn't doing any direct container assignments with  
constants ( reading data from a file into a container based on posted  
code ), but there might be other pascal usage in the runtime.

I might have some time later today to build a demo based on something  
other than containers ( unless Ken or Bernie beat me to it! ). It  
should be possible to read data into a pointer and then do a fn  
CFStringCreateWithBytes. The following is a re-worked version of  
Eugen's OpenFile.

'--------------
local fn OpenFileReadIntoPtr as Pointer  // caller responsible for  
doing DisposePtr( p )
'~'1
dim as UInt32     dataSize
dim as pointer    p          p = 0
dim as FSSpec     fileSpec

long if ( files$( _FSSpecOpen,, "Open file:", fileSpec ) )
open "I", 1, @fileSpec

fn FSMakeFSSpec( system( _aplVRefNum ), system( _aplParID ),  
"Temporar.txt", @fileSpec )
open "O", 2, @fileSpec

dataSize = lof(1,1)
p = fn NewPtr( dataSize )
read file 1, p, dataSize
close #1
end if
end fn = p
'----------------

Also, for the times when the file data does not need to be changed  
before putting in and edit field, it can be inserted directly without  
intermediate step to create a CFString:

err = fn SetControlData( c, _kControlEditTextPart,  
_kControlEditTextTextTag, fn GetPtrSize( p ), #p ) // where 'c' is a  
ControlRef to the edit field.



Thanks for posting the demo code Eugen.

Brian S