Ref T485 Update for efficient QString usage in CLogMessage:

- `debug()`, `warning()`, `error()` etc. overloaded on `const char16_t[]` to accept UTF-16 string literals.
- Overloads on `const char *` are deleted to avoid accidents.
- Message is stored as QString and/or QStringView depending which overload is used.
- The multiplexing between QString and QStringView is handled by a special value class, to keep the metaclass simple.
- QStringView does not have `arg()` method, so had to implement our own.
This commit is contained in:
Mat Sutcliffe
2018-12-23 17:12:16 +00:00
parent dd655bcb25
commit cba820cbce
5 changed files with 184 additions and 34 deletions

View File

@@ -28,6 +28,8 @@ namespace BlackMiscTest
private slots:
//! Status message
void statusMessage();
//! Message with arguments
void statusArgs();
};
void CTestStatusMessage::statusMessage()
@@ -48,6 +50,27 @@ namespace BlackMiscTest
cAssign = s2;
QVERIFY(cAssign.getMSecsSinceEpoch() == s2.getMSecsSinceEpoch());
}
void CTestStatusMessage::statusArgs()
{
auto s1 = CStatusMessage().info(u"literal percent: %1");
auto s2 = CStatusMessage().info(u"literal percent: %a");
auto s3 = CStatusMessage().info(u"literal percent: %");
auto s4 = CStatusMessage().info(u"literal percent: %%");
auto s5 = CStatusMessage().info(u"literal percents: %%%");
auto s6 = CStatusMessage().info(u"will be expanded: %1%2") << "foo" << "bar";
auto s7 = CStatusMessage().info(u"will be expanded: %1+%2") << "foo" << "bar";
auto s8 = CStatusMessage().info(u"will be expanded: %012") << "foo";
QVERIFY(s1.getMessage() == "literal percent: %1");
QVERIFY(s2.getMessage() == "literal percent: %a");
QVERIFY(s3.getMessage() == "literal percent: %");
QVERIFY(s4.getMessage() == "literal percent: %");
QVERIFY(s5.getMessage() == "literal percents: %%");
QVERIFY(s6.getMessage() == "will be expanded: foobar");
QVERIFY(s7.getMessage() == "will be expanded: foo+bar");
QVERIFY(s8.getMessage() == "will be expanded: foo2");
}
} // namespace
//! main