Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure SetRawUTF8(var Dest: RawUTF8; text: pointer; len: integer);
- {$ifdef FPC}inline;
- begin
- if (len>128) or (len=0) or (text<>pointer(Dest)) then
- SetString(Dest,PAnsiChar(text),len) else
- SetLength(Dest,len);
- end;
- {$else}
- {$ifdef PUREPASCAL}
- var P: PStrRec;
- begin
- if (len>128) or (len=0) or (PtrInt(Dest)=0) or // Dest=''
- (PStrRec(PtrInt(Dest)-STRRECSIZE)^.refCnt<>1) then
- SetString(Dest,PAnsiChar(text),len) else begin
- if PStrRec(Pointer(PtrInt(Dest)-STRRECSIZE))^.length<>len then begin
- P := Pointer(PtrInt(Dest)-STRRECSIZE);
- ReallocMem(P,len+(STRRECSIZE+1));
- P^.length := len;
- pointer(Dest) := pointer(PAnsiChar(P)+STRRECSIZE);
- PByteArray(Dest)[len] := 0;
- end;
- Move(pointer(text)^,pointer(Dest)^,len);
- end;
- end;
- {$else}
- asm // eax=@Dest text=edx len=ecx
- cmp ecx,128 // avoid huge move() in ReallocMem()
- {$ifdef UNICODE}
- ja @3
- {$else}
- ja System.@LStrFromPCharLen
- {$endif}
- or ecx,ecx // len=0
- {$ifdef UNICODE}
- jz @3
- {$else}
- jz System.@LStrFromPCharLen
- {$endif}
- push ebx
- mov ebx,[eax]
- test ebx,ebx
- jnz @2
- @0: pop ebx
- {$ifdef UNICODE}
- @3: push CP_UTF8 // UTF-8 code page for Delphi 2009+
- call System.@LStrFromPCharLen // we need a call, not a jmp here
- ret
- {$else}
- jmp System.@LStrFromPCharLen
- {$endif}
- @2: cmp dword ptr [ebx-8],1
- jne @0
- cmp dword ptr [ebx-4],ecx
- je @1
- sub ebx,STRRECSIZE
- push edx
- push eax
- push ecx
- push ebx
- mov eax,esp // ReallocMem() over ebx pointer on stack
- lea edx,ecx+STRRECSIZE+1
- call System.@ReallocMem
- pop ebx
- pop ecx
- add ebx,STRRECSIZE
- pop eax
- pop edx
- mov [eax],ebx
- mov dword ptr [ebx-4],ecx
- mov byte ptr [ebx+ecx],0
- @1: mov eax,edx
- mov edx,ebx
- call Move
- pop ebx
- end;
- {$endif}
- {$endif}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement