lazutils: simplified

git-svn-id: trunk@56163 -
This commit is contained in:
mattias 2017-10-23 09:35:35 +00:00
parent f9cb151061
commit 90dd28d142

View File

@ -887,24 +887,27 @@ begin
end; end;
function UTF8CharacterStrictLength(P: PChar): integer; function UTF8CharacterStrictLength(P: PChar): integer;
var
c: Char;
begin begin
if p=nil then exit(0); if p=nil then exit(0);
if ord(p^)<%10000000 then begin c:=p^;
if ord(c)<%10000000 then begin
// regular single byte character // regular single byte character
exit(1); exit(1);
end end
else if ord(p^)<%11000000 then begin else if ord(c)<%11000000 then begin
// invalid single byte character // invalid single byte character
exit(0); exit(0);
end end
else if ((ord(p^) and %11100000) = %11000000) then begin else if ((ord(c) and %11100000) = %11000000) then begin
// should be 2 byte character // should be 2 byte character
if (ord(p[1]) and %11000000) = %10000000 then if (ord(p[1]) and %11000000) = %10000000 then
exit(2) exit(2)
else else
exit(0); exit(0);
end end
else if ((ord(p^) and %11110000) = %11100000) then begin else if ((ord(c) and %11110000) = %11100000) then begin
// should be 3 byte character // should be 3 byte character
if ((ord(p[1]) and %11000000) = %10000000) if ((ord(p[1]) and %11000000) = %10000000)
and ((ord(p[2]) and %11000000) = %10000000) then and ((ord(p[2]) and %11000000) = %10000000) then
@ -912,7 +915,7 @@ begin
else else
exit(0); exit(0);
end end
else if ((ord(p^) and %11111000) = %11110000) then begin else if ((ord(c) and %11111000) = %11110000) then begin
// should be 4 byte character // should be 4 byte character
if ((ord(p[1]) and %11000000) = %10000000) if ((ord(p[1]) and %11000000) = %10000000)
and ((ord(p[2]) and %11000000) = %10000000) and ((ord(p[2]) and %11000000) = %10000000)