synopse / mORMot2

OpenSource RESTful ORM/SOA/MVC Framework for Delphi and FreePascal
https://synopse.info
Other
516 stars 130 forks source link

修正UnicodeBufferToAnsi函数不支持中文问题 #186

Closed blue8228 closed 1 year ago

blue8228 commented 1 year ago

src\core\mormot.core.unicode.pas src\core\mormot.core.unicode.pas

Unicode_WideToAnsi(Source, Dest, SourceChars, SourceChars, fCodePage)); --->>> Unicode_WideToAnsi(Source, Dest, SourceChars, (SourceChars + 1) shl fAnsiCharShift, fCodePage));

synopse commented 1 year ago

On which OS ? On which compiler ?

The +1 is not expected because it is up to the caller to add the trailing #0.

The shl fAnsiCharShift is not needed either, because we should use number of UTF-16 chars, not the bytes count. On Windows, it just calls WideCharToMultiByte() which requires the UTF-16 chars count. On Linux, it calls either Unicode2AnsiMoveProc() or ucnv_fromUChars() which also both require the UTF-16 chars count.

So I don't understand your modifications. Please use the synopse forum for discussion about this.

synopse commented 1 year ago

I guess the discussion continues at https://synopse.info/forum/viewtopic.php?id=6583