#1 2016-09-12 11:09:00

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

TSynAnsiConvert.AnsiBufferTo* and #0 in the end

@AB - while implementing a nodeJS Buffer object (to be committed to SyNode) we discover a problem:
all TSynAnsiConvert.AnsiBufferTo* functions append a #0 to the end of Dest buffer. This is not good for our use cases - we need to modify a part of buffer and not break a rest.
Can I add a optional argument to the AnsiBufferTo* to prevent such behavior?

function AnsiBufferToUnicode(Dest: PWideChar; Source: PAnsiChar; SourceChars: Cardinal; ZeroTerminate: boolean = true): PWideChar; overload; virtual;
begin
...
  if ZeroTerminate then result^ := #0;
end;

Offline

#2 2016-09-12 12:23:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,669
Website

Re: TSynAnsiConvert.AnsiBufferTo* and #0 in the end

Offline

#3 2016-09-12 15:20:21

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: TSynAnsiConvert.AnsiBufferTo* and #0 in the end

Thanks! The first check is OK..
Please, review the commit  [86ecc83b65]- we add a REPLACEMENT CHARACTER (0xEF 0xBF 0xBD for UFT8) for unmathced surrogate pairs during RawUnicodeToUtf8
This version is pass nodeJS buffer tests, but may be you decide to rewrite in more "mORMot" way smile

Last edited by mpv (2016-09-12 15:22:53)

Offline

#4 2016-09-13 07:41:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,669
Website

Re: TSynAnsiConvert.AnsiBufferTo* and #0 in the end

Offline

#5 2016-09-13 11:50:02

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: TSynAnsiConvert.AnsiBufferTo* and #0 in the end

I add small changes - see http://synopse.info/fossil/info/7043499 … 71277de61d (and [81ebdcdf6d] - I don't understand how I rewrite your changes - looks like fossil merge not ideal)

Offline

#6 2016-09-13 12:02:44

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: TSynAnsiConvert.AnsiBufferTo* and #0 in the end

Ups. This is not fossil merge - this is my Subversion. AB - let's merge a  WinWebSocket &  HTTPServerEvents to the trunk. This changes not break your code, but add a low-level HTTP.SYS based WebSockets (allow many WS client connections - we currently have near 5000 in production and WSS). Because I work in WinWebSocket brunch I can't use a fossil repo directly and need to copy mORMot to the my subversion repo. This complicates my life for every mORMot repo commit sad

Offline

#7 2018-03-01 08:06:38

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,571
Website

Re: TSynAnsiConvert.AnsiBufferTo* and #0 in the end

I'm simplify condition for replacing unmatched surrogate pairs during RawUnicodeToUtf8 - please, see fix for FPC compiler. Delphi and FPC compiler unexpectedly differs for me...

Offline

Board footer

Powered by FluxBB