Errors, bugs, questions - page 2825

 
Vladimir Pastushak:

What's wrong with the code ?

I'd also rather not answer than explain the perniciousness of working with a generic character list.

 
Alexey Viktorov:

I'd rather not answer either, than explain the perniciousness of working with a generic character list.

In private

 

isthe syntax highlighting on the website glitchy?


b.highlight is not a function

 
2020.08.15 13:07:42.660 Network 'xxxx': no connection to MetaQuotes-Beta
 

There is a text file, but the encoding is unknown beforehand. Accordingly, we need to determine which flag to open it with: FILE_ANSI or FILE_UNICODE.

Who has one, please share a bicycle on the subject.

 
fxsaber:

There is a text file, but the encoding is unknown beforehand. Accordingly, we need to determine which flag to open it with: FILE_ANSI or FILE_UNICODE.

If you have one, please share your bike on the subject.

Aren't there any encoding labels inside the file?

 

Sometimes Unicode has an encoding label in the first 2 bytes.

There is also VinAPI IsTextUnicode like this https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-istextunicode

IsTextUnicode function (winbase.h) - Win32 apps
IsTextUnicode function (winbase.h) - Win32 apps
  • 2018.12.05
  • lastnameholiu
  • docs.microsoft.com
Determines if a buffer is likely to contain a form of Unicode text.
 
I did this.
  bool IsUnicode( const uchar &Bytes[] )
  {
    return((::ArraySize(Bytes) > 1) && (Bytes[0] == 0xFF) && (Bytes[1] == 0xFE));
  }

  void Unicode2ANSI( uchar &Bytes[] )
  {
    if (IsUnicode(Bytes))
    {
      const int Size = (::ArraySize(Bytes) >> 1) - 1;
      
      for (int i = 0; i < Size; i++)
        Bytes[i] = Bytes[(i << 1) + 2];
        
      ::ArrayResize(Bytes, Size);
    }
  }
But I don't know if this condition is always correct.
 
fxsaber:
Did it this way. But I don't know if this condition is always correct.

this token is optional and is different for LE, BE and UTF8. if it is missing, you can theoretically count the number of null bytes in some initial chunk of the file

 
Andrei Trukhanovich:

this token is optional and is different for LE, BE and UTF8. if it is missing, theoretically it is possible to count the number of null bytes in some initial piece of file

Considered this workaround, thanks. Seems to be the only way to do it.

Reason: