fix: recently broken unicode support in comments

This commit is contained in:
Massimo Melina 2020-05-26 16:30:39 +02:00
parent a7b45ed515
commit f8877304ee
2 changed files with 12 additions and 15 deletions

View File

@ -514,36 +514,32 @@ end; // base64decode
function validUTF8(s:rawbytestring):boolean;
var
i, bits, len: integer;
i, more, len: integer;
c: byte;
begin
c:=0;
bits:=0;
len:=length(s);
i:=0;
while i < len do
begin
inc(i);
c:=ord(s[i]);
if c < 128 then
if c < $80 then
continue;
if c >= 254 then
if c >= $FE then
exit(FALSE);
if c >= 252 then bits:=6
else if c >= 248 then bits:=5
else if c >= 240 then bits:=4
else if c >= 224 then bits:=3
else if c >= 192 then bits:=2
if c >= $F0 then more:=3
else if c >= $E0 then more:=2
else if c >= $C0 then more:=1
else exit(FALSE);
if (i+bits > len) then
if i+more > len then
exit(FALSE);
while bits > 1 do
while more > 0 do
begin
inc(i);
c:=ord(s[i]);
if (c < 128) or (c > 191) then
if (c < $80) or (c > $C0) then
exit(FALSE);
dec(bits);
dec(more);
end;
end;
result:=TRUE;

View File

@ -2062,7 +2062,8 @@ if to_ = NIL then
end;
l:=to_-from+1;
setLength(result, l);
if l > 0 then strLcopy(@result[1], from, l);
if l > 0 then
strLcopy(@result[1], from, l);
end; // getStr
function poss(chars:TcharSet; s:string; ofs:integer=1):integer;