19#include <QDomDocument>
21#include <QRegularExpression>
24#ifndef QGSSTRINGUTILS_H
25#define QGSSTRINGUTILS_H
27#define FUZZY_SCORE_WORD_MATCH 5
28#define FUZZY_SCORE_NEW_MATCH 3
29#define FUZZY_SCORE_CONSECUTIVE_MATCH 4
51 QString
match()
const {
return mMatch; }
67 QString process(
const QString &input )
const;
71 return mMatch == other.mMatch && mReplacement == other.mReplacement && mCaseSensitive == other.mCaseSensitive && mWholeWordOnly == other.mWholeWordOnly;
95 QRegularExpression mRx;
120 QList< QgsStringReplacement >
replacements()
const {
return mReplacements; }
137 QString process(
const QString &input )
const;
145 void writeXml( QDomElement &elem, QDomDocument &doc )
const;
152 void readXml(
const QDomElement &elem );
155 QList< QgsStringReplacement > mReplacements;
194 static int levenshteinDistance(
const QString &string1,
const QString &string2,
bool caseSensitive =
false );
205 static QString
longestCommonSubstring(
const QString &string1,
const QString &string2,
bool caseSensitive =
false );
216 static int hammingDistance(
const QString &string1,
const QString &string2,
bool caseSensitive =
false );
224 static QString
soundex(
const QString &
string );
235 static double fuzzyScore(
const QString &candidate,
const QString &search );
244 static QString
insertLinks(
const QString &
string,
bool *foundLinks =
nullptr );
252 static bool isUrl(
const QString &
string );
266 static QString
wordWrap(
const QString &
string,
int length,
bool useMaxLineLength =
true,
const QString &customDelimiter = QString() );
312 static bool containsByWord(
const QString &candidate,
const QString &words, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive );
381 static QString
unaccent(
const QString &input );
Capitalization
String capitalization options.
void setReplacements(const QList< QgsStringReplacement > &replacements)
Sets the list of string replacements in this collection.
QgsStringReplacementCollection(const QList< QgsStringReplacement > &replacements=QList< QgsStringReplacement >())
Constructor for QgsStringReplacementCollection.
QList< QgsStringReplacement > replacements() const
Returns the list of string replacements in this collection.
A representation of a single string replacement.
bool wholeWordOnly() const
Returns true if match only applies to whole words, or false if partial word matches are permitted.
QString replacement() const
Returns the string to replace matches with.
bool caseSensitive() const
Returns true if match is case sensitive.
QgsStringReplacement(const QString &match, const QString &replacement, bool caseSensitive=false, bool wholeWordOnly=false)
Constructor for QgsStringReplacement.
bool operator==(const QgsStringReplacement &other) const
QString match() const
Returns the string matched by this object.
Utility functions for working with strings.
static int hammingDistance(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the Hamming distance between two strings.
static QString soundex(const QString &string)
Returns the Soundex representation of a string.
static QHash< QString, QString > UNACCENT_MAP
Lookup table used by unaccent().
static int levenshteinDistance(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the Levenshtein edit distance between two strings.
static QString htmlToMarkdown(const QString &html)
Convert simple HTML to markdown.
static QString longestCommonSubstring(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the longest common substring between two strings.
static QString capitalize(const QString &string, Qgis::Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
static QString substituteVerticalCharacters(QString string)
Returns a string with characters having vertical representation form substituted.
static QString unaccent(const QString &input)
Removes accents and other diacritical marks from a string, replacing accented characters with their u...
static bool containsByWord(const QString &candidate, const QString &words, Qt::CaseSensitivity sensitivity=Qt::CaseInsensitive)
Given a candidate string, returns true if the candidate contains all the individual words from anothe...
static QString insertLinks(const QString &string, bool *foundLinks=nullptr)
Returns a string with any URL (e.g., http(s)/ftp) and mailto: text converted to valid HTML <a ....
static double fuzzyScore(const QString &candidate, const QString &search)
Tests a candidate string to see how likely it is a match for a specified search string.
static QString qRegExpEscape(const QString &string)
Returns an escaped string matching the behavior of QRegExp::escape.
static QString ampersandEncode(const QString &string)
Makes a raw string safe for inclusion as a HTML/XML string literal.
static QString wordWrap(const QString &string, int length, bool useMaxLineLength=true, const QString &customDelimiter=QString())
Automatically wraps a string by inserting new line characters at appropriate locations in the string.
static bool isUrl(const QString &string)
Returns whether the string is a URL (http,https,ftp,file).
static QString truncateMiddleOfString(const QString &string, int maxLength)
Truncates a string to the specified maximum character length.
static QHash< QString, QString > createUnaccentMap()
Generates the unaccent mapping table (auto-generated by script at build time).
QMap< QString, QString > QgsStringMap