forked from Mudlet/Mudlet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring/reimplementation of MXP support (Mudlet#3625)
Refactoring/reimplementation of MXP protocol Extracts MXP support from TBuffer Separates input parsing from protocol processing: input is parsed into MxpTag objects by the MxpNodeBuilder and are passed to be handled by the MxpTagProcessor Class hierarchy of MxpTagHandler for implementing support for each tag: allows for a clear separation of the implementation of each tag and makes it easier for adding support for new tags Defines a clear interface (MxpClient) separating the MXP implementation from other parts of the code Solves some limitations of previous implementation such as supporting element definitions not only for<SEND> tags, interpolating named and positional attributes and interpolating &text; placeholder by tag content Includes support for COLOR tag Handles FONT, U, I, B, VAR and !ENTITY tags, but so far no defined behavior (can be implemented in MxpMudlet) Attributes that hold MXP state are now in the Host class to avoid needless copies when TBuffer is copied around Introduces QtTests for some of the classes Other refactorings intended to simplify TBuffer class, extracting responbilities that aren't directly related to the buffer mgmt Extracted TEncodingTable from TBuffer, this class is responsible for mapping encoding names to tables. It also removes some bloat from TBuffer. TLinkStore to manage links and associated hints to be displayed. TEntityResolver to map character entities, such as > &Mudlet#32;   to their associated string values; supports interpolating strings replacing the entity placeholders by their values
- Loading branch information
Showing
72 changed files
with
5,491 additions
and
1,293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/*************************************************************************** | ||
* Copyright (C) 2020 by Gustavo Sousa - gustavocms@gmail.com * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program; if not, write to the * | ||
* Free Software Foundation, Inc., * | ||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | ||
***************************************************************************/ | ||
|
||
#include "MxpTag.h" | ||
#include "TMxpTagParser.h" | ||
|
||
const MxpTagAttribute& MxpStartTag::getAttribute(int attrIndex) const | ||
{ | ||
return getAttribute(mAttrsNames[attrIndex]); | ||
} | ||
|
||
const MxpTagAttribute& MxpStartTag::getAttribute(const QString& attrName) const | ||
{ | ||
const auto ptr = mAttrsMap.find(attrName.toUpper()); | ||
return *ptr; | ||
} | ||
|
||
const QString& MxpStartTag::getAttributeValue(int attrIndex) const | ||
{ | ||
return getAttribute(attrIndex).getValue(); | ||
} | ||
|
||
const QString& MxpStartTag::getAttributeValue(const QString& attrName) const | ||
{ | ||
return getAttribute(attrName).getValue(); | ||
} | ||
|
||
bool MxpStartTag::hasAttribute(const QString& attrName) const | ||
{ | ||
return mAttrsMap.contains(attrName.toUpper()); | ||
} | ||
|
||
bool MxpStartTag::isAttributeAt(const char* attrName, int attrIndex) | ||
{ | ||
return mAttrsNames[attrIndex].compare(attrName, Qt::CaseInsensitive) == 0; | ||
} | ||
|
||
bool MxpTag::isNamed(const QString& tagName) const | ||
{ | ||
return name.compare(tagName, Qt::CaseInsensitive) == 0; | ||
} | ||
|
||
QString MxpEndTag::toString() const | ||
{ | ||
QString result; | ||
result.append("</"); | ||
result.append(name); | ||
result.append(">"); | ||
return result; | ||
} | ||
|
||
QString MxpStartTag::toString() const | ||
{ | ||
QString result; | ||
result.append('<'); | ||
result.append(name); | ||
for (const auto& attrName : mAttrsNames) { | ||
result.append(' '); | ||
if (attrName.contains(" ") || attrName.contains("<")) { | ||
result.append('"'); | ||
result.append(attrName); | ||
result.append('"'); | ||
} else { | ||
result.append(attrName); | ||
} | ||
|
||
const auto& attr = getAttribute(attrName); | ||
if (attr.hasValue()) { | ||
result.append('='); | ||
|
||
const auto& val = attr.getValue(); | ||
result.append('"'); | ||
result.append(val); | ||
result.append('"'); | ||
} | ||
} | ||
|
||
if (mIsEmpty) { | ||
result.append(" /"); | ||
} | ||
|
||
result.append('>'); | ||
|
||
return result; | ||
} | ||
|
||
MxpStartTag MxpStartTag::transform(const MxpTagAttribute::Transformation& transformation) const | ||
{ | ||
QList<MxpTagAttribute> newAttrs; | ||
for (const auto& attr : mAttrsNames) { | ||
newAttrs.append(transformation(mAttrsMap[attr.toUpper()])); | ||
} | ||
|
||
return MxpStartTag(name, newAttrs, mIsEmpty); | ||
} | ||
|
||
const QString& MxpStartTag::getAttributeByNameOrIndex(const QString& attrName, int attrIndex, const QString& defaultValue) const | ||
{ | ||
if (hasAttribute(attrName)) | ||
return getAttributeValue(attrName); | ||
if (getAttributesCount() > attrIndex && !getAttribute(attrIndex).hasValue()) | ||
return getAttribute(attrIndex).getName(); | ||
|
||
return defaultValue; | ||
} | ||
|
||
const QString& MxpStartTag::getAttrName(int attrIndex) const | ||
{ | ||
return mAttrsNames[attrIndex]; | ||
} |
Oops, something went wrong.