19#include "kanoopcommon.h"
38 static bool toBool(
const QString& value) {
return value.toLower() ==
"true" || value ==
"1"; }
44 static bool toBool(
int value) {
return value != 0; }
56 static QString
toString(
bool value) {
return value ?
"true" :
"false"; }
63 static QString
toString(
double value,
int precision = 6);
70 static QString
toString(
const QByteArray& value,
const QString& delimiter = QString(
" "));
79 static QString
toHexTable(
const QByteArray& buffer,
bool showOffset =
true,
bool showText =
true,
int tableWidth = 16);
86 static QString
toString(
const QList<QUuid>& value,
const QString& delimiter = QString(
" "));
93 static QList<QUuid>
uuidsFromString(
const QString& value,
const QString& delimiter = QString(
" "));
120 static QString
toKMG(qint64 byteCount);
127 static QString
trimFront(
const QString& value,
const QList<QChar> &chars);
141 static QString
trimEnd(
const QString& value,
const QList<QChar> &chars);
148 static QString
trimBothEnds(
const QString& value,
const QList<QChar> &chars);
161 static QString
quoted(
const QString& value) {
return QString(
"\"%1\"").arg(value); }
169 static QStringList
trimmed(
const QStringList& value, Qt::SplitBehavior behavior = Qt::KeepEmptyParts);
178 static QStringList
splitWithQuotes(
const QString& value, QChar separator, Qt::SplitBehavior behavior = Qt::KeepEmptyParts);
186 static QStringList
splitWithQuotes(
const QString& value, QList<QChar> separators, Qt::SplitBehavior behavior = Qt::KeepEmptyParts);
196 static QString
combineToEol(
const QStringList& lines,
int index,
const QChar& eolCharacter =
';',
int* consumed =
nullptr);
213 static int fuzzyIndexOf(
const QString& needle,
const QString& haystack,
int maxDistance = 1);
235 Bitap(
const QString& haystack,
const QString& needle,
int maxDistance = 1);
241 int index()
const {
return _index; }
244 int calculate(
int maxDistance);
273 int min(
int a,
int b,
int c)
276 if(a <= b && a <= c) {
279 else if(b <= a && b <= c) {
282 else if(c <= a && c <= b) {
294 static QStringList splitWithQuotes(
const QString& value, QChar separator, Qt::SplitBehavior behavior = Qt::KeepEmptyParts);
295 static QStringList splitWithQuotes(
const QString& value, QList<QChar> separators, Qt::SplitBehavior behavior = Qt::KeepEmptyParts);
298 StringSplitter(
const QString& value, QList<QChar> separators, Qt::SplitBehavior behavior = Qt::KeepEmptyParts) :
299 _originalString(value), _separators(separators), _behavior(behavior), _inQuote(false) {}
302 void appendCurrent();
304 QString _originalString;
305 QList<QChar> _separators;
306 Qt::SplitBehavior _behavior;
313 static const char QUOTE =
'\"';
319 static QString combineToEol(
const QStringList& lines,
int index,
const QChar& eolCharacter,
int* consumed =
nullptr);
322 static const char QUOTE =
'\"';
323 static const char COLON =
':';
Implements BITAP algorithm for fuzzy search.
int index() const
Return the index of the fuzzy match.
Bitap(const QString &haystack, const QString &needle, int maxDistance=1)
Construct a Bitap fuzzy search and compute the result.
Implements the Levenshtein algorithm to determine the distance between two strings.
int distance() const
Return the computed Levenshtein distance.
Levenshtein(const QString &s1, const QString &s2)
Construct a Levenshtein calculator and compute the distance.
static QString trimEnd(const QString &value, const QList< QChar > &chars)
Trim the given characters from the end of the string.
static bool toBool(int value)
Convert an integer to a boolean.
static QString toDelimitedString(const QList< uint8_t > &list, char delimiter=' ')
Convert a list of uint8_t values to a single delimited string.
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 QString trimEnd(const QString &value)
Trim trailing whitespace from the string.
static QString quoted(const QString &value)
Wrap a string in double quotes.
static QString toDelimitedString(const QStringList &list, char delimiter=' ')
Convert a list of strings to a single delimited string.
static QString unquoted(const QString &value)
Return the region between the outermost quotes.
static QStringList trimmed(const QStringList &value, Qt::SplitBehavior behavior=Qt::KeepEmptyParts)
Return a list of all the strings trimmed.
static QString trimBothEnds(const QString &value, const QList< QChar > &chars)
Trim the given characters from both ends of the string.
static int levenshteinDistance(const QString &s1, const QString &s2)
Calculate the Levenshtein distance between two strings.
static QString toString(bool value)
Convert a boolean to a string ("true" or "false").
static QString toHexTable(const QByteArray &buffer, bool showOffset=true, bool showText=true, int tableWidth=16)
Convert a byte array to a hexadecimal table.
static QStringList splitWithQuotes(const QString &value, QChar separator, Qt::SplitBehavior behavior=Qt::KeepEmptyParts)
Split the string respecting quoted substrings.
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 QByteArray toByteArray(const QString &value)
Convert a string to a byte array.
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 QStringList splitWithQuotes(const QString &value, QList< QChar > separators, Qt::SplitBehavior behavior=Qt::KeepEmptyParts)
Split the string respecting quoted substrings, using multiple separators.
static QString toDelimitedString(const QList< int > &list, char delimiter=' ')
Convert a list of ints to a single delimited string.
static QString toString(const QList< QUuid > &value, const QString &delimiter=QString(" "))
Convert a list of QUuids to a string.
static QString toString(double value, int precision=6)
Convert a double to a string, trimming trailing zeros.
static bool toBool(const QString &value)
Convert the given string to a boolean.
static QList< QUuid > uuidsFromString(const QString &value, const QString &delimiter=QString(" "))
Convert a delimited string to a list of UUIDs.
static QString toString(const QByteArray &value, const QString &delimiter=QString(" "))
Convert a byte array to a hex string.