Hello
I make my own TEditorExpert. I discovered one problem. Is there a way to detect that unit is UTF8 or ASCII? I need to decide when to use GxOtaDeleteByteFromPos or GxOtaDeleteTextFromPos. Because GxOtaDeleteTextFromPos dont work correctly if unit has ASCII format and contains some national characters with ASCII code higher than 127.
In my opinion, the function GxOtaDeleteTextFromPos should have a mechanism for recognizing the unit coding . And if unit has ASCII coding then function GxOtaDeleteTextFromPos should call GxOtaDeleteByteFromPos and if unit has UTF8 coding then CharIndexToUTF8Pos is needed.
In function GxOtaDeleteTextFromPos is this comment:
// "StartPos" is a character position in a (possibly unicode) string
// the EditWriter needs a byte position in a UTF-8 string (for Delphi >=8)
// or in an ansistring (for Delphi <8)
But this is by my opinion wrong. I have Delphi 10.4.2 and my units is mostly still ASCII. Onli if i use some UTF8 chars (russian, chinese, greek and so on) then IDE ask me if i wont convert unit to UTF8. On the other hand my units is still default ASCII.
Mayby, better way is modify CharIndexToUTF8Pos funciton. If unit is ASCII then return the same index, if unit is UTF8 then is needed recalculating index.
Does the Gexpert have a function to recognize if unit is ASCII or UTF8?
The comment is referring to the internal encoding used in the text editor, not the encoding used in the file. Internally, Delphi up to 7 internally used ANSI, newer versions use UTF-8.