Sign in Join
FPDoc Onlineexperiment

UTF8SwapCase function

In unit LazUTF8

Converts the case for UTF-8 codepoints in the specified string and returns the converted value.

Declaration

pascal
function UTF8SwapCase(const AInStr: string; const ALanguage: string='')
                      : string

Arguments

AInStr

UTF-8-encoded values converted in the routine.

ALanguage

Optional Language code for the locale used in the conversion.

Function result

UTF-8-encoded values after case conversion.

Description

UTF8SwapCase is a String function used to convert the case for the specified UTF-8 codepoints.

AInStr contains a UTF-8-encoded string with values to convert it the routine. Each codepoint in AInStr will have its case "toggled" in the function. In other words, a codepoint which is an uppercase character is converted to a lowercase one, and vice versa.

ALanguage indicates the language code to use for the conversion. ALanguage should be specified using ISO 639-1 format, which uses 2 characters to represent each language. If the language has no code in ISO 639-1, then the 3-character code from ISO 639-2 should be used. For example: 'tr' for the Turkish language locale or 'az' for the Azeri language code. ALanguage can be set to an empty string ('') for maximum speed in the conversion routine.

No actions are performed in the routine when AInStr is an empty string (''), and the return value is an empty string as well.

UTF6SwapCase processes the individual codepoints in AInStr to get the return value for the function. It ensures that codepoints which have a different number of bytes in the lowercase and uppercase variants are handled properly. UTF8UpperCase and UTF8LowerCase are called to change the case for each codepoint.

See also

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.