Skip to content

Commit f887730

Browse files
committed
fix: recently broken unicode support in comments
1 parent a7b45ed commit f887730

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

hslib.pas

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -514,36 +514,32 @@ function base64decode(s:ansistring):ansistring;
514514

515515
function validUTF8(s:rawbytestring):boolean;
516516
var
517-
i, bits, len: integer;
517+
i, more, len: integer;
518518
c: byte;
519519
begin
520-
c:=0;
521-
bits:=0;
522520
len:=length(s);
523521
i:=0;
524522
while i < len do
525523
begin
526524
inc(i);
527525
c:=ord(s[i]);
528-
if c < 128 then
526+
if c < $80 then
529527
continue;
530-
if c >= 254 then
528+
if c >= $FE then
531529
exit(FALSE);
532-
if c >= 252 then bits:=6
533-
else if c >= 248 then bits:=5
534-
else if c >= 240 then bits:=4
535-
else if c >= 224 then bits:=3
536-
else if c >= 192 then bits:=2
530+
if c >= $F0 then more:=3
531+
else if c >= $E0 then more:=2
532+
else if c >= $C0 then more:=1
537533
else exit(FALSE);
538-
if (i+bits > len) then
534+
if i+more > len then
539535
exit(FALSE);
540-
while bits > 1 do
536+
while more > 0 do
541537
begin
542538
inc(i);
543539
c:=ord(s[i]);
544-
if (c < 128) or (c > 191) then
540+
if (c < $80) or (c > $C0) then
545541
exit(FALSE);
546-
dec(bits);
542+
dec(more);
547543
end;
548544
end;
549545
result:=TRUE;

utillib.pas

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,8 @@ function getStr(from, to_:pchar):string;
20622062
end;
20632063
l:=to_-from+1;
20642064
setLength(result, l);
2065-
if l > 0 then strLcopy(@result[1], from, l);
2065+
if l > 0 then
2066+
strLcopy(@result[1], from, l);
20662067
end; // getStr
20672068

20682069
function poss(chars:TcharSet; s:string; ofs:integer=1):integer;

0 commit comments

Comments
 (0)