1 /**************************************************************************** 2 ** 3 ** DQt - D bindings for the Qt Toolkit 4 ** 5 ** GNU Lesser General Public License Usage 6 ** This file may be used under the terms of the GNU Lesser 7 ** General Public License version 3 as published by the Free Software 8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 9 ** packaging of this file. Please review the following information to 10 ** ensure the GNU Lesser General Public License version 3 requirements 11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 12 ** 13 ****************************************************************************/ 14 module qt.core.regularexpression; 15 extern(C++): 16 17 import qt.config; 18 import qt.core.flags; 19 import qt.core.metatype; 20 import qt.core.shareddata; 21 import qt.core.string; 22 import qt.core.stringlist; 23 import qt.core.stringview; 24 import qt.core.typeinfo; 25 import qt.helpers; 26 27 /+ QT_REQUIRE_CONFIG(regularexpression); 28 29 30 class QStringList; 31 class QLatin1String; 32 33 class QRegularExpressionMatch; 34 class QRegularExpressionMatchIterator; +/ 35 struct QRegularExpressionPrivate; 36 /+ class QRegularExpression; 37 38 Q_CORE_EXPORT uint qHash(const QRegularExpression &key, uint seed = 0) noexcept; +/ 39 40 @Q_MOVABLE_TYPE @(QMetaType.Type.QRegularExpression) extern(C++, class) struct /+ Q_CORE_EXPORT +/ QRegularExpression 41 { 42 public: 43 enum PatternOption { 44 NoPatternOption = 0x0000, 45 CaseInsensitiveOption = 0x0001, 46 DotMatchesEverythingOption = 0x0002, 47 MultilineOption = 0x0004, 48 ExtendedPatternSyntaxOption = 0x0008, 49 InvertedGreedinessOption = 0x0010, 50 DontCaptureOption = 0x0020, 51 UseUnicodePropertiesOption = 0x0040, 52 OptimizeOnFirstUsageOption /+ Q_DECL_ENUMERATOR_DEPRECATED_X("This option does not have any effect since Qt 5.12") +/ = 0x0080, 53 DontAutomaticallyOptimizeOption /+ Q_DECL_ENUMERATOR_DEPRECATED_X("This option does not have any effect since Qt 5.12") +/ = 0x0100, 54 } 55 /+ Q_DECLARE_FLAGS(PatternOptions, PatternOption) +/ 56 alias PatternOptions = QFlags!(PatternOption); 57 PatternOptions patternOptions() const; 58 void setPatternOptions(PatternOptions options); 59 60 @disable this(); 61 pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this)))) 62 ref typeof(this) rawConstructor(); 63 static typeof(this) create() 64 { 65 typeof(this) r = typeof(this).init; 66 r.rawConstructor(); 67 return r; 68 } 69 70 /+ explicit +/this(ref const(QString) pattern, PatternOptions options = PatternOption.NoPatternOption); 71 @disable this(this); 72 this(ref const(QRegularExpression) re); 73 ~this(); 74 /+ref QRegularExpression operator =(ref const(QRegularExpression) re);+/ 75 /+ QRegularExpression &operator=(QRegularExpression &&re) noexcept 76 { d.swap(re.d); return *this; } +/ 77 78 /+ void swap(QRegularExpression &other) noexcept { d.swap(other.d); } +/ 79 80 QString pattern() const; 81 void setPattern(ref const(QString) pattern); 82 83 bool isValid() const; 84 int patternErrorOffset() const; 85 QString errorString() const; 86 87 int captureCount() const; 88 QStringList namedCaptureGroups() const; 89 90 enum MatchType { 91 NormalMatch = 0, 92 PartialPreferCompleteMatch, 93 PartialPreferFirstMatch, 94 NoMatch 95 } 96 97 enum MatchOption { 98 NoMatchOption = 0x0000, 99 AnchoredMatchOption = 0x0001, 100 DontCheckSubjectStringMatchOption = 0x0002 101 } 102 /+ Q_DECLARE_FLAGS(MatchOptions, MatchOption) +/ 103 alias MatchOptions = QFlags!(MatchOption); 104 QRegularExpressionMatch match(ref const(QString) subject, 105 int offset = 0, 106 MatchType matchType = MatchType.NormalMatch, 107 MatchOptions matchOptions = MatchOption.NoMatchOption) const; 108 109 QRegularExpressionMatch match(ref const(QStringRef) subjectRef, 110 int offset = 0, 111 MatchType matchType = MatchType.NormalMatch, 112 MatchOptions matchOptions = MatchOption.NoMatchOption) const; 113 114 pragma(inline, true) QRegularExpressionMatch match(QStringView subject, 115 int offset = 0, 116 MatchType matchType = MatchType.NormalMatch, 117 MatchOptions matchOptions = MatchOption.NoMatchOption) const 118 /+ 119 pragma(inline, true) QRegularExpressionMatch match(QStringView subject, int offset, 120 QRegularExpression.MatchType matchType, MatchOptions matchOptions) const+/ 121 { 122 auto tmp = subject.toString(); return match(tmp, offset, matchType, matchOptions); 123 } 124 125 QRegularExpressionMatchIterator globalMatch(ref const(QString) subject, 126 int offset = 0, 127 MatchType matchType = MatchType.NormalMatch, 128 MatchOptions matchOptions = MatchOption.NoMatchOption) const; 129 130 QRegularExpressionMatchIterator globalMatch(ref const(QStringRef) subjectRef, 131 int offset = 0, 132 MatchType matchType = MatchType.NormalMatch, 133 MatchOptions matchOptions = MatchOption.NoMatchOption) const; 134 135 pragma(inline, true) QRegularExpressionMatchIterator globalMatch(QStringView subject, 136 int offset = 0, 137 MatchType matchType = MatchType.NormalMatch, 138 MatchOptions matchOptions = MatchOption.NoMatchOption) const 139 /+ 140 pragma(inline, true) QRegularExpressionMatchIterator globalMatch(QStringView subject, int offset, 141 QRegularExpression.MatchType matchType, MatchOptions matchOptions) const+/ 142 { 143 auto tmp = subject.toString(); return globalMatch(tmp, offset, matchType, matchOptions); 144 } 145 146 void optimize() const; 147 148 static if(QT_STRINGVIEW_LEVEL < 2) 149 { 150 static QString escape(ref const(QString) str); 151 static QString wildcardToRegularExpression(ref const(QString) str); 152 pragma(inline, true) static QString anchoredPattern(ref const(QString) expression) 153 { 154 return anchoredPattern(QStringView(expression)); 155 } 156 } 157 158 static QString escape(QStringView str); 159 static QString wildcardToRegularExpression(QStringView str); 160 static QString anchoredPattern(QStringView expression); 161 162 /+bool operator ==(ref const(QRegularExpression) re) const;+/ 163 /+pragma(inline, true) bool operator !=(ref const(QRegularExpression) re) const { return !operator==(re); }+/ 164 165 private: 166 /+ friend struct QRegularExpressionPrivate; +/ 167 /+ friend class QRegularExpressionMatch; +/ 168 /+ friend struct QRegularExpressionMatchPrivate; +/ 169 /+ friend class QRegularExpressionMatchIterator; +/ 170 /+ friend Q_CORE_EXPORT uint qHash(const QRegularExpression &key, uint seed) noexcept; +/ 171 172 this(ref QRegularExpressionPrivate dd); 173 QExplicitlySharedDataPointer!(QRegularExpressionPrivate) d; 174 } 175 /+pragma(inline, true) QFlags!(QRegularExpression.PatternOptions.enum_type) operator |(QRegularExpression.PatternOptions.enum_type f1, QRegularExpression.PatternOptions.enum_type f2)/+noexcept+/{return QFlags!(QRegularExpression.PatternOptions.enum_type)(f1)|f2;}+/ 176 /+pragma(inline, true) QFlags!(QRegularExpression.PatternOptions.enum_type) operator |(QRegularExpression.PatternOptions.enum_type f1, QFlags!(QRegularExpression.PatternOptions.enum_type) f2)/+noexcept+/{return f2|f1;}+/ 177 /+pragma(inline, true) QIncompatibleFlag operator |(QRegularExpression.PatternOptions.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/ 178 179 /+ Q_DECLARE_SHARED(QRegularExpression) 180 Q_DECLARE_OPERATORS_FOR_FLAGS(QRegularExpression::PatternOptions) +/ 181 /+pragma(inline, true) QFlags!(QRegularExpression.MatchOptions.enum_type) operator |(QRegularExpression.MatchOptions.enum_type f1, QRegularExpression.MatchOptions.enum_type f2)/+noexcept+/{return QFlags!(QRegularExpression.MatchOptions.enum_type)(f1)|f2;}+/ 182 /+pragma(inline, true) QFlags!(QRegularExpression.MatchOptions.enum_type) operator |(QRegularExpression.MatchOptions.enum_type f1, QFlags!(QRegularExpression.MatchOptions.enum_type) f2)/+noexcept+/{return f2|f1;}+/ 183 /+pragma(inline, true) QIncompatibleFlag operator |(QRegularExpression.MatchOptions.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/ 184 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QRegularExpression::MatchOptions) 185 #ifndef QT_NO_DATASTREAM 186 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &out, const QRegularExpression &re); 187 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &in, QRegularExpression &re); 188 #endif 189 190 #ifndef QT_NO_DEBUG_STREAM 191 Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QRegularExpression &re); 192 Q_CORE_EXPORT QDebug operator<<(QDebug debug, QRegularExpression::PatternOptions patternOptions); 193 #endif +/ 194 195 struct QRegularExpressionMatchPrivate; 196 197 @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QRegularExpressionMatch 198 { 199 public: 200 @disable this(); 201 pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this)))) 202 ref typeof(this) rawConstructor(); 203 static typeof(this) create() 204 { 205 typeof(this) r = typeof(this).init; 206 r.rawConstructor(); 207 return r; 208 } 209 210 ~this(); 211 @disable this(this); 212 this(ref const(QRegularExpressionMatch) match); 213 /+ref QRegularExpressionMatch operator =(ref const(QRegularExpressionMatch) match);+/ 214 /+ QRegularExpressionMatch &operator=(QRegularExpressionMatch &&match) noexcept 215 { d.swap(match.d); return *this; } +/ 216 /+ void swap(QRegularExpressionMatch &other) noexcept { d.swap(other.d); } +/ 217 218 QRegularExpression regularExpression() const; 219 QRegularExpression.MatchType matchType() const; 220 QRegularExpression.MatchOptions matchOptions() const; 221 222 bool hasMatch() const; 223 bool hasPartialMatch() const; 224 225 bool isValid() const; 226 227 int lastCapturedIndex() const; 228 229 QString captured(int nth = 0) const; 230 QStringRef capturedRef(int nth = 0) const; 231 QStringView capturedView(int nth = 0) const; 232 233 static if(QT_STRINGVIEW_LEVEL < 2) 234 { 235 QString captured(ref const(QString) name) const; 236 QStringRef capturedRef(ref const(QString) name) const; 237 } 238 239 QString captured(QStringView name) const; 240 QStringRef capturedRef(QStringView name) const; 241 QStringView capturedView(QStringView name) const; 242 243 QStringList capturedTexts() const; 244 245 int capturedStart(int nth = 0) const; 246 int capturedLength(int nth = 0) const; 247 int capturedEnd(int nth = 0) const; 248 249 static if(QT_STRINGVIEW_LEVEL < 2) 250 { 251 int capturedStart(ref const(QString) name) const; 252 int capturedLength(ref const(QString) name) const; 253 int capturedEnd(ref const(QString) name) const; 254 } 255 256 int capturedStart(QStringView name) const; 257 int capturedLength(QStringView name) const; 258 int capturedEnd(QStringView name) const; 259 260 private: 261 /+ friend class QRegularExpression; +/ 262 /+ friend struct QRegularExpressionMatchPrivate; +/ 263 /+ friend class QRegularExpressionMatchIterator; +/ 264 265 this(ref QRegularExpressionMatchPrivate dd); 266 QSharedDataPointer!(QRegularExpressionMatchPrivate) d; 267 } 268 269 /+ Q_DECLARE_SHARED(QRegularExpressionMatch) 270 271 #ifndef QT_NO_DEBUG_STREAM 272 Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QRegularExpressionMatch &match); 273 #endif +/ 274 275 struct QRegularExpressionMatchIteratorPrivate; 276 277 @Q_MOVABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QRegularExpressionMatchIterator 278 { 279 public: 280 @disable this(); 281 pragma(mangle, defaultConstructorMangling(__traits(identifier, typeof(this)))) 282 ref typeof(this) rawConstructor(); 283 static typeof(this) create() 284 { 285 typeof(this) r = typeof(this).init; 286 r.rawConstructor(); 287 return r; 288 } 289 290 ~this(); 291 @disable this(this); 292 this(ref const(QRegularExpressionMatchIterator) iterator); 293 /+ref QRegularExpressionMatchIterator operator =(ref const(QRegularExpressionMatchIterator) iterator);+/ 294 /+ QRegularExpressionMatchIterator &operator=(QRegularExpressionMatchIterator &&iterator) noexcept 295 { d.swap(iterator.d); return *this; } +/ 296 /+ void swap(QRegularExpressionMatchIterator &other) noexcept { d.swap(other.d); } +/ 297 298 bool isValid() const; 299 300 bool hasNext() const; 301 QRegularExpressionMatch next(); 302 QRegularExpressionMatch peekNext() const; 303 304 QRegularExpression regularExpression() const; 305 QRegularExpression.MatchType matchType() const; 306 QRegularExpression.MatchOptions matchOptions() const; 307 308 private: 309 /+ friend class QRegularExpression; +/ 310 311 this(ref QRegularExpressionMatchIteratorPrivate dd); 312 QSharedDataPointer!(QRegularExpressionMatchIteratorPrivate) d; 313 } 314 315 /+ Q_DECLARE_SHARED(QRegularExpressionMatchIterator) +/ 316 317