Skip to content

Commit

Permalink
Enhance: fixes for CodeFactor
Browse files Browse the repository at this point in the history
Mainly the addition or removal of spaces...

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
  • Loading branch information
SlySven committed Apr 3, 2020
1 parent 54f287a commit 71afdc1
Show file tree
Hide file tree
Showing 25 changed files with 185 additions and 202 deletions.
2 changes: 1 addition & 1 deletion src/Host.cpp
Expand Up @@ -1003,7 +1003,7 @@ QPair<int, QString> Host::createStopWatch(const QString& name)
int newWatchId = 1;
while (mStopWatchMap.contains(newWatchId)) {
++newWatchId;
};
}

// It is hard to imagine a situation in which this will fail - so we won't
// bother coding for it:
Expand Down
4 changes: 2 additions & 2 deletions src/Host.h
Expand Up @@ -165,9 +165,9 @@ class Host : public QObject
QString & getPass() { QMutexLocker locker(& mLock); return mPass; }
void setPass(const QString& s ) { QMutexLocker locker(& mLock); mPass = s; }
int getRetries() { QMutexLocker locker(& mLock); return mRetries;}
void setRetries( int c ) { QMutexLocker locker(& mLock); mRetries=c; }
void setRetries( int c ) { QMutexLocker locker(& mLock); mRetries = c; }
int getTimeout() { QMutexLocker locker(& mLock); return mTimeout; }
void setTimeout( int seconds ) { QMutexLocker locker(& mLock); mTimeout=seconds; }
void setTimeout( int seconds ) { QMutexLocker locker(& mLock); mTimeout = seconds; }
bool wideAmbiguousEAsianGlyphs() { QMutexLocker locker(& mLock); return mWideAmbigousWidthGlyphs; }
// Uses PartiallyChecked to set the automatic mode, otherwise Checked/Unchecked means use wide/narrow ambiguous glyphs
void setWideAmbiguousEAsianGlyphs(Qt::CheckState state );
Expand Down
11 changes: 1 addition & 10 deletions src/T2DMap.cpp
Expand Up @@ -3435,16 +3435,7 @@ void T2DMap::slot_userAction(QString uniqueName)
event.mArgumentTypeList.append(ARGUMENT_TYPE_NUMBER);
}
mpHost->raiseEvent(event);
}
// Unreachable code as had effectively the same test as the previous "if"
// mMultiSelectionList is now mMultiSelectionSet:
// else if( mMultiSelectionList.size() > 0 )
// {
// event.mArgumentList.append(QString::number(mMultiSelectionList[0]));
// event.mArgumentTypeList.append(ARGUMENT_TYPE_NUMBER);
// mpHost->raiseEvent( & event );
// }
else {
} else {
event.mArgumentList.append(uniqueName);
event.mArgumentTypeList.append(ARGUMENT_TYPE_STRING);
for (int i = 0; i < userEvent.size(); i++) {
Expand Down
15 changes: 6 additions & 9 deletions src/TBuffer.cpp
Expand Up @@ -1094,7 +1094,7 @@ void TBuffer::translateToPlainText(std::string& incoming, const bool isFromServe
continue;
}

if (spanEnd >= localBufferLength || cParameter.indexOf(localBuffer[spanEnd]) >=0) {
if (spanEnd >= localBufferLength || cParameter.indexOf(localBuffer[spanEnd]) >= 0) {
// We have gone to the end of the buffer OR the last character
// in the buffer is still within a CSI sequence - therefore we
// have got a split between data packets and are not in a
Expand Down Expand Up @@ -1540,8 +1540,7 @@ void TBuffer::translateToPlainText(std::string& incoming, const bool isFromServe
_tl[i].replace("|", "");
if (_element.name == "A") {
_tl[i] = "openUrl([[" + _tl[i] + "]])";
}
else if (!_send_to_command_line) {
} else if (!_send_to_command_line) {
_tl[i] = "send([[" + _tl[i] + "]])";
} else {
_tl[i] = "printCmdLine([[" + _tl[i] + "]])";
Expand Down Expand Up @@ -1604,9 +1603,7 @@ void TBuffer::translateToPlainText(std::string& incoming, const bool isFromServe
mSkip.clear();
ch = '"';
}
}
// if the content is split across package borders
else if (mSkip == "&gt" && ch == ';') {
} else if (mSkip == "&gt" && ch == ';') { // if the content is split across package borders
mIgnoreTag = false;
mSkip.clear();
ch = '>';
Expand Down Expand Up @@ -2951,7 +2948,7 @@ void TBuffer::decodeOSC(const QString& sequence)
// Uses mid(...) rather than at(...) because we want the return to
// be a (single character) QString and not a QChar so we can use
// QString::toUInt(...):
quint8 colorNumber = sequence.midRef(1,1).toUInt(&isOk, 16);
quint8 colorNumber = sequence.midRef(1, 1).toUInt(&isOk, 16);
quint8 rr = 0;
if (isOk) {
rr = sequence.midRef(2, 2).toUInt(&isOk, 16);
Expand Down Expand Up @@ -4144,8 +4141,8 @@ QString TBuffer::bufferToHtml(const bool showTimeStamp /*= false*/, const int ro
s.append(QStringLiteral("<span style=\"color: rgb(200,150,0); background: rgb(22,22,22); \">%1").arg(timeBuffer.at(row).left(timeStampFormat.length())));
// Set the current idea of what the formatting is so we can spot if it
// changes:
currentFgColor = QColor(200,150,0);
currentBgColor = QColor(22,22,22);
currentFgColor = QColor(200, 150, 0);
currentBgColor = QColor(22, 22, 22);
currentFlags = TChar::None;
// We are no longer before the first span - so we need to flag that
// there will be one to close:
Expand Down
6 changes: 3 additions & 3 deletions src/TBuffer.h
Expand Up @@ -83,8 +83,8 @@ class TChar

bool operator==(const TChar&);
void setColors(const QColor& newForeGroundColor, const QColor& newBackGroundColor) {
mFgColor=newForeGroundColor;
mBgColor=newBackGroundColor;
mFgColor = newForeGroundColor;
mBgColor = newBackGroundColor;
}
// Only considers the following flags: Bold, Italic, Overline, Reverse,
// Strikeout, Underline, does not consider Echo:
Expand Down Expand Up @@ -176,7 +176,7 @@ class TBuffer
QStringList getEndLines(int);
void clear();
QPoint getEndPos();
void translateToPlainText(std::string& s, bool isFromServer=false);
void translateToPlainText(std::string& s, bool isFromServer = false);
void append(const QString& chunk, int sub_start, int sub_end, const QColor& fg, const QColor& bg, const TChar::AttributeFlags flags = TChar::None, const int linkID = 0);
// Only the bits within TChar::TestMask are considered for formatting:
void append(const QString& chunk, const int sub_start, const int sub_end, const TChar format, const int linkID = 0);
Expand Down
6 changes: 3 additions & 3 deletions src/TCommandLine.cpp
Expand Up @@ -52,10 +52,10 @@ TCommandLine::TCommandLine(Host* pHost, TConsole* pConsole, QWidget* parent)

setFont(mpHost->getDisplayFont());

mRegularPalette.setColor(QPalette::Text, mpHost->mCommandLineFgColor); //QColor(0,0,192));
mRegularPalette.setColor(QPalette::Text, mpHost->mCommandLineFgColor);
mRegularPalette.setColor(QPalette::Highlight, QColor(0, 0, 192));
mRegularPalette.setColor(QPalette::HighlightedText, QColor(Qt::white));
mRegularPalette.setColor(QPalette::Base, mpHost->mCommandLineBgColor); //QColor(255,255,225));
mRegularPalette.setColor(QPalette::Base, mpHost->mCommandLineBgColor);

setPalette(mRegularPalette);

Expand Down Expand Up @@ -1037,7 +1037,7 @@ void TCommandLine::slot_addWord()

void TCommandLine::spellCheckWord(QTextCursor& c)
{
if (!mpHost||!mpHost->mEnableSpellCheck) {
if (!mpHost || !mpHost->mEnableSpellCheck) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/TConsole.cpp
Expand Up @@ -446,10 +446,10 @@ TConsole::TConsole(Host* pH, ConsoleType type, QWidget* parent)
mpBufferSearchBox->setFocusPolicy(Qt::ClickFocus);
mpBufferSearchBox->setPlaceholderText("Search ...");
QPalette __pal;
__pal.setColor(QPalette::Text, mpHost->mCommandLineFgColor); //QColor(0,0,192));
__pal.setColor(QPalette::Text, mpHost->mCommandLineFgColor);
__pal.setColor(QPalette::Highlight, QColor(0, 0, 192));
__pal.setColor(QPalette::HighlightedText, QColor(Qt::white));
__pal.setColor(QPalette::Base, mpHost->mCommandLineBgColor); //QColor(255,255,225));
__pal.setColor(QPalette::Base, mpHost->mCommandLineBgColor);
__pal.setColor(QPalette::Window, mpHost->mCommandLineBgColor);
mpBufferSearchBox->setPalette(__pal);
mpBufferSearchBox->setToolTip(QStringLiteral("<html><head/><body><p>%1</p></body></html>").arg(
Expand Down
6 changes: 3 additions & 3 deletions src/TConsole.h
Expand Up @@ -161,7 +161,7 @@ class TConsole : public QWidget
bool setBackgroundColor(const QString& name, int r, int g, int b, int alpha);
QString getCurrentLine(std::string&);
void selectCurrentLine(std::string&);
bool setMiniConsoleFontSize(int);
bool setMiniConsoleFontSize(int);
bool setMiniConsoleFont(const QString& font);
void setLink(const QStringList& linkFunction, const QStringList& linkHint);
// Cannot be called setAttributes as that would mask an inherited method
Expand Down Expand Up @@ -367,7 +367,7 @@ public slots:

Q_DECLARE_OPERATORS_FOR_FLAGS(TConsole::ConsoleType)

#if ! defined(QT_NO_DEBUG)
#if !defined(QT_NO_DEBUG)
inline QDebug& operator<<(QDebug& debug, const TConsole::ConsoleType& type)
{
QString text;
Expand All @@ -386,6 +386,6 @@ inline QDebug& operator<<(QDebug& debug, const TConsole::ConsoleType& type)
debug.nospace() << text;
return debug;
}
#endif // ! defined(QT_NO_DEBUG)
#endif // !defined(QT_NO_DEBUG)

#endif // MUDLET_TCONSOLE_H
2 changes: 1 addition & 1 deletion src/TLabel.cpp
Expand Up @@ -228,7 +228,7 @@ bool TLabel::forwardEventToMapper(QEvent* event)
QWidget* qw = qApp->widgetAt(wheelEvent->globalPos());

if (qw && parentWidget()->findChild<QWidget*>(QStringLiteral("mapper")) && parentWidget()->findChild<QWidget*>(QStringLiteral("mapper"))->isAncestorOf(qw)) {
#if (QT_VERSION >= QT_VERSION_CHECK(5,12, 0))
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
// Have switched to the latest QWheelEvent as that handles both X
// and Y wheels at the same time whereas previously we said the
// event was a vertical one - even if it wasn't! Additionally we
Expand Down
52 changes: 26 additions & 26 deletions src/TLuaInterpreter.cpp
Expand Up @@ -1750,7 +1750,7 @@ int TLuaInterpreter::feedTriggers(lua_State* L)
auto* pDataCodec = QTextCodec::codecForName(currentEncoding.toLatin1().constData());
auto* pDataEncoder = pDataCodec->makeEncoder(QTextCodec::IgnoreHeader);
if (!(currentEncoding.isEmpty() || currentEncoding == QStringLiteral("ASCII"))) {
if (! pDataCodec->canEncode(dataQString)) {
if (!pDataCodec->canEncode(dataQString)) {
lua_pushnil(L);
lua_pushfstring(L, "cannot send \"%s\" as it contains one or more characters that cannot be conveyed in the current game server encoding of \"%s\"", data.constData(), currentEncoding.toLatin1().constData());
return 2;
Expand Down Expand Up @@ -7070,7 +7070,7 @@ int TLuaInterpreter::sendATCP(lua_State* L)
Host& host = getHostFromLua(L);
std::string msg;
if (!lua_isstring(L, 1)) {
lua_pushfstring(L, "sendATCP: bad argument #1 type (message as string expected, got %1!)", luaL_typename(L,1));
lua_pushfstring(L, "sendATCP: bad argument #1 type (message as string expected, got %1!)", luaL_typename(L, 1));
return lua_error(L);
} else {
msg = host.mTelnet.encodeAndCookBytes(lua_tostring(L, 1));
Expand All @@ -7079,7 +7079,7 @@ int TLuaInterpreter::sendATCP(lua_State* L)
std::string what;
if (lua_gettop(L) > 1) {
if (!lua_isstring(L, 2)) {
lua_pushfstring(L, "sendATCP: bad argument #2 type (what as string is optional, got %1!)", luaL_typename(L,2));
lua_pushfstring(L, "sendATCP: bad argument #2 type (what as string is optional, got %1!)", luaL_typename(L, 2));
return lua_error(L);
} else {
what = host.mTelnet.encodeAndCookBytes(lua_tostring(L, 2));
Expand All @@ -7105,7 +7105,7 @@ int TLuaInterpreter::sendATCP(lua_State* L)
}

// output is in Mud Server Encoding form here:
if (! host.mTelnet.socketOutRaw(output)) {
if (!host.mTelnet.socketOutRaw(output)) {
lua_pushnil(L);
lua_pushstring(L, "unable to send all of the ATCP message");
return 2;
Expand Down Expand Up @@ -7145,7 +7145,7 @@ int TLuaInterpreter::sendGMCP(lua_State* L)
Host& host = getHostFromLua(L);
std::string msg;
if (!lua_isstring(L, 1)) {
lua_pushfstring(L, "sendGMCP: bad argument #1 type (message as string expected, got %1!)", luaL_typename(L,1));
lua_pushfstring(L, "sendGMCP: bad argument #1 type (message as string expected, got %1!)", luaL_typename(L, 1));
return lua_error(L);
} else {
msg = host.mTelnet.encodeAndCookBytes(lua_tostring(L, 1));
Expand All @@ -7154,7 +7154,7 @@ int TLuaInterpreter::sendGMCP(lua_State* L)
std::string what;
if (lua_gettop(L) > 1) {
if (!lua_isstring(L, 2)) {
lua_pushfstring(L, "sendGMCP: bad argument #2 type (what as string is optional, got %1!)", luaL_typename(L,2));
lua_pushfstring(L, "sendGMCP: bad argument #2 type (what as string is optional, got %1!)", luaL_typename(L, 2));
return lua_error(L);
} else {
what = host.mTelnet.encodeAndCookBytes(lua_tostring(L, 2));
Expand All @@ -7180,7 +7180,7 @@ int TLuaInterpreter::sendGMCP(lua_State* L)
}

// output is in Mud Server Encoding form here:
if (! host.mTelnet.socketOutRaw(output)) {
if (!host.mTelnet.socketOutRaw(output)) {
lua_pushnil(L);
lua_pushstring(L, "unable to send all of the GMCP message");
return 2;
Expand Down Expand Up @@ -7386,7 +7386,7 @@ int TLuaInterpreter::tempTimer(lua_State* L)
}

if (!lua_isstring(L, 2)) {
lua_pushfstring(L, "tempTimer: bad argument #2 type (script or function name as string expected, got %s!)", luaL_typename(L,2));
lua_pushfstring(L, "tempTimer: bad argument #2 type (script or function name as string expected, got %s!)", luaL_typename(L, 2));
return lua_error(L);
}
QString luaCode = QString::fromUtf8(lua_tostring(L, 2));
Expand Down Expand Up @@ -8461,13 +8461,13 @@ int TLuaInterpreter::permScript(lua_State* L)
int TLuaInterpreter::permTimer(lua_State* L)
{
if (!lua_isstring(L, 1)) {
lua_pushfstring(L, "permTimer: bad argument #1 type (timer name as string expected, got %s!)", luaL_typename(L,1));
lua_pushfstring(L, "permTimer: bad argument #1 type (timer name as string expected, got %s!)", luaL_typename(L, 1));
return lua_error(L);
}
QString name = QString::fromUtf8(lua_tostring(L, 1));

if (!lua_isstring(L, 2)) {
lua_pushfstring(L, "permTimer: bad argument #2 type (timer parent name as string expected, got %s!)", luaL_typename(L,2));
lua_pushfstring(L, "permTimer: bad argument #2 type (timer parent name as string expected, got %s!)", luaL_typename(L, 2));
return lua_error(L);
}
QString parent = QString::fromUtf8(lua_tostring(L, 2));
Expand Down Expand Up @@ -9009,8 +9009,8 @@ int TLuaInterpreter::setAreaName(lua_State* L)
// with this ID, but without a TArea instance to accompany it (the latter was/is
// instantiated as needed when a room is moved to the relevent area...) and we
// need to continue to allow this - Slysven
// else if( ! host.mpMap->mpRoomDB->getAreaIDList().contains( id ) ) {
// lua_pushnil( L );
// else if (!host.mpMap->mpRoomDB->getAreaIDList().contains(id)) {
// lua_pushnil(L);
// lua_pushstring(L, "setAreaName: bad argument #1 value (number %d is not a valid area id)."
// id);
// return 2;
Expand Down Expand Up @@ -14948,32 +14948,32 @@ void TLuaInterpreter::parseJSON(QString& key, const QString& string_data, const
// Then one pattern for \uXXXX\uXXXX where each XXXX is a 4-digit hexadecimal value
// These are 'surrogate pairs', (U+D800-U+DBFF) followed by (U+DC00-U+DFFF).
// D800-DF00 DC00-DFFF
int j=0;
while((j = initialText.indexOf(codeRegex,j)) != -1){
int j = 0;
while((j = initialText.indexOf(codeRegex, j)) != -1){
uint u;
switch(initialText.at(j+1).unicode()){
case 'n' : initialText.replace(j,2,'\n'); break;
case 't' : initialText.replace(j,2,'\t'); break;
case '\"' : initialText.replace(j,2,'\"'); break;
case '\\' : initialText.replace(j,2,'\\'); break;
case 'n' : initialText.replace(j, 2, '\n'); break;
case 't' : initialText.replace(j, 2, '\t'); break;
case '\"' : initialText.replace(j, 2, '\"'); break;
case '\\' : initialText.replace(j, 2, '\\'); break;
case 'u': // handle lone code or pair of codes together
u = initialText.midRef(j+2,4).toUShort(0,16);
u = initialText.midRef(j+2, 4).toUShort(0, 16);
if(u > 0xFFFD){
j += 5; // FFFE and FFFF are guaranteed to not be Unicode characters. Skip it.
}
else if((u < 0xD800) || (0xDFFF < u)){
// Characters in ranges U+0000-U+D7FF and U+E000-U+FFFD are stored as a single unit.
initialText.replace(j,6,QChar(u));
initialText.replace(j, 6, QChar(u));
}
else if((0xD7FF < u) && (u < 0xDC00)){
// Non-BMP characters (range U+10000-U+10FFFF) are stored as "surrogate pairs".
// A 'high' surrogate (U+D800-U+DBFF) followed by 'low' surrogate (U+DC00-U+DFFF).
// Surrogates are always written in pairs, a lone one is invalid.
// The regex above should ensure second code is DCxx-DFxx
QChar code[2];
code[0]=QChar(u);
code[1]=QChar(initialText.midRef(j+8,4).toUShort(0,16));
initialText.replace(j,12,code,2);
code[0] = QChar(u);
code[1] = QChar(initialText.midRef(j+8, 4).toUShort(0, 16));
initialText.replace(j, 12, code, 2);
j++; // in this case we are adding 2 code points for the character
}
// DC00-DFFF should be filtered out by the regex.
Expand Down Expand Up @@ -17241,7 +17241,7 @@ QPair<int, QString> TLuaInterpreter::setScriptCode(QString& name, const QString&
// No documentation available in wiki - internal function
QPair<int, QString> TLuaInterpreter::startPermTimer(const QString& name, const QString& parent, double timeout, const QString& function)
{
QTime time = QTime(0,0,0,0).addMSecs(qRound(timeout * 1000));
QTime time = QTime(0, 0, 0, 0).addMSecs(qRound(timeout * 1000));
TTimer* pT;
if (parent.isEmpty()) {
pT = new TTimer(QStringLiteral("newPermTimerWithoutAnId"), time, mpHost);
Expand Down Expand Up @@ -18098,7 +18098,7 @@ void TLuaInterpreter::updateAnsi16ColorsInTable()
lua_getfield(L, LUA_GLOBALSINDEX, "color_table");
if (!(lua_toboolean(L,-1))) {
// no it doesn't
lua_pop(L,1);
lua_pop(L, 1);
// So make it
lua_newtable(L);
}
Expand Down Expand Up @@ -18205,7 +18205,7 @@ void TLuaInterpreter::updateExtendedAnsiColorsInTable()
lua_getfield(L, LUA_GLOBALSINDEX, "color_table");
if (!(lua_toboolean(L,-1))) {
// no it doesn't
lua_pop(L,1);
lua_pop(L, 1);
// So make it
lua_newtable(L);
}
Expand Down

0 comments on commit 71afdc1

Please sign in to comment.