[futurebasic] Save unicode text

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

From: Eugen Rosu <eugen.rosu@...>
Date: Thu, 10 Dec 2009 18:30:06 +0200
This is my demo code:






"--------------------------------
BEGIN GLOBALS
      DIM AS container conteinerText, conteinerText2
END GLOBALS

include "Util_Containers.incl"
include "Tlbx HIView.incl"

'~'1
LOCAL
dim as Str255    s
DIM AS LONG dataSize
dim as handle  textHandle
dim as FSSpec fileSpec
LOCAL FN OpenFile
'---------------------------------------------------
s = files$( _FSSpecOpen,, "Open file:", fileSpec )
IF s="" THEN EXIT FN
open "I", 1, @fileSpec

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

dataSize = LOF(1,1)
textHandle = fn NewHandle( dataSize )
CALL HLock( textHandle )
READ FILE 1, [textHandle], dataSize
CALL HUnlock( textHandle )
CLOSE #1
conteinerText = &textHandle
END FN

'~'1
LOCAL
dim as UniChar             nr1, nr2
dim as CFStringRef         cfStr1, cfStr2
dim as CFIndex             count : count = 0
LOCAL FN ReplaceCharacter ( find as integer, replace as integer,  
mutStrTemp as CFMutableStringRef)  as CFMutableStringRef
nr1 = find
cfStr1 = fn CFStringCreateWithCharacters( _kCFAllocatorDefault, nr1, 1 )
nr2 = replace
cfStr2 = fn CFStringCreateWithCharacters( _kCFAllocatorDefault, nr2, 1 )
long if ( mutStrTemp )
count = fn CFStringFindAndReplace( mutStrTemp, cfStr1, cfStr2, fn  
CFRangeMake( 0, fn CFStringGetLength( mutStrTemp ) ), 0 )
end if
END FN = mutStrTemp

'~'1
LOCAL
dim as CFMutableStringRef  mutStrTemp
dim as ControlFontStyleRec cfs
LOCAL fn BuildWindow
window 1,,(0,0)-(400,600)

mutStrTemp = fn ContainerCreateCFString( conteinerText )

edit field 1,,(10,10)-(390,190),,_leftJust
cfs.flags = _kControlUseSizeMask
cfs.size = 13
fn SetButtonFontStyle( 1, cfs )
fn HIViewSetText( button&( 1 ), mutStrTemp )
'------ Romanian characters --------------
mutStrTemp = FN ReplaceCharacter(8747, 537, mutStrTemp)'∫ --> sh

edit field 2,,(10,200)-(390,390),,_leftJust
fn SetButtonFontStyle( 2, cfs )

fn HIViewSetText( button&( 2 ), mutStrTemp )

edit field 3,,(10,400)-(390,590),,_leftJust
fn SetButtonFontStyle( 3, cfs )
fn ContainerCreateWithCFString( mutStrTemp, conteinerText2 )

EDIT$(3) = conteinerText2
' Now I want to save mutStrTemp or conteinerText2
CFRelease( mutStrTemp )
END FN

'~'1
FN OpenFile
fn BuildWindow

do
HandleEvents
until ( gFBquit )
'-----------------------------------------------


Bucure�ti