#1 2022-01-26 06:30:17

htits2008
Member
Registered: 2015-03-25
Posts: 31

strings code Different in client and server

Hi, Master!
   I have some strings code Different in client and server 。I want change some UTF8char(CJK) to ansichar. In client it do ok, and the length of strings is 285. but in server it make Garbled code, and the length of strings is 190。
Can I get any suggest?

function fullToHalf(aStr: rawutf8): rawutf8;
var
 str0,str1,str2:strings;
  strcnw:strings;
 Flags: TReplaceFlags;
 n,iCount:Integer;
const
 strcn:string='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ‘1234567890-=\~!#$%^&()_+|〔〕{};’:,。/<>?【】“”';
 stren:string='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`1234567890-=\~!#$%^&()_+|[]{};'':,./<>?[]""';
begin
 try
 strcnw:=utf8String(strcn);
 str0:=astr;
         with tsynlog.Enter() do
        begin
          log(sllinfo,str0);
         log(sllinfo,inttostr(length(strcn))+' char');  //190 or 285 
         log(sllinfo,inttostr(length(strcnw))+' wchar');   //190 or 285 
         log(sllinfo,inttostr(length(stren))+' echar'); //95
        end;
 for n:=1 to 93 do
 begin
 str1:=copy(strcnw,n*2-1,2); // copy(strcnw,n*3-2,3);
 str2:=copy(stren,n,1);

 Flags:=[rfReplaceAll];
 str0:=StringReplace(str0,str1,str2,iCount);
 if iCount>0 then
 begin
   with tsynlog.Enter() do
   begin
        log(sllinfo,str1+' '+str2 +' '+inttostr(iCount));
        //log(sllinfo,);
   end;
 end;
 end;
 Result:=str0;
 with tsynlog.Enter() do
begin
 log(sllinfo,' result: ');
 log(sllinfo,Result);
end;

  except
     on E:exception do
     begin
        with tsynlog.Enter() do
        begin
          log(sllinfo,' half error:  '+E.Message);

        end;
     end;
  end;
end; 

Offline

#2 2022-01-26 12:12:51

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: strings code Different in client and server

You need to provide more info, compiled with Delphi? Which version? Both client and server using same compiler & build mode? Modern Delphi string type is UnicodeString by default UTF-16 encoded so as expected uses more space then UTF-8 encoded rawutf8.

Offline

#3 2022-01-27 00:48:11

htits2008
Member
Registered: 2015-03-25
Posts: 31

Re: strings code Different in client and server

pvn0 wrote:

You need to provide more info, compiled with Delphi? Which version? Both client and server using same compiler & build mode? Modern Delphi string type is UnicodeString by default UTF-16 encoded so as expected uses more space then UTF-8 encoded rawutf8.

I use codetyphon 7.6 ,fpc 3.3.1, windows 7 64bit.
In server side ,I add to interface object.

  TORP_FTSObject =class(TInterfacedObject, Iorp_FTS)
    function fullToHalf(aStr:rawutf8):rawutf8; 
  end;

Offline

#4 2022-01-27 03:55:42

htits2008
Member
Registered: 2015-03-25
Posts: 31

Re: strings code Different in client and server

I got the answer. Thanks!
https://synopse.info/forum/viewtopic.php?id=5241

Last edited by htits2008 (2022-01-27 06:03:02)

Offline

Board footer

Powered by FluxBB