diff --git a/hslib.pas b/hslib.pas index ab487ad..a0305ec 100644 --- a/hslib.pas +++ b/hslib.pas @@ -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; diff --git a/utillib.pas b/utillib.pas index d25b089..69d855e 100644 --- a/utillib.pas +++ b/utillib.pas @@ -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;