QGIS API Documentation  3.0.2-Girona (307d082)
Public Types | Static Public Member Functions | List of all members
QgsStringUtils Class Reference

Utility functions for working with strings. More...

#include <qgsstringutils.h>

Public Types

enum  Capitalization { MixedCase = QFont::MixedCase, AllUppercase = QFont::AllUppercase, AllLowercase = QFont::AllLowercase, ForceFirstLetterToCapital = QFont::Capitalize }
 Capitalization options. More...
 

Static Public Member Functions

static QString capitalize (const QString &string, Capitalization capitalization)
 Converts a string by applying capitalization rules to the string. More...
 
static int hammingDistance (const QString &string1, const QString &string2, bool caseSensitive=false)
 Returns the Hamming distance between two strings. More...
 
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 ...> links. More...
 
static int levenshteinDistance (const QString &string1, const QString &string2, bool caseSensitive=false)
 Returns the Levenshtein edit distance between two strings. More...
 
static QString longestCommonSubstring (const QString &string1, const QString &string2, bool caseSensitive=false)
 Returns the longest common substring between two strings. More...
 
static QString soundex (const QString &string)
 Returns the Soundex representation of a string. More...
 

Detailed Description

Utility functions for working with strings.

Since
QGIS 2.11

Definition at line 180 of file qgsstringutils.h.

Member Enumeration Documentation

◆ Capitalization

Capitalization options.

Enumerator
MixedCase 

Mixed case, ie no change.

AllUppercase 

Convert all characters to uppercase.

AllLowercase 

Convert all characters to lowercase.

ForceFirstLetterToCapital 

Convert just the first letter of each word to uppercase, leave the rest untouched.

Definition at line 185 of file qgsstringutils.h.

Member Function Documentation

◆ capitalize()

QString QgsStringUtils::capitalize ( const QString &  string,
QgsStringUtils::Capitalization  capitalization 
)
static

Converts a string by applying capitalization rules to the string.

Parameters
stringinput string
capitalizationcapitalization type to apply
Returns
capitalized string
Since
QGIS 3.0

Definition at line 22 of file qgsstringutils.cpp.

◆ hammingDistance()

int QgsStringUtils::hammingDistance ( const QString &  string1,
const QString &  string2,
bool  caseSensitive = false 
)
static

Returns the Hamming distance between two strings.

This equates to the number of characters at corresponding positions within the input strings where the characters are different. The input strings must be the same length.

Parameters
string1first string
string2second string
caseSensitiveset to true for case sensitive comparison
Returns
Hamming distance between strings, or -1 if strings are different lengths.

Definition at line 209 of file qgsstringutils.cpp.

◆ insertLinks()

QString QgsStringUtils::insertLinks ( const QString &  string,
bool *  foundLinks = nullptr 
)
static

Returns a string with any URL (e.g., http(s)/ftp) and mailto: text converted to valid HTML <a ...> links.

Parameters
stringstring to insert links into
foundLinksif specified, will be set to true if any links were inserted into the string
Returns
string with inserted links
Since
QGIS 3.0

Definition at line 343 of file qgsstringutils.cpp.

◆ levenshteinDistance()

int QgsStringUtils::levenshteinDistance ( const QString &  string1,
const QString &  string2,
bool  caseSensitive = false 
)
static

Returns the Levenshtein edit distance between two strings.

This equates to the minimum number of character edits (insertions, deletions or substitutions) required to change one string to another.

Parameters
string1first string
string2second string
caseSensitiveset to true for case sensitive comparison
Returns
edit distance. Lower distances indicate more similar strings.

Definition at line 64 of file qgsstringutils.cpp.

◆ longestCommonSubstring()

QString QgsStringUtils::longestCommonSubstring ( const QString &  string1,
const QString &  string2,
bool  caseSensitive = false 
)
static

Returns the longest common substring between two strings.

This substring is the longest string that is a substring of the two input strings. For example, the longest common substring of "ABABC" and "BABCA" is "ABC".

Parameters
string1first string
string2second string
caseSensitiveset to true for case sensitive comparison
Returns
longest common substring

Definition at line 146 of file qgsstringutils.cpp.

◆ soundex()

QString QgsStringUtils::soundex ( const QString &  string)
static

Returns the Soundex representation of a string.

Soundex is a phonetic matching algorithm, so strings with similar sounds should be represented by the same Soundex code.

Parameters
stringinput string
Returns
4 letter Soundex code

Definition at line 248 of file qgsstringutils.cpp.


The documentation for this class was generated from the following files: