16 #include "qgis_core.h"
20 #include <QRegularExpression>
22 #include <QDomDocument>
25 #ifndef QGSSTRINGUTILS_H
26 #define QGSSTRINGUTILS_H
28 #define FUZZY_SCORE_WORD_MATCH 5
29 #define FUZZY_SCORE_NEW_MATCH 3
30 #define FUZZY_SCORE_CONSECUTIVE_MATCH 4
52 const QString &replacement,
53 bool caseSensitive =
false,
54 bool wholeWordOnly =
false );
57 QString
match()
const {
return mMatch; }
73 QString process(
const QString &input )
const;
77 return mMatch == other.mMatch
78 && mReplacement == other.mReplacement
79 && mCaseSensitive == other.mCaseSensitive
80 && mWholeWordOnly == other.mWholeWordOnly;
105 QRegularExpression mRx;
126 : mReplacements( replacements )
133 QList< QgsStringReplacement >
replacements()
const {
return mReplacements; }
143 mReplacements = replacements;
153 QString process(
const QString &input )
const;
161 void writeXml( QDomElement &elem, QDomDocument &doc )
const;
168 void readXml(
const QDomElement &elem );
172 QList< QgsStringReplacement > mReplacements;
191 MixedCase = QFont::MixedCase,
192 AllUppercase = QFont::AllUppercase,
193 AllLowercase = QFont::AllLowercase,
194 ForceFirstLetterToCapital = QFont::Capitalize,
195 TitleCase = QFont::Capitalize + 1000,
196 UpperCamelCase = QFont::Capitalize + 1001,
206 static QString capitalize(
const QString &
string, Capitalization capitalization );
216 static QString ampersandEncode(
const QString &
string );
227 static int levenshteinDistance(
const QString &string1,
const QString &string2,
bool caseSensitive =
false );
238 static QString longestCommonSubstring(
const QString &string1,
const QString &string2,
bool caseSensitive =
false );
249 static int hammingDistance(
const QString &string1,
const QString &string2,
bool caseSensitive =
false );
257 static QString soundex(
const QString &
string );
268 static double fuzzyScore(
const QString &candidate,
const QString &search );
278 static QString insertLinks(
const QString &
string,
bool *foundLinks =
nullptr );
286 static bool isUrl(
const QString &
string );
300 static QString wordWrap(
const QString &
string,
int length,
bool useMaxLineLength =
true,
const QString &customDelimiter = QString() );
308 static QString substituteVerticalCharacters( QString
string );
316 static QString htmlToMarkdown(
const QString &html );
324 static QString qRegExpEscape(
const QString &
string );
335 static QString truncateMiddleOfString(
const QString &
string,
int maxLength );
A collection of string replacements (specified using QgsStringReplacement objects).
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.
QString match() const
Returns the string matched by this object.
bool operator==(const QgsStringReplacement &other)
Utility functions for working with strings.
Capitalization
Capitalization options.
QMap< QString, QString > QgsStringMap