UTF8WrapText function
Creates a word-wrapped version of the specified string.
Declaration
function UTF8WrapText(S: string; BreakStr: string;
BreakChars: TSysCharSet; MaxCol: Integer;
Indent: Integer): string; overloadArguments
S | String with values word-wrapped in the routine. |
BreakStr | End-of-line sequence used in the routine. |
BreakChars | Set of characters where a line break can be inserted. |
MaxCol | Maximum line width in number of UTF-8 characters. |
Indent | Number of Space (#32) characters used to indent the individual lines of word-wrapped text. |
Function result
Word-wrapped version of the specified text.
Description
UTF8WrapText is an overloaded
String function used to
wrap lines of text in
S at the number of characters (codepoints)
specified in
MaxCol.
The overloaded variant allow additional parameters to be provided with the
EOL character sequence and a set of characters where a line break can be
inserted. Default characters are used in BreakChars for the
variant without a BreakChars argument. They include: ' ' (Space), '-' (Dash),
and #9 (Tab). BreakStr contains the end-of-line sequence used to
represent a line break inserted into the return value.
Use Indent to specify the number of Space (#32) characters inserted
as indentation at the beginning of each word-wrapped line. The default value
is 0 (zero) and omits indentation in the word-wrapped lines. A negative value
in Indent causes the argument to be set to 0.
The Indent argument affects the number of UTF-8 characters allowed in each word-wrapped line. When set to a positive non-zero value, the maximum number of characters allowed per line is MaxCol - Indent - Len(BreakStr). BreakStr is not inserted if a given line exceeds MaxCol but does not include one of the values in BreakChars. For example:
// 90 character string not wrapped at column 80 when no break chars are found ShowMessage(UTF8WrapText( '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890', LineEnding, [' ', ';'], 80, 8));
No actions are performed in the function when S is an empty string (''), MaxCol is set to 0 (zero), or BreakChars is an empty set ([]).
Modified in LazUtils 4.0 to include the overload with an indentation argument.
See also
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
