mirror of
https://github.com/Mudlet/Mudlet
synced 2026-08-13 18:26:27 -04:00
<!-- Keep the title short & concise so anyone non-technical can
understand it,
the title appears in PTB changelogs -->
#### Brief overview of PR changes/additions
Mudlet was only able to display entities with only one Latin1 character
in normal mud output.
This fix removes this restriction and also enables the use of special
characters represented by MXP default entities.
#### Motivation for adding to Mudlet
Improve MXP compliance
#### Other info (issues closed, discussion etc)
The patch changes small tidbits in several places: TBuffer was not able
to add additional characters to an input line, also the inserted entity
content must be reparsed to see if an MXP element is contained or to
interprete any non-Latin1 encoding while not risking a deadlock by
trying to resolve a recursive entity definition. This also required a
way for the entity resolver if a given entity is custom, default, or
unknown.
There are some screenshots and remarks at the end of
https://forums.mudlet.org/viewtopic.php?f=7&t=23206&start=10 .
Also, you can see how this works by connection to aldebaran-mud.de login
as a guest char (hit y to confirm) then "set mxp test 5", "set mxp test
6" or, for insights: "set mxp test 5 source", "set mxp test 6 source"
85 lines
2 KiB
C++
85 lines
2 KiB
C++
#include <TEntityHandler.h>
|
|
#include <QtTest/QtTest>
|
|
|
|
class TEntityHandlerTest : public QObject {
|
|
Q_OBJECT
|
|
|
|
private:
|
|
|
|
private slots:
|
|
|
|
void initTestCase()
|
|
{
|
|
}
|
|
|
|
void testHandleSimpleString()
|
|
{
|
|
TEntityHandler handler;
|
|
|
|
std::string str = "Someone says "Hello"";
|
|
QString result = processString(handler, str);
|
|
|
|
QCOMPARE(result, "Someone says \"Hello\"");
|
|
}
|
|
|
|
void testHandleUnfinishedString()
|
|
{
|
|
TEntityHandler handler;
|
|
|
|
std::string str = "Someone says "Hello&qu";
|
|
QString result = processString(handler, str);
|
|
|
|
QCOMPARE(result, "Someone says \"Hello");
|
|
}
|
|
|
|
void testLongSequence()
|
|
{
|
|
TEntityHandler handler;
|
|
|
|
std::string str = "Long sequence: &01234567; asdf";
|
|
QString result = processString(handler, str);
|
|
|
|
QCOMPARE(result, "Long sequence: &01234567; asdf");
|
|
}
|
|
|
|
void testHandleSplitInTwoParts()
|
|
{
|
|
TEntityHandler handler;
|
|
|
|
std::string part1 = "Someone says "Hello&qu";
|
|
QString result1 = processString(handler, part1);
|
|
QCOMPARE(result1, "Someone says \"Hello");
|
|
|
|
std::string part2 = "ot; to you";
|
|
QString result2 = processString(handler, part2);
|
|
QCOMPARE(result2, "\" to you");
|
|
|
|
QString result = result1 + result2;
|
|
|
|
qDebug() << result1;
|
|
qDebug() << result2;
|
|
qDebug() << result;
|
|
|
|
QCOMPARE(result, "Someone says \"Hello\" to you");
|
|
}
|
|
|
|
inline static QString processString(TEntityHandler& handler, std::string& str)
|
|
{
|
|
size_t len = str.length();
|
|
QString result;
|
|
for (size_t i = 0; i < len; i++) {
|
|
if (!handler.handle(str[i], true)) {
|
|
result += str[i];
|
|
} else if (handler.isEntityResolved()) {
|
|
result += handler.getResultAndReset();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void cleanupTestCase()
|
|
{
|
|
}
|
|
};
|
|
#include "TEntityHandlerTest.moc"
|
|
QTEST_MAIN(TEntityHandlerTest)
|