How create a UTF-8 file

forum.sourcecode (2000-2005) & forum.td.sourcecode (2005-2010)
Roberto Martinez

How create a UTF-8 file

Post by Roberto Martinez » 29 Jan 2009, 00:28

 Posted by:  Roberto Martinez 

Hi!!! somebody have created a UTF-8 file?????

How????

I only have created an ANSI file..

thanks in advice

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2385
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: How create a UTF-8 file

Post by Jeff Luther » 29 Jan 2009, 17:57

 Posted by:  Jeff Luther 

Take a look at my unify/td page: http://www.jeffluther.net/unify/
go to the bottom of the page and look for "Unicode Samples." I have a sample
called: Writing UTF-8 & Big Endian formatted files with TD v5.1
And if you do not have v5.1 my TD-Converter utility, also on that page, can
back convert from 5.1.

- Jeff/Unify

Roberto Martinez

Re: How create a UTF-8 file

Post by Roberto Martinez » 04 Feb 2009, 22:58

 Posted by:  Roberto Martinez 

Hi Jeff,

Thanks for the tip.... and i did you said i downloaded td-converter and the
Writing UTF8 exlample ...

but i have one big problem....SalStrToMultiByte function doesn't exist in my
TD 4.0....i think this is part of TD5.0.....

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2385
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: How create a UTF-8 file

Post by Jeff Luther » 05 Feb 2009, 01:46

 Posted by:  Jeff Luther 

SalStrToMultiByte() -- came out in vt5.1.

But if you'll download the zip for "Writing a Unicode-formatted file before
TD v5.1" on my web page in the samples section, you will see the
KERNEL32.DLL functions to use. They are:
MultiByteToWideChar() and WideCharToMultiByte()

- Jeff/Unify Corp.

Roberto Martinez

Re: How create a UTF-8 file

Post by Roberto Martinez » 17 Feb 2009, 00:10

 Posted by:  Roberto Martinez 

Hi Jeff,

I downloaded the files and i tested....i have a doubt... in the code section
you create an UTF file ...but later there are a section where i supose you
create a utf8 file but you dont save any file.....

Code: Select all

!!CB!! 174
Set nUnicodeCharsLength = WideCharToMultiByte( CP_UTF8, WC_COMPOSITECHECK,sTextIn, SalStrGetBufferLength( sTextIn ),       sUnicodeBufBackIn, nBufLen,'*', bUsedDefaultChar )
Set nBufLen = SalStrGetBufferLength( sUnicodeBufBackIn )
so i put a similar utf section to create the file but i create an empty file

Code: Select all

If SalFileWrite( hFile, sUnicodeBufBackIn, SalStrGetBufferLength(sUnicodeBufBackIn) ) = 0
 Call SalFileClose( hFile )
 Return FALSE
Call SalFileClose( hFile )
i search about the characters you put at the begining of the file 0xFF and
0xFE in google an d i found the codes to configure and utf8 file ..i
replaced and used the characters to create an UTF8 file but the infomation
is very strange and i dont know if the information is right or wrong ....
:-(

Any suggestion?
thanks in advance
see ya!!

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2385
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: How create a UTF-8 file

Post by Jeff Luther » 17 Feb 2009, 02:40

 Posted by:  Jeff Luther 

'but you dont save any file' --?? The file is written in the line:
SalFileWrite()
and then the file is closed with: SalFileClose().

I think you are confusing UTF-16 with UTF-8:
--> "FF FE" is the 2-byte header for UTF-16 encoding.
--> "EF BB BF" is the 3-byte header for UTF-8 encoding.

I don't know where you got the code below and the CP_UTF8 constant.

This code, beginning with:
Set nUnicodeCharsLength = WideCharToMultiByte( CP_UTF8, ...
is only to convert back so I can compare the 'before' and 'after' strings.
Look at my comments...

! test conversion back to Unicode
and
! can't display sUnicodeBufBackIn since it's Unicode, but lengths between
original sTextIn and sUnicodeBufBackIn should be the same

- Jeff

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2385
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: How create a UTF-8 file

Post by Jeff Luther » 17 Feb 2009, 02:42

 Posted by:  Jeff Luther 

Sorry... Ignore the line "I don't know where you got the code below and the
CP_UTF8 constant." :wink:

Return to “td.sourcecode”

Who is online

Users browsing this forum: [Ccbot] and 0 guests