Skip to content

Commit b99671c

Browse files
QLoggingRegistry: don't use QTextStream for the QT_LOGGING_RULES env var
We can use the existing QStringView-based rules parser. Additionally, we can make this even better by avoiding the QString::replace() call and simply tokenize on the semi-colon character (';'). Change-Id: I89d3890da482fc684abafffdd56ec17cad908f21 Reviewed-by: Ivan Solovev <[email protected]>
1 parent c08766a commit b99671c

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/corelib/io/qloggingregistry.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ void QLoggingRule::parse(QStringView pattern)
152152
\internal
153153
Parses configuration from \a content.
154154
*/
155-
void QLoggingSettingsParser::setContent(QStringView content)
155+
void QLoggingSettingsParser::setContent(QStringView content, char16_t separator)
156156
{
157157
_rules.clear();
158-
for (auto line : qTokenize(content, u'\n'))
158+
for (auto line : qTokenize(content, separator))
159159
parseNextLine(line);
160160
}
161161

@@ -298,12 +298,11 @@ void QLoggingRegistry::initializeRules()
298298
if (qtLoggingDebug())
299299
debugMsg("Checking %s environment variable", "QT_LOGGING_RULES");
300300

301-
const QByteArray rulesSrc = qgetenv("QT_LOGGING_RULES").replace(';', '\n');
301+
const QString rulesSrc = qEnvironmentVariable("QT_LOGGING_RULES");
302302
if (!rulesSrc.isEmpty()) {
303-
QTextStream stream(rulesSrc);
304303
QLoggingSettingsParser parser;
305304
parser.setImplicitRulesSection(true);
306-
parser.setContent(stream);
305+
parser.setContent(rulesSrc, u';');
307306

308307
if (qtLoggingDebug())
309308
debugMsg("Loaded %td rules", static_cast<ptrdiff_t>(parser.rules().size()));

src/corelib/io/qloggingregistry_p.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class Q_AUTOTEST_EXPORT QLoggingSettingsParser
8181
public:
8282
void setImplicitRulesSection(bool inRulesSection) { m_inRulesSection = inRulesSection; }
8383

84-
void setContent(QStringView content);
84+
void setContent(QStringView content, char16_t separator = u'\n');
8585
void setContent(QTextStream &stream);
8686

8787
QList<QLoggingRule> rules() const { return _rules; }

0 commit comments

Comments
 (0)