19 #include <QTextDocument>     20 #include <QStringList>    21 #include <QTextBoundaryFinder>    25   if ( 
string.isEmpty() )
    28   switch ( capitalization )
    34       return string.toUpper();
    37       return string.toLower();
    43       QTextBoundaryFinder wordSplitter( QTextBoundaryFinder::Word, 
string.constData(), 
string.length(), 0, 0 );
    44       QTextBoundaryFinder letterSplitter( QTextBoundaryFinder::Grapheme, 
string.constData(), 
string.length(), 0, 0 );
    48 #if QT_VERSION >= 0x050000    49       while (( first && wordSplitter.
boundaryReasons() & QTextBoundaryFinder::StartOfItem )
    52       while (( first && wordSplitter.
boundaryReasons() & QTextBoundaryFinder::StartWord )
    72   int length1 = string1.
length();
    73   int length2 = string2.
length();
    89   const QChar* s1Char = s1.constData();
    90   const QChar* s2Char = s2.constData();
    93   int commonPrefixLen = 0;
    94   while ( length1 > 0 && length2 > 0 && *s1Char == *s2Char )
   104   while ( length1 > 0 && length2 > 0 && s1.at( commonPrefixLen + length1 - 1 ) == s2.at( commonPrefixLen + length2 - 1 ) )
   115   else if ( length2 == 0 )
   121   if ( length1 > length2 )
   124     qSwap( length1, length2 );
   129   col.
fill( 0, length2 + 1 );
   131   prevCol.
reserve( length2 + 1 );
   132   for ( 
int i = 0; i < length2 + 1; ++i )
   136   const QChar* s2start = s2Char;
   137   for ( 
int i = 0; i < length1; ++i )
   141     for ( 
int j = 0; j < length2; ++j )
   143       col[j + 1] = qMin( qMin( 1 + col[j], 1 + prevCol[1 + j] ), prevCol[j] + (( *s1Char == *s2Char ) ? 0 : 1 ) );
   149   return prevCol[length2];
   170   int* currentScores = 
new int [ s2.length()];
   171   int* previousScores = 
new int [ s2.length()];
   172   int maxCommonLength = 0;
   173   int lastMaxBeginIndex = 0;
   175   const QChar* s1Char = s1.constData();
   176   const QChar* s2Char = s2.constData();
   177   const QChar* s2Start = s2Char;
   179   for ( 
int i = 0; i < s1.length(); ++i )
   181     for ( 
int j = 0; j < s2.length(); ++j )
   183       if ( *s1Char != *s2Char )
   185         currentScores[j] = 0;
   189         if ( i == 0 || j == 0 )
   191           currentScores[j] = 1;
   195           currentScores[j] = 1 + previousScores[j - 1];
   198         if ( maxCommonLength < currentScores[j] )
   200           maxCommonLength = currentScores[j];
   201           lastMaxBeginIndex = i;
   206     qSwap( currentScores, previousScores );
   210   delete [] currentScores;
   211   delete [] previousScores;
   212   return string1.
mid( lastMaxBeginIndex - maxCommonLength + 1, maxCommonLength );
   240   const QChar* s1Char = s1.constData();
   241   const QChar* s2Char = s2.constData();
   243   for ( 
int i = 0; i < string1.
length(); ++i )
   245     if ( *s1Char != *s2Char )
   256   if ( 
string.isEmpty() )
   265   for ( 
int i = 0; i < tmp.
length(); ++i, ++char2 )
   267     if (( *char2 ).unicode() >= 0x41 && ( *char2 ).unicode() <= 0x5A && ( i == 0 || (( *char2 ).unicode() != 0x41 && ( *char2 ).unicode() != 0x45
   268         && ( *char2 ).unicode() != 0x48 && ( *char2 ).unicode() != 0x49
   269         && ( *char2 ).unicode() != 0x4F && ( *char2 ).unicode() != 0x55
   270         && ( *char2 ).unicode() != 0x57 && ( *char2 ).unicode() != 0x59 ) ) )
   281   for ( 
int i = 1; i < tmp.
length(); ++i, ++tmpChar )
   283     switch (( *tmpChar ).unicode() )
   328   for ( 
int i = 1; i < tmp.
length(); ++i, ++char2 )
   330     if ( *char2 != *char1 )
   355   static QRegExp urlRegEx( 
"(\\b(([\\w-]+://?|www[.])[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^!\"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_`{|}~\\s]|/))))" );
   356   static QRegExp protoRegEx( 
"^(?:f|ht)tps?://" );
   357   static QRegExp emailRegEx( 
"([\\w._%+-]+@[\\w.-]+\\.[A-Za-z]+)" );
   361   while ( urlRegEx.
indexIn( converted, offset ) != -1 )
   366     if ( protoRegEx.
indexIn( protoUrl ) == -1 )
   372     offset = urlRegEx.
pos( 1 ) + anchor.
length();
   375   while ( emailRegEx.
indexIn( converted, offset ) != -1 )
   381     offset = emailRegEx.
pos( 1 ) + anchor.
length();
   392     , mReplacement( replacement )
   393     , mCaseSensitive( caseSensitive )
   394     , mWholeWordOnly( wholeWordOnly )
   396   if ( mWholeWordOnly )
   398                    mCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive );
   404   if ( !mWholeWordOnly )
   406     return result.
replace( mMatch, mReplacement, mCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive );
   410     return result.
replace( mRx, mReplacement );
   417   map.
insert( 
"match", mMatch );
   418   map.
insert( 
"replace", mReplacement );
   419   map.
insert( 
"caseSensitive", mCaseSensitive ? 
"1" : 
"0" );
   420   map.
insert( 
"wholeWord", mWholeWordOnly ? 
"1" : 
"0" );
   427                                properties.
value( 
"replace" ),
   428                                properties.
value( 
"caseSensitive", 
"0" ) == 
"1",
   429                                properties.
value( 
"wholeWord", 
"0" ) == 
"1" );
   449     for ( ; it != props.
constEnd(); ++it )
   459   mReplacements.clear();
   461   for ( 
int i = 0;i < nodelist.
count(); i++ )
   467     for ( 
int j = 0; j < nodeMap.
count(); ++j )
 
static QString longestCommonSubstring(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the longest common substring between two strings. 
 
QDomNodeList elementsByTagName(const QString &tagname) const
 
QString cap(int nth) const
 
QString & append(QChar ch)
 
void truncate(int position)
 
QDomNode appendChild(const QDomNode &newChild)
 
A representation of a single string replacement. 
 
QString nodeValue() const
 
QString & prepend(QChar ch)
 
QVector< T > & fill(const T &value, int size)
 
const_iterator constBegin() const
 
static QString soundex(const QString &string)
Returns the Soundex representation of a string. 
 
void writeXml(QDomElement &elem, QDomDocument &doc) const
Writes the collection state to an XML element. 
 
QDomElement toElement() const
 
int indexIn(const QString &str, int offset, CaretMode caretMode) const
 
static QgsStringReplacement fromProperties(const QgsStringMap &properties)
Creates a new QgsStringReplacement from an encoded properties map. 
 
static QString capitalize(const QString &string, Capitalization capitalization)
Converts a string by applying capitalization rules to the string. 
 
void setAttribute(const QString &name, const QString &value)
 
const_iterator constEnd() const
 
void setPosition(int position)
 
static int levenshteinDistance(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the Levenshtein edit distance between two strings. 
 
Convert just the first letter of each word to uppercase, leave the rest untouched. 
 
Convert all characters to uppercase. 
 
Capitalization
Capitalization options. 
 
QgsStringMap properties() const
Returns a map of the replacement properties. 
 
QString & replace(int position, int n, QChar after)
 
QString process(const QString &input) const
Processes a given input string, applying any valid replacements which should be made. 
 
QString mid(int position, int n) const
 
Mixed case, ie no change. 
 
QString escape(const QString &plain)
 
void swap(QVector< T > &other)
 
iterator insert(const Key &key, const T &value)
 
Convert all characters to lowercase. 
 
void readXml(const QDomElement &elem)
Reads the collection state from an XML element. 
 
QString process(const QString &input) const
Processes a given input string, applying any valid replacements which should be made using QgsStringR...
 
BoundaryReasons boundaryReasons() const
 
QDomElement createElement(const QString &tagName)
 
QDomNode item(int index) const
 
QgsStringReplacement(const QString &match, const QString &replacement, bool caseSensitive=false, bool wholeWordOnly=false)
Constructor for QgsStringReplacement. 
 
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
 
static QString insertLinks(const QString &string, bool *foundLinks=nullptr)
Returns a string with any URL (eg http(s)/ftp) and mailto: text converted to valid HTML <a ...
 
static int hammingDistance(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the Hamming distance between two strings. 
 
QDomNode at(int index) const
 
const T value(const Key &key) const
 
QDomNamedNodeMap attributes() const