Sign in Join
FPDoc Onlineexperiment

LazUTF8 unit

Routines for managing UTF-8-encoded strings.

lazutf8.pas contains useful routines for managing UTF-8-encoded strings. All routines are thread-safe unless explicitly stated.

lazutf8.pas is part of the LazUtils package.

Classes and records

TStringListUTF8FastclassImplements a string list using fast ASCII comparison functions when its data is pure ASCII.

Procedures and functions

ConsoleToUTF8functionConverts an OEM-encoded string to UTF8.
ConvertUTF16ToUTF8functionConverts values from UTF-16 encoding to UTF-8 encoding.
ConvertUTF8ToUTF16functionConverts values from UTF-8 encoding to UTF-16 encoding.
FindInvalidUTF8CodepointfunctionFinds the position where an invalid UTF-8 codepoint is found in the string.
GetEnvironmentStringUTF8functionReturns a system environment string.
GetEnvironmentVariableCountUTF8functionReturns the number of system environment variables.
GetEnvironmentVariableUTF8functionReturns the value of a system environment variable.
IsAsciifunctionReturns True when the specified string contains only single-byte ASCII characters.
IsPureAsciifunctionDetermines whether the specified string contains only single-byte ASCII characters.
NeedRTLAnsifunctionIndicates if the OS requires use of AnsiToUTF8 and UTF8ToAnsi for the RTL.
ParamStrUTF8functionGets the specified command line parameter and converts it to a UTF-8-encoded string.
SetNeedRTLAnsiprocedureSets the value for the unit global variable.
SysErrorMessageUTF8functionGets the UTF-8-encoded system error message for the specified error code.
SysToUTF8functionConverts strings (and format settings) from the system codepage to UTF-8.
UnicodeToUTF8functionEncodes the given code point as an UTF-8 sequence of 1 to 4 bytes.
UnicodeToUTF8InlinefunctionEncodes the given code point as an UTF-8 sequence of 1 to 4 bytes.
UnicodeToUTF8SkipErrorsfunctionStores a single Unicode codepoint as a UTF-8-encoded value in the buffer.
UTF16ToUTF8functionConverts a UTF-16-encoded string (system endian) to UTF-8 encoding.
UTF8AddCharfunctionAdds the specified number of UTF-8 codepoints to a string.
UTF8AddCharRfunctionAppends the specified number of UTF-8 codepoints to a string.
UTF8CodepointCountfunctionGets the number of valid UTF-8 codepoints in the specified value.
UTF8CodepointSizefunctionReturns the size of the UTF-8 codepoint in bytes.
UTF8CodepointSizeFastfunctionFast version of UTF8CodepointSize.
UTF8CodepointStartfunctionFinds the n-th UTF-8 codepoint.
UTF8CodepointStrictSizefunctionGets the number of bytes needed for the UTF-8 codepoint.
UTF8CodepointToByteIndexfunctionFinds the byte index of the n-th UTF-8 codepoint.
UTF8CodepointToUnicodefunctionConverts a UTF-8-encoded character to its unique Unicode U+XXXX character value.
UTF8CompareStrfunctionCompares the UTF-8-encoded string values.
UTF8CompareStrPfunctionCompares the specified PChar values.
UTF8CompareTextfunctionCase-insensitive comparison of two UTF-8-encoded values.
UTF8CompareTextPfunctionPerforms a case-insensitive comparision for the specified UTF-8-encoded PChar values.
UTF8CopyfunctionCopies the specified number of codepoints from the UTF-8-encoded string starting at the specified character index.
UTF8CStringToUTF8StringfunctionCopies from a C-style string with UTF-8 encoding to UTF-8 string.
UTF8DeleteprocedureDeletes characters (or codepoints) in a UTF-8-encoded string.
UTF8EndsTextfunctionDetermines if a string ends with the specified value.
Utf8EscapeControlCharsfunctionTranslates control characters in a UTF-8-encoded string into human-readable escaped format.
UTF8FindNearestCharStartfunctionFinds the start of the UTF-8 character at the specified position.
UTF8FixBrokenprocedureReplaces all invalid UTF-8 characters in a string with the specified character.
UTF8InsertprocedureInserts the specified UTF-8 values into a string at the specified character position.
UTF8LeftStrfunctionGets the specified number of characters (codepoints) at the start of the string.
UTF8LengthfunctionGets the length of a UTF-8-encoded string in codepoints.
UTF8LengthFastfunctionFast version of UTF8Length.
UTF8LowerCasefunctionConverts the specified string to lowercase using Unicode case mapping rules.
UTF8LowerCaseFastfunctionGets the lowercase value for the specified text. Optimized to improve speed for ASCII content in the argument.
UTF8LowerStringfunctionConverts the specified string to lowercase using Unicode case mapping rules.
UTF8PadCenterfunctionCenter aligns a string to the specified length.
UTF8PadLeftfunctionAdds the specified number of values in AUtf8Char to the beginning of a string.
UTF8PadRightfunctionAppends the specified number of UTF-8 codepoints to the end of a string.
UTF8PosfunctionReturns the character index where the search text starts in the string.
UTF8PosPfunctionReturns a pointer to the position where SearchForText starts in SearchInText, or Nil when not found.
UTF8ProperCasefunctionCapitalizes the first letter of each word in the UTF-8-encoded string.
UTF8QuotedStrfunctionPerforms safe quoting for the specified UTF-8-encoded string value.
UTF8ReverseStringfunctionReverses the order of codepoints in the specified string.
UTF8RightStrfunctionGets the specified number of characters (codepoints) at the end of the string.
UTF8RPosfunctionGets the right-most position in the Source string for the value in Substr.
UTF8StartsTextfunctionDetermines if a string starts with the specified value.
UTF8StringOfCharfunctionCreates a string filled with the specified number of given codepoints.
UTF8StringReplacefunctionReplaces one or more values in a UTF-8-encoded string which match a given pattern.
UTF8SwapCasefunctionConverts the case for UTF-8 codepoints in the specified string and returns the converted value.
UTF8ToConsolefunctionConverts a UTF-8-encoded string to console (OEM) encoding.
UTF8ToDoubleBytefunctionConverts a UTF-8-encode string to its DBCS representation.
UTF8ToDoubleByteStringfunctionConverts UTF-8 values to their DBCS equivalent.
UTF8ToSysfunctionEnsures UTF-8 characters (or format settings) are converted to the system code page.
UTF8ToUTF16functionConverts the UTF-8 encoded string to UTF-16 encoding (system endian).
UTF8ToWinCPfunctionConverts the UTF-8-encoded string to the Windows code page encoding.
UTF8TrimfunctionRemoves leading and trailing whitespace or control characters.
Utf8TryFindCodepointStartfunctionTries to find the start of a valid UTF-8 codepoint in a string.
UTF8UpperCasefunctionConverts the specified string to uppercase using Unicode case mapping rules.
UTF8UpperCaseFastfunctionGets the uppercase value for the specified text. Optimized to improve speed for ASCII content in the argument.
UTF8UpperStringfunctionInline variant of UTF8UpperCase.
UTF8WrapTextfunctionCreates a word-wrapped version of the specified string.
WinCPToUTF8functionConverts the string from Windows code page to UTF-8.

Types

PEscapedStringstypePointer to a TEscapedStrings type.
TControlCharstypeSpecifies a range used to identify control characters.
TConvertOptionenumerationIndicates options enabled during UTF-8 <-> UTF-16 conversions.
TConvertOptionssetStores values from the TConvertOption enumeration.
TConvertResultenumerationIndicates the result from UTF-8 <-> UTF-16 conversions.
TEscapedStringstypeFixed-length array of strings used to convert control characters to an escaped encoding style.
TEscapeModeenumerationRepresents styles used to escape control characters.
TUTF8TrimFlagenumerationControls trimming actions performed in UTF8Trim.
TUTF8TrimFlagssetStores values from the TUTF8TrimFlag enumeration.

Constants

trNoErrorconstantDeprecated. Use trSuccess in TConvertResult instead.

Variables

FPUpCharsvariableContains uppercase characters for all values in the char type.

Uses

  • cwstring
  • FPCAdds
  • Classes
  • SysUtils
  • StrUtils

An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.