mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-13 21:29:19 +02:00
* fpc_char_to_unicodestr: call widestringmanager directly instead of nested char_to_uchar conversion.
* UnicodeToUtf8: calculate UCS4 value without three (!) temp string variables. Also removed separate word-sized variable and unsigned subtractions. git-svn-id: trunk@20268 -
This commit is contained in:
parent
c72a639e7b
commit
8dab34b31a
@ -505,10 +505,7 @@ Function fpc_Char_To_UnicodeStr(const c : Char): UnicodeString; compilerproc;
|
|||||||
Converts a Char to a UnicodeString;
|
Converts a Char to a UnicodeString;
|
||||||
}
|
}
|
||||||
begin
|
begin
|
||||||
Setlength(fpc_Char_To_UnicodeStr,1);
|
widestringmanager.Ansi2UnicodeMoveProc(@c,DefaultSystemCodePage,result,1);
|
||||||
fpc_Char_To_UnicodeStr[1]:=c;
|
|
||||||
{ Terminating Zero }
|
|
||||||
PUnicodeChar(Pointer(fpc_Char_To_UnicodeStr)+sizeof(UnicodeChar))^:=#0;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1437,9 +1434,7 @@ function UnicodeToUtf8(Dest: PChar; Source: PUnicodeChar; MaxBytes: SizeInt): Si
|
|||||||
function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PUnicodeChar; SourceChars: SizeUInt): SizeUInt;
|
function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PUnicodeChar; SourceChars: SizeUInt): SizeUInt;
|
||||||
var
|
var
|
||||||
i,j : SizeUInt;
|
i,j : SizeUInt;
|
||||||
w : word;
|
|
||||||
lw : longword;
|
lw : longword;
|
||||||
len : longint;
|
|
||||||
begin
|
begin
|
||||||
result:=0;
|
result:=0;
|
||||||
if source=nil then
|
if source=nil then
|
||||||
@ -1450,28 +1445,28 @@ function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PUnicodeChar
|
|||||||
begin
|
begin
|
||||||
while (i<SourceChars) and (j<MaxDestBytes) do
|
while (i<SourceChars) and (j<MaxDestBytes) do
|
||||||
begin
|
begin
|
||||||
w:=word(Source[i]);
|
lw:=ord(Source[i]);
|
||||||
case w of
|
case lw of
|
||||||
0..$7f:
|
0..$7f:
|
||||||
begin
|
begin
|
||||||
Dest[j]:=char(w);
|
Dest[j]:=char(lw);
|
||||||
inc(j);
|
inc(j);
|
||||||
end;
|
end;
|
||||||
$80..$7ff:
|
$80..$7ff:
|
||||||
begin
|
begin
|
||||||
if j+1>=MaxDestBytes then
|
if j+1>=MaxDestBytes then
|
||||||
break;
|
break;
|
||||||
Dest[j]:=char($c0 or (w shr 6));
|
Dest[j]:=char($c0 or (lw shr 6));
|
||||||
Dest[j+1]:=char($80 or (w and $3f));
|
Dest[j+1]:=char($80 or (lw and $3f));
|
||||||
inc(j,2);
|
inc(j,2);
|
||||||
end;
|
end;
|
||||||
$800..$d7ff,$e000..$ffff:
|
$800..$d7ff,$e000..$ffff:
|
||||||
begin
|
begin
|
||||||
if j+2>=MaxDestBytes then
|
if j+2>=MaxDestBytes then
|
||||||
break;
|
break;
|
||||||
Dest[j]:=char($e0 or (w shr 12));
|
Dest[j]:=char($e0 or (lw shr 12));
|
||||||
Dest[j+1]:=char($80 or ((w shr 6) and $3f));
|
Dest[j+1]:=char($80 or ((lw shr 6) and $3f));
|
||||||
Dest[j+2]:=char($80 or (w and $3f));
|
Dest[j+2]:=char($80 or (lw and $3f));
|
||||||
inc(j,3);
|
inc(j,3);
|
||||||
end;
|
end;
|
||||||
$d800..$dbff:
|
$d800..$dbff:
|
||||||
@ -1479,11 +1474,12 @@ function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PUnicodeChar
|
|||||||
begin
|
begin
|
||||||
if j+3>=MaxDestBytes then
|
if j+3>=MaxDestBytes then
|
||||||
break;
|
break;
|
||||||
if (i<sourcechars-1) and
|
if (i+1<sourcechars) and
|
||||||
(word(Source[i+1]) >= $dc00) and
|
(word(Source[i+1]) >= $dc00) and
|
||||||
(word(Source[i+1]) <= $dfff) then
|
(word(Source[i+1]) <= $dfff) then
|
||||||
begin
|
begin
|
||||||
lw:=longword(utf16toutf32(Source[i] + Source[i+1], 1, len));
|
{ $d7c0 is ($d800 - ($10000 shr 10)) }
|
||||||
|
lw:=(longword(lw-$d7c0) shl 10) + (ord(source[i+1]) xor $dc00);
|
||||||
Dest[j]:=char($f0 or (lw shr 18));
|
Dest[j]:=char($f0 or (lw shr 18));
|
||||||
Dest[j+1]:=char($80 or ((lw shr 12) and $3f));
|
Dest[j+1]:=char($80 or ((lw shr 12) and $3f));
|
||||||
Dest[j+2]:=char($80 or ((lw shr 6) and $3f));
|
Dest[j+2]:=char($80 or ((lw shr 6) and $3f));
|
||||||
@ -1514,7 +1510,7 @@ function UnicodeToUtf8(Dest: PChar; MaxDestBytes: SizeUInt; Source: PUnicodeChar
|
|||||||
inc(j,3);
|
inc(j,3);
|
||||||
$d800..$dbff:
|
$d800..$dbff:
|
||||||
begin
|
begin
|
||||||
if (i<sourcechars-1) and
|
if (i+1<sourcechars) and
|
||||||
(word(Source[i+1]) >= $dc00) and
|
(word(Source[i+1]) >= $dc00) and
|
||||||
(word(Source[i+1]) <= $dfff) then
|
(word(Source[i+1]) <= $dfff) then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user