Hello Made a simple dwstring.bi Test with Unicode. Runs perfekt with Last Tiko build
I saved only the whole dwstring.bi File and copied in tiko-main folder.
' unicode test, go, tiko Editor
'
#INCLUDE ONCE "dwstring.bi"
DIM dws AS DWSTRING = "Дмитрий Дмитриевич Шостакович"
DIM f AS LONG = FREEFILE
OPEN "test1.txt" FOR OUTPUT ENCODING "utf16" AS #f ' go russian characters saved in text file too
PRINT #f, dws
CLOSE #f
print dws ' go
sleep
I will be switching over to DWSTRING soon. I am still using CWSTR from the original Afx library.
I suggest that you check out the CTextFile class. It makes dealing with unicode and non-unicode files very easy. It also has the benefit of being able to use unicode filenames (eg. if your test1.txt contained non-English characters).
Here is code directly from Tiko's source code.
This snippet loads all FB keywords directly from the text file into the FBKeywords string variable
#include once "Afx\AfxFile.inc"
dim pStream as CTextStream
if pStream.Open(this.FBKeywordsFilename) <> S_OK then exit function
this.FBKeywords = pStream.ReadAll
pStream.Close
This one saves those keywords back to the non-unicode file:
dim pStream as CTextStream
if pStream.Create(this.FBKeywordsFilename) <> S_OK then exit function
pStream.WriteLine this.FBKeywords
pStream.Close
This one opens a non-unicode file and reads it line by line:
dim pStream as CTextStream
if pStream.Open(this.FBCodetipsFilename) <> S_OK then return true ' error
do until pStream.EOS
wst = pStream.ReadLine
' do stuff with the line
loop
pStream.Close
This opens a unicode file and reads it line by line:
dim pStream as CTextStream '(utf16)
if pStream.OpenUnicode(this.ConfigFilename) <> S_OK then return true ' error
do until pStream.EOS
wst = pStream.ReadLine
' do stuff with the line
loop
pStream.Close
This one creates a unicode file and saves information to it line by line:
dim pStream as CTextStream '(utf16)
if pStream.Create(this.ConfigFilename, true, true) <> S_OK then return true ' error
pStream.WriteLine "' SETTINGS FILE"
pStream.WriteLine ""
pStream.WriteLine "SettingsVersion=" & APPVERSION
' etc etc etc
pStream.Close
DWSTRING has several advantages over CWSTR, like using words instead of bytes.
The string descriptor follows the one for FreeBasic's STRING, but for unicode. This means that we can use STRPTR instead of * (although * still can be used).
' // Don't change the order of these variables
m_pBuffer AS WSTRING PTR ' // Pointer to the buffer
m_BufferLen AS ssize_t ' // Length in UTF16 characters of the buffer
m_Capacity AS ssize_t ' // The total size of the buffer in UTF16 characters
All the operations are centralized in the AppendBuffer method. This means that for any new feature I don't need to modify many other procedures. For example, it contains optional code to check and fix broken surrogates, without having to modify any of the string procedures.
CWSTR has been doing its job well, but it needed a revision. After all it was the first class that I wrote and I had little expertise with FreeBasic at that time.
hello jose, what I can use for similar equivalent files for AfxFile.inc for AfxNova?
thanks, frank
' Afx/AfxFile.inc ' winfbe editor
#pragma once
#include once "Afx/AfxWin.inc"
#include once "Afx/AfxPath.inc"
#include once "Afx/CStream.inc"
#include once "Afx/CTextStream.inc"
#include once "Afx/CFindFile.inc"
#include once "Afx/CFileSys.inc"
#include once "Afx/CFileTime.inc"
USING Afx
And Last Not least afxRichEdit.inc
They have the same name. Use "AfxNova" instead of "Afx", e.g. #include once "Afx/AfxWin.inc"