Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
TextUtils Namespace Reference

Pure string helpers with no dependencies on QDoc driver types. More...

Functions

QString separator (qsizetype wordPosition, qsizetype numberOfWords)
QString comma (qsizetype wordPosition, qsizetype numberOfWords)
QString asAsciiPrintable (const QString &str)
 Returns an ASCII-printable representation of str.
QString protect (const QString &string)

Variables

static constexpr QLatin1StringView samp = "&"_L1
static constexpr QLatin1StringView slt = "<"_L1
static constexpr QLatin1StringView sgt = ">"_L1
static constexpr QLatin1StringView squot = """_L1

Detailed Description

Pure string helpers with no dependencies on QDoc driver types.

TextUtils groups text-manipulation helpers that the IR builders, the template generator, and the legacy generators all need, but that do not touch Node, Tree, Config, or Generator. Keeping them here lets QDocLib components call them without dragging in the rest of QDoc.

Function Documentation

◆ asAsciiPrintable()

QString TextUtils::asAsciiPrintable ( const QString & str)

Returns an ASCII-printable representation of str.

Replaces non-ASCII-printable characters in str from a subset of such characters. The subset includes alphanumeric (alnum) characters ([a-zA-Z0-9]), space, punctuation characters, and common symbols. Non-alnum characters in this subset are replaced by a single hyphen. Leading, trailing, and consecutive hyphens are removed, such that the resulting string does not start or end with a hyphen. All characters are converted to lowercase.

If any character in str is non-latin, or latin and not found in the aforementioned subset (e.g. 'ß', 'å', or 'ö'), a hash of str is appended to the final string.

Returns a string that is normalized for use where ASCII-printable strings are required, such as file names or fragment identifiers in URLs.

Definition at line 80 of file textutils.cpp.

◆ comma()

QString TextUtils::comma ( qsizetype wordPosition,
qsizetype numberOfWords )

Returns the inter-item punctuation for a list of numberOfWords words at wordPosition.

For a list of length one, returns an empty QString. For a list of length two, returns " and ". For longer lists, returns ", " for early items and ", and " for the item before the last. The last position returns an empty QString; its punctuation is the period returned by separator().

See also
separator()

Definition at line 51 of file textutils.cpp.

◆ protect()

QString TextUtils::protect ( const QString & str)

HTML-escapes the ampersand, less-than, greater-than, and double-quote characters in str, leaving other characters untouched.

Definition at line 127 of file textutils.cpp.

◆ separator()

QString TextUtils::separator ( qsizetype wordPosition,
qsizetype numberOfWords )

Returns the punctuation character for the word at wordPosition in a list of numberOfWords length. For the last position, returns "." (full stop). For any other word, delegates to comma().

See also
comma()

Definition at line 30 of file textutils.cpp.

Variable Documentation

◆ samp

QLatin1StringView TextUtils::samp = "&"_L1
staticconstexpr

Definition at line 37 of file textutils.h.

◆ sgt

QLatin1StringView TextUtils::sgt = ">"_L1
staticconstexpr

Definition at line 39 of file textutils.h.

◆ slt

QLatin1StringView TextUtils::slt = "<"_L1
staticconstexpr

Definition at line 38 of file textutils.h.

◆ squot

QLatin1StringView TextUtils::squot = """_L1
staticconstexpr

Definition at line 40 of file textutils.h.