[Overview][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'LazUTF8' (#lazutils)

UTF8Length

Gets the length of a UTF-8-encoded string in codepoints.

Declaration

Source position: lazutf8.pas line 81

function UTF8Length(

  const s: string

):PtrInt;

function UTF8Length(

  p: PChar;

  ByteCount: PtrInt

):PtrInt;

Arguments

s

  

UTF-8-encoded string to examine in the function.

Function result

Number of codepoints in the byte values for the string.

Arguments

p

  

Pointer to the UTF-8-encoded string to examine in the function.

ByteCount

  

Number of byte values in the UTF-8-encoded string.

Description

UTF8Length is a function used to get the character length for the specified UTF-8-encoded string. The return value contains the number of UTF-8-encoded characters (or codepoints) found in the byte values for the string.

An overloaded variant of the function is provided which uses the PChar type to specify the byte values in the string. Internally, the String variant casts its value a PChar type and calls the overloaded variant.

UTF8Length iterates over the bytes in the UTF-8-encoded string data, and calls UTF8CodepointSize to determine the number of bytes needed for each codepoint. Use UTF8LengthFast for a version of the routine optimized for speed.

See also

UTF8CodepointSize

  

Returns the size of the UTF-8 codepoint in bytes.

UTF8LengthFast

  

Fast version of UTF8Length.


Version 3.2 Generated 2024-02-25 Home