PlanetSquires Forums

Support Forums => José Roca Software => Topic started by: Frank Bruebach on July 21, 2025, 12:33:45 PM

Title: Dwstring test
Post by: Frank Bruebach on July 21, 2025, 12:33:45 PM
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
Title: Re: Dwstring test
Post by: Paul Squires on July 21, 2025, 12:55:16 PM
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


Title: Re: Dwstring test
Post by: José Roca on July 21, 2025, 05:04:53 PM
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.


Title: Re: Dwstring test
Post by: Frank Bruebach on July 21, 2025, 11:40:06 PM
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
Title: Re: Dwstring test
Post by: José Roca on July 22, 2025, 07:31:31 AM
They have the same name. Use "AfxNova" instead of "Afx", e.g. #include once "Afx/AfxWin.inc"