File indexing completed on 2024-05-12 17:13:29
0001 #include <QtCore/QString> 0002 #include <QtCore/QRegularExpression> 0003 0004 void test() 0005 { 0006 if (QString("abc").contains(QRegularExpression("[a-z]"))) { // Warn 0007 } 0008 0009 QString h = "hello"; 0010 auto c = h.indexOf(QRegularExpression("[hel]"), 0); // Warn 0011 0012 QRegularExpression e("[a-z]"); 0013 auto r = h.indexOf(e); // Warn 0014 0015 static const QRegularExpression staticRegex("[a-z]"); 0016 auto nr = h.indexOf(staticRegex); // Ok 0017 0018 bool empty = QString().isEmpty(); 0019 0020 h.lastIndexOf(QRegularExpression("[hel]")); // Warn 0021 h.lastIndexOf(e); // Warn 0022 h.lastIndexOf(staticRegex); // Ok 0023 0024 h.count(QRegularExpression("[hel]")); // Warn 0025 h.count(e); // Warn 0026 h.count(staticRegex); // Ok 0027 0028 h.replace(QRegularExpression("[hel]"), QString()); // Warn 0029 h.replace(e, QString()); // Warn 0030 h.replace(staticRegex, QString()); // Ok 0031 0032 h.remove(QRegularExpression("[hel]")); // Warn 0033 h.remove(e); // Warn 0034 h.remove(staticRegex); // Ok 0035 0036 h.section(QRegularExpression("[hel]"), 0); // Warn 0037 h.section(e, 0); // Warn 0038 h.section(staticRegex, 0); // Ok 0039 0040 h.split(QRegularExpression("[hel]")); // Warn 0041 h.split(e); // Warn 0042 h.split(staticRegex); // Ok 0043 0044 h.splitRef(QRegularExpression("[hel]")); // Warn 0045 h.splitRef(e); // Warn 0046 h.splitRef(staticRegex); // Ok 0047 0048 QStringList strList; 0049 0050 strList.indexOf(e); // Warn 0051 strList.indexOf(staticRegex); 0052 0053 strList.lastIndexOf(e); // Warn 0054 strList.lastIndexOf(staticRegex); // Ok 0055 0056 QString regexStr = "[abc]"; 0057 h.contains(QRegularExpression(regexStr)); // Warn 0058 0059 { 0060 QRegularExpression reg(regexStr); 0061 h.contains(reg); // Warn 0062 } 0063 { 0064 static const QRegularExpression reg(regexStr); 0065 h.contains(reg); // Ok 0066 } 0067 } 0068 0069 void test1(const QString& regex, QString toCheck) 0070 { 0071 QRegularExpression re(regex); 0072 toCheck.contains(re); // Ok 0073 } 0074 0075 void test2(const QStringList& regexes, QString toCheck) 0076 { 0077 for (const auto& regix : regexes) { 0078 toCheck.contains(QRegularExpression(regix)); // Ok, no warn 0079 } 0080 } 0081 0082 void test_nocrash() 0083 { 0084 QRegularExpression re; 0085 QString s; 0086 s.contains(re); 0087 } 0088 0089 #include <QtCore/QVariant> 0090 void test_qregexmatch(QString selectedText) 0091 { 0092 QRegularExpression weekRE("(?<week>"); 0093 auto match1 = weekRE.match(selectedText); 0094 auto match2 = weekRE.globalMatch(selectedText); 0095 0096 auto m1 = QRegularExpression("[123]").match(selectedText); 0097 auto m2 = QRegularExpression("[123]").globalMatch(selectedText); 0098 0099 QVariant v; 0100 v.toRegularExpression().match(selectedText); // No Warn 0101 } 0102 0103 extern QString someText(); 0104 void test_qregexmatch_rvalueString(QString s) 0105 { 0106 // XValue + RValue arg 0107 QString text; 0108 QRegularExpression(someText()).match(text); // Ok 0109 0110 // LValue + RValue arg 0111 QRegularExpression re(someText()); 0112 re.match(text); 0113 0114 QRegularExpression re1("^" + someText()); 0115 re1.match(text); 0116 0117 QRegularExpression re2("^" + s); 0118 re2.match(text); 0119 0120 QRegularExpression re3((QString(s))); 0121 re3.match(text); 0122 }