sonar-delphi icon indicating copy to clipboard operation
sonar-delphi copied to clipboard

Add full support for `HIGHCHARUNICODE`

Open fourls opened this issue 5 months ago • 4 comments

Fixes #368 by improving TextLiteralNode::characterEscapeToChar. Note that the interpretation of "ANSI encoding" is the system native encoding, so it is assumed that the system the Sonar scan runs on has the same native encoding as the system compiling the code.

fourls avatar Jul 23 '25 03:07 fourls

One thing I forgot to note - I removed support for binary character escapes (e.g. #%11101110) since as far as I can tell Delphi does not recognise them.

fourls avatar Jul 23 '25 03:07 fourls

The system encoding isn't what the compiler is using. The compiler is using the configured codepage, which may be 0, which means the system encoding.

zaneduffield avatar Jul 23 '25 03:07 zaneduffield

Actually... let me check that.

zaneduffield avatar Jul 23 '25 03:07 zaneduffield

It's a bit subtle, but I was right that the compiler does use the configured codepage for this kind of thing.

The reason it's subtle, is that if the type of the variable being assigned to is AnsiChar (or AnsiString), then the codepage at compile-time is irrelevant, because the bytes will be stored as written and interpreted at runtime. However if the type of the variable being assigned to is WideChar (or WideString), then any ANSI bytes from compile-time would have been converted to Unicode at compile time using the configured codepage.

I'm not sure how exactly this affects the change here, but I would expect the configured codepage to become involved at some point.

zaneduffield avatar Jul 23 '25 04:07 zaneduffield