mirror of
				https://gitlab.com/freepascal.org/lazarus/lazarus.git
				synced 2025-11-04 12:29:27 +01:00 
			
		
		
		
	Cocoa: improve in UTF8CodepointCount()
This commit is contained in:
		
							parent
							
								
									a851bf46fa
								
							
						
					
					
						commit
						27063a7dca
					
				@ -84,8 +84,8 @@ function UTF8Length(p: PChar; ByteCount: PtrInt): PtrInt;
 | 
			
		||||
function UTF8LengthFast(const s: string): PtrInt; inline;
 | 
			
		||||
function UTF8LengthFast(p: PChar; ByteCount: PtrInt): PtrInt;
 | 
			
		||||
 | 
			
		||||
function UTF8CodepointCount(const s: string): PtrInt; inline;
 | 
			
		||||
function UTF8CodepointCount(p: PChar; ByteCount: PtrInt): PtrInt;
 | 
			
		||||
function UTF8CodepointCount(const s: string): SizeInt; inline;
 | 
			
		||||
function UTF8CodepointCount(p: PChar; ByteCount: SizeInt): SizeInt;
 | 
			
		||||
 | 
			
		||||
// Functions dealing with unicode number U+xxx.
 | 
			
		||||
function UTF8CodepointToUnicode(p: PChar; out CodepointLen: integer): Cardinal;
 | 
			
		||||
@ -575,16 +575,18 @@ begin
 | 
			
		||||
  Result:=UTF8CodepointCount(PChar(s),length(s));
 | 
			
		||||
end;
 | 
			
		||||
 | 
			
		||||
function UTF8CodepointCount(p: PChar; ByteCount: PtrInt): PtrInt;
 | 
			
		||||
function UTF8CodepointCount(p: PChar; ByteCount: SizeInt): SizeInt;
 | 
			
		||||
var
 | 
			
		||||
  codepointLen: LongInt;
 | 
			
		||||
  codepointLen: SizeInt;
 | 
			
		||||
begin
 | 
			
		||||
  Result:=0;
 | 
			
		||||
  while (ByteCount>0) do begin
 | 
			
		||||
    inc(Result);
 | 
			
		||||
    codepointLen:=UTF8CodepointLen(p,ByteCount,false);
 | 
			
		||||
    if codepointLen=0 then
 | 
			
		||||
    codepointLen:=UTF8CodepointLen(p,ByteCount,False);
 | 
			
		||||
    if codepointLen >= 0 then
 | 
			
		||||
      inc(Result);
 | 
			
		||||
    if codepointLen = 0 then
 | 
			
		||||
      Exit;
 | 
			
		||||
    codepointLen:= abs( codepointLen);
 | 
			
		||||
    inc(p,codepointLen);
 | 
			
		||||
    dec(ByteCount,codepointLen);
 | 
			
		||||
  end;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user