/usr/include/qgis/qgsstringutils.h is in libqgis-dev 2.18.17+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | /***************************************************************************
qgsstringutils.h
----------------
begin : June 2015
copyright : (C) 2015 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QString>
#include <QRegExp>
#include <QList>
#include <QDomDocument>
#include <QFont> // for enum values
#include "qgis.h"
#ifndef QGSSTRINGUTILS_H
#define QGSSTRINGUTILS_H
/** \ingroup core
* \class QgsStringReplacement
* \brief A representation of a single string replacement.
* \note Added in version 3.0
*/
class CORE_EXPORT QgsStringReplacement
{
public:
/** Constructor for QgsStringReplacement.
* @param match string to match
* @param replacement string to replace match with
* @param caseSensitive set to true for a case sensitive match
* @param wholeWordOnly set to true to match complete words only, or false to allow partial word matches
*/
QgsStringReplacement( const QString& match,
const QString& replacement,
bool caseSensitive = false,
bool wholeWordOnly = false );
//! Returns the string matched by this object
QString match() const { return mMatch; }
//! Returns the string to replace matches with
QString replacement() const { return mReplacement; }
//! Returns true if match is case sensitive
bool caseSensitive() const { return mCaseSensitive; }
//! Returns true if match only applies to whole words, or false if partial word matches are permitted
bool wholeWordOnly() const { return mWholeWordOnly; }
/** Processes a given input string, applying any valid replacements which should be made.
* @param input input string
* @returns input string with any matches replaced by replacement string
*/
QString process( const QString& input ) const;
bool operator==( const QgsStringReplacement& other )
{
return mMatch == other.mMatch
&& mReplacement == other.mReplacement
&& mCaseSensitive == other.mCaseSensitive
&& mWholeWordOnly == other.mWholeWordOnly;
}
/** Returns a map of the replacement properties.
* @see fromProperties()
*/
QgsStringMap properties() const;
/** Creates a new QgsStringReplacement from an encoded properties map.
* @see properties()
*/
static QgsStringReplacement fromProperties( const QgsStringMap& properties );
private:
QString mMatch;
QString mReplacement;
bool mCaseSensitive;
bool mWholeWordOnly;
QRegExp mRx;
};
/** \ingroup core
* \class QgsStringReplacementCollection
* \brief A collection of string replacements (specified using QgsStringReplacement objects).
* \note Added in version 3.0
*/
class CORE_EXPORT QgsStringReplacementCollection
{
public:
/** Constructor for QgsStringReplacementCollection
* @param replacements initial list of string replacements
*/
QgsStringReplacementCollection( const QList< QgsStringReplacement >& replacements = QList< QgsStringReplacement >() )
: mReplacements( replacements )
{}
/** Returns the list of string replacements in this collection.
* @see setReplacements()
*/
QList< QgsStringReplacement > replacements() const { return mReplacements; }
/** Sets the list of string replacements in this collection.
* @param replacements list of string replacements to apply. Replacements are applied in the
* order they are specified here.
* @see replacements()
*/
void setReplacements( const QList< QgsStringReplacement >& replacements )
{
mReplacements = replacements;
}
/** Processes a given input string, applying any valid replacements which should be made
* using QgsStringReplacement objects contained by this collection. Replacements
* are made in order of the QgsStringReplacement objects contained in the collection.
* @param input input string
* @returns input string with any matches replaced by replacement string
*/
QString process( const QString& input ) const;
/** Writes the collection state to an XML element.
* @param elem target DOM element
* @param doc DOM document
* @see readXml()
*/
void writeXml( QDomElement& elem, QDomDocument& doc ) const;
/** Reads the collection state from an XML element.
* @param elem DOM element
* @see writeXml()
*/
void readXml( const QDomElement& elem );
private:
QList< QgsStringReplacement > mReplacements;
};
/** \ingroup core
* \class QgsStringUtils
* \brief Utility functions for working with strings.
* \note Added in version 2.11
*/
class CORE_EXPORT QgsStringUtils
{
public:
//! Capitalization options
enum Capitalization
{
MixedCase = QFont::MixedCase, //!< Mixed case, ie no change
AllUppercase = QFont::AllUppercase, //!< Convert all characters to uppercase
AllLowercase = QFont::AllLowercase, //!< Convert all characters to lowercase
ForceFirstLetterToCapital = QFont::Capitalize, //!< Convert just the first letter of each word to uppercase, leave the rest untouched
};
/** Converts a string by applying capitalization rules to the string.
* @param string input string
* @param capitalization capitalization type to apply
* @return capitalized string
* @note added in QGIS 2.18
*/
static QString capitalize( const QString& string, Capitalization capitalization );
/** 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.
* @param string1 first string
* @param string2 second string
* @param caseSensitive set to true for case sensitive comparison
* @returns edit distance. Lower distances indicate more similar strings.
*/
static int levenshteinDistance( const QString &string1, const QString &string2, bool caseSensitive = false );
/** Returns the longest common substring between two strings. This substring is the longest
* string that is a substring of the two input strings. Eg, the longest common substring
* of "ABABC" and "BABCA" is "ABC".
* @param string1 first string
* @param string2 second string
* @param caseSensitive set to true for case sensitive comparison
* @returns longest common substring
*/
static QString longestCommonSubstring( const QString &string1, const QString &string2, bool caseSensitive = false );
/** 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.
* @param string1 first string
* @param string2 second string
* @param caseSensitive set to true for case sensitive comparison
* @returns Hamming distance between strings, or -1 if strings are different lengths.
*/
static int hammingDistance( const QString &string1, const QString &string2, bool caseSensitive = false );
/** 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.
* @param string input string
* @returns 4 letter Soundex code
*/
static QString soundex( const QString &string );
/** Returns a string with any URL (eg http(s)/ftp) and mailto: text converted to valid HTML <a ...>
* links.
* @param string string to insert links into
* @param foundLinks if specified, will be set to true if any links were inserted into the string
* @returns string with inserted links
* @note added in QGIS 2.18
*/
static QString insertLinks( const QString& string, bool* foundLinks = nullptr );
};
#endif //QGSSTRINGUTILS_H
|