Pull request - CWSTR to CBSTR (fix Chinese)

Started by Paul Squires, August 15, 2018, 07:11:11 PM

Previous topic - Next topic

Paul Squires

Hi Jose, over on my WinFBE GitHub a user has posted a pull rewust: https://github.com/PaulSquires/WinFBE/pull/3
Essentially all it sees to be do is change the CWSTR to CBSTR when reading a line from the localization file (which are UTF-16 BOM files).

Change line 1045 in modRoutines.inc from:
   Dim as CWSTR wst, wKey, wData
To:
   Dim as CBSTR wst, wKey, wData



Function LoadLocalizationFile( Byref wszFileName As CWSTR ) As BOOLEAN

   ' default that the file failed to load
   Function = False
   If AfxFileExists(wszFileName) = 0 Then Exit Function

   Dim as CWSTR wst, wKey, wData    '<----- THIS LINE
   Dim nKey  As Long
   Dim nData As Long 
   Dim i     As Long
   
   dim pStream AS CTextStream
   if pStream.OpenUnicode(wszFileName) <> S_OK then exit function
   
   do until pStream.EOS
      wst = pStream.ReadLine
     
      If Len(wst) = 0 Then Continue Do
      If Left(wst, 1) = "'" Then Continue Do


The request says that it "fixes messy Chinese code". Can you understand why that would be the case? The CWSTR should easily read the unicode characters from the UTF-16 file so why would CBSTR make any difference? What do you think?

Paul Squires
PlanetSquires Software

José Roca

#1
Well, Readline returns a CBSTR, not a CWSTR, but I'm no making any kind of conversion, but copying all the bytes from one to another.

I have slightly modified CWSTR.inc to use a direct pointer instead of casting, i.e. cast(ANY PTR, cbs.m_bstr) instead of cast(ANY PTR, cbs). It should not make any difference, but...

Also check if the first two bytes returned by ReadLine are the BOM or not. They should be skipped, but...

We really need Chinese testers :)

Paul Squires

Thanks Jose, I will post a link to your post and the new CWSTR file as a response to the pull request. I could easily change the source to use CBSTR but for consistency I'd prefer to stick with CWSTR as it is used everywhere else in WinFBE.

...I'll let you know if I hear back from the submitter.
Paul Squires
PlanetSquires Software