|
KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
|
|
#include <stringutil.h>
Classes | |
| class | Bitap |
| Implements BITAP algorithm for fuzzy search. More... | |
| class | Levenshtein |
| Implements the Levenshtein algorithm to determine the distance between two strings. More... | |
Static Public Member Functions | |
| static bool | toBool (const QString &value) |
| Convert the given string to a boolean. | |
| static bool | toBool (int value) |
| Convert an integer to a boolean. | |
| static QByteArray | toByteArray (const QString &value) |
| Convert a string to a byte array. | |
| static QString | toString (bool value) |
| Convert a boolean to a string ("true" or "false"). | |
| static QString | toString (double value, int precision=6) |
| Convert a double to a string, trimming trailing zeros. | |
| static QString | toString (const QByteArray &value, const QString &delimiter=QString(" ")) |
| Convert a byte array to a hex string. | |
| static QString | toHexTable (const QByteArray &buffer, bool showOffset=true, bool showText=true, int tableWidth=16) |
| Convert a byte array to a hexadecimal table. | |
| static QString | toString (const QList< QUuid > &value, const QString &delimiter=QString(" ")) |
| Convert a list of QUuids to a string. | |
| static QList< QUuid > | uuidsFromString (const QString &value, const QString &delimiter=QString(" ")) |
| Convert a delimited string to a list of UUIDs. | |
| static QString | toDelimitedString (const QStringList &list, char delimiter=' ') |
| Convert a list of strings to a single delimited string. | |
| static QString | toDelimitedString (const QList< int > &list, char delimiter=' ') |
| Convert a list of ints to a single delimited string. | |
| static QString | toDelimitedString (const QList< uint8_t > &list, char delimiter=' ') |
| Convert a list of uint8_t values to a single delimited string. | |
| static QString | toKMG (qint64 byteCount) |
| Format a byte count as an abbreviated string (K, M, G). | |
| static QString | trimFront (const QString &value, const QList< QChar > &chars) |
| Trim the given characters from the front of the string. | |
| static QString | trimEnd (const QString &value) |
| Trim trailing whitespace from the string. | |
| static QString | trimEnd (const QString &value, const QList< QChar > &chars) |
| Trim the given characters from the end of the string. | |
| static QString | trimBothEnds (const QString &value, const QList< QChar > &chars) |
| Trim the given characters from both ends of the string. | |
| static QString | unquoted (const QString &value) |
| Return the region between the outermost quotes. | |
| static QString | quoted (const QString &value) |
| Wrap a string in double quotes. | |
| static QStringList | trimmed (const QStringList &value, Qt::SplitBehavior behavior=Qt::KeepEmptyParts) |
| Return a list of all the strings trimmed. | |
| static QStringList | splitWithQuotes (const QString &value, QChar separator, Qt::SplitBehavior behavior=Qt::KeepEmptyParts) |
| Split the string respecting quoted substrings. | |
| static QStringList | splitWithQuotes (const QString &value, QList< QChar > separators, Qt::SplitBehavior behavior=Qt::KeepEmptyParts) |
| Split the string respecting quoted substrings, using multiple separators. | |
| static QString | combineToEol (const QStringList &lines, int index, const QChar &eolCharacter=';', int *consumed=nullptr) |
| Combine strings from the list until hitting one that ends with an EOL character. | |
| static int | indexOfWord (const QString &value, int wordNumber) |
| Return the character index of a given word number (1-based) in the string. | |
| static int | fuzzyIndexOf (const QString &needle, const QString &haystack, int maxDistance=1) |
| Calculate the index of a fuzzy match using the BITAP algorithm. | |
| static int | levenshteinDistance (const QString &s1, const QString &s2) |
| Calculate the Levenshtein distance between two strings. | |
Some static helper methods for converting strings to and from other types.
Additionally, methods exist for fuzzy string comparisons using the BITAP and Levenshtein Distance algorithms.
Stephen Punak, February 12 2021
Static helper methods for string conversion, manipulation, and fuzzy matching.
Provides conversions between strings and common types (bool, double, QByteArray), trimming, splitting with quote awareness, and fuzzy matching via the BITAP and Levenshtein Distance algorithms.
Definition at line 28 of file stringutil.h.
|
static |
Combine strings from the list until hitting one that ends with an EOL character.
| lines | Source string list |
| index | Starting index |
| eolCharacter | End-of-line character to look for |
| consumed | Output set to the number of lines consumed (may be nullptr) |
|
static |
Calculate the index of a fuzzy match using the BITAP algorithm.
| needle | Pattern to search for |
| haystack | String to search in |
| maxDistance | Maximum Levenshtein distance for a match |
|
static |
Return the character index of a given word number (1-based) in the string.
| value | Source string |
| wordNumber | 1-based word ordinal |
|
static |
Calculate the Levenshtein distance between two strings.
| s1 | First string |
| s2 | Second string |
|
inlinestatic |
Wrap a string in double quotes.
| value | String to quote |
Definition at line 161 of file stringutil.h.
|
static |
Split the string respecting quoted substrings.
| value | String to split |
| separator | Separator character |
| behavior | Whether to keep or skip empty parts |
|
static |
Split the string respecting quoted substrings, using multiple separators.
| value | String to split |
| separators | List of separator characters |
| behavior | Whether to keep or skip empty parts |
|
inlinestatic |
Convert the given string to a boolean.
"true" (case-insensitive) or "1" yields true; everything else yields false.
| value | String to convert |
Definition at line 38 of file stringutil.h.
|
inlinestatic |
Convert an integer to a boolean.
| value | Integer to convert (0 = false, non-zero = true) |
Definition at line 44 of file stringutil.h.
|
static |
Convert a string to a byte array.
| value | String to convert |
|
static |
Convert a list of ints to a single delimited string.
| list | Integer list to join |
| delimiter | Separator character |
|
static |
Convert a list of uint8_t values to a single delimited string.
| list | Byte list to join |
| delimiter | Separator character |
|
static |
Convert a list of strings to a single delimited string.
| list | String list to join |
| delimiter | Separator character |
|
static |
Convert a byte array to a hexadecimal table.
| buffer | Byte array to display |
| showOffset | Whether to show byte offsets |
| showText | Whether to show ASCII text column |
| tableWidth | Number of bytes per row |
|
static |
Format a byte count as an abbreviated string (K, M, G).
| byteCount | Number of bytes |
|
inlinestatic |
Convert a boolean to a string ("true" or "false").
| value | Boolean to convert |
Definition at line 56 of file stringutil.h.
|
static |
Convert a byte array to a hex string.
| value | Byte array to convert |
| delimiter | Separator between hex bytes |
|
static |
Convert a list of QUuids to a string.
| value | List of UUIDs |
| delimiter | Separator between UUIDs |
|
static |
Convert a double to a string, trimming trailing zeros.
| value | Double to convert |
| precision | Maximum number of decimal places |
|
static |
Trim the given characters from both ends of the string.
| value | Source string |
| chars | Characters to trim |
|
static |
Trim trailing whitespace from the string.
| value | Source string |
|
static |
Trim the given characters from the end of the string.
| value | Source string |
| chars | Characters to trim |
|
static |
Trim the given characters from the front of the string.
| value | Source string |
| chars | Characters to trim |
|
static |
Return a list of all the strings trimmed.
| value | String list to trim |
| behavior | Whether to keep or skip empty parts |
|
static |
Return the region between the outermost quotes.
| value | Quoted string |
|
static |
Convert a delimited string to a list of UUIDs.
| value | Delimited string containing UUIDs |
| delimiter | Separator between UUIDs |