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

Utf8EscapeControlChars

Translates control characters in a UTF-8-encoded string into human readable format.

Declaration

Source position: lazutf8.pas line 158

function Utf8EscapeControlChars(

  S: string;

  EscapeMode: TEscapeMode = emPascal

):string;

Arguments

S

  

UTF-8 encoded string with values converted in the routine.

EscapeMode

  

Controls the human readable format for escaped characters.

Function result

String with the escaped values for control characters in S.

Description

Utf8EscapeControlChars translates control characters inside a UTF-8-encoded string into human readable format. Characters in the range #0..#31 are converted into the human-readable values for the control characters in the format specified by EscapeMode, including:

emPascal
Pascal-style escape characters '#27'
emHexPascal
Pascal-style hexadecimal strings '#$1B'
emHexC
C-style hexadecimal strings '\0x1B'
emC
C-style strings '\e'
emAsciiControlNames
ASCII-style control names '[ESC]'

Utf8EscapeControlChars calls FindInvalidUTF8Codepoint to see if S contains any invalid codepoints for the UTF-8 encoding. UTF8FixBroken is called to repair the input value.

Utf8EscapeControlChars iterates over the characters in S, and converts any character value in the eligible range using an internal lookup table for the value in EscapeMode. All other character values (or values in multi-byte UTF-8 code points) are included in the return value in their unmodified form.

Mainly used as a diagnostic or logging tool.

See also

UTF8FixBroken

  

Replaces all invalid UTF-8 characters with spaces.

TEscapeMode

  

Represents styles used to escape control characters.


Version 3.2 Generated 2024-02-25 Home