Commit a120210c authored by hjk's avatar hjk
Browse files

debugger: simplify escapeCString



There was no real need for the QString based version after all.

Change-Id: I3ea64ba03164c97205fe5ee545fb53ebf44c7535
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@nokia.com>
parent 88f5949e
......@@ -2542,7 +2542,7 @@ QByteArray GdbEngine::breakpointLocation(BreakpointModelId id)
? data.fileName : breakLocation(data.fileName);
// The argument is simply a C-quoted version of the argument to the
// non-MI "break" command, including the "original" quoting it wants.
return "\"\\\"" + GdbMi::escapeCString(fileName).toLocal8Bit() + "\\\":"
return "\"\\\"" + GdbMi::escapeCString(fileName.toLocal8Bit()) + "\\\":"
+ QByteArray::number(data.lineNumber) + '"';
}
......@@ -2552,7 +2552,7 @@ QByteArray GdbEngine::breakpointLocation2(BreakpointModelId id)
const BreakpointParameters &data = handler->breakpointData(id);
const QString fileName = data.pathUsage == BreakpointUseFullPath
? data.fileName : breakLocation(data.fileName);
return GdbMi::escapeCString(fileName).toLocal8Bit() + ':'
return GdbMi::escapeCString(fileName.toLocal8Bit()) + ':'
+ QByteArray::number(data.lineNumber);
}
......@@ -2685,7 +2685,7 @@ void GdbEngine::handleBreakInsert1(const GdbResponse &response)
const QString fileName = handler->fileName(id);
const int lineNumber = handler->lineNumber(id);
QByteArray cmd = "trace "
"\"" + GdbMi::escapeCString(fileName).toLocal8Bit() + "\":"
"\"" + GdbMi::escapeCString(fileName.toLocal8Bit()) + "\":"
+ QByteArray::number(lineNumber);
QVariant vid = QVariant::fromValue(id);
postCommand(cmd, NeedsStop | RebuildBreakpointModel,
......
......@@ -246,69 +246,36 @@ void GdbMi::dumpChildren(QByteArray * str, bool multiline, int indent) const
}
}
template <class String, typename CharType>
struct EscapeTraits
{
static CharType at(const String &s, int i)
{ return s.at(i); }
static void appendChar(CharType c, String *s)
{ s->append(c); }
static void appendString(const char *c, String *s)
{ s->append(c); }
};
template <>
struct EscapeTraits<QString, ushort>
{
static ushort at(const QString &s, int i)
{ return s.at(i).unicode(); }
static void appendChar(ushort c, QString *s)
{ s->append(QLatin1Char(c)); }
static void appendString(const char *c, QString *s)
{ s->append(QLatin1String(c)); }
};
template<class ST, typename CT>
inline ST escapeCStringTpl(const ST &ba)
QByteArray GdbMi::escapeCString(const QByteArray &ba)
{
ST ret;
QByteArray ret;
ret.reserve(ba.length() * 2);
for (int i = 0; i < ba.length(); ++i) {
const CT c = EscapeTraits<ST, CT>::at(ba, i);
const uchar c = ba.at(i);
switch (c) {
case '\\': EscapeTraits<ST, CT>::appendString("\\\\", &ret); break;
case '\a': EscapeTraits<ST, CT>::appendString("\\a", &ret); break;
case '\b': EscapeTraits<ST, CT>::appendString("\\b", &ret); break;
case '\f': EscapeTraits<ST, CT>::appendString("\\f", &ret); break;
case '\n': EscapeTraits<ST, CT>::appendString("\\n", &ret); break;
case '\r': EscapeTraits<ST, CT>::appendString("\\r", &ret); break;
case '\t': EscapeTraits<ST, CT>::appendString("\\t", &ret); break;
case '\v': EscapeTraits<ST, CT>::appendString("\\v", &ret); break;
case '"': EscapeTraits<ST, CT>::appendString("\\\"", &ret); break;
case '\\': ret += "\\\\"; break;
case '\a': ret += "\\a"; break;
case '\b': ret += "\\b"; break;
case '\f': ret += "\\f"; break;
case '\n': ret += "\\n"; break;
case '\r': ret += "\\r"; break;
case '\t': ret += "\\t"; break;
case '\v': ret += "\\v"; break;
case '"': ret += "\\\""; break;
default:
if (c < 32 || c == 127) {
EscapeTraits<ST, CT>::appendChar('\\', &ret);
EscapeTraits<ST, CT>::appendChar('0' + (c >> 6), &ret);
EscapeTraits<ST, CT>::appendChar('0' + ((c >> 3) & 7), &ret);
EscapeTraits<ST, CT>::appendChar('0' + (c & 7), &ret);
ret += '\\';
ret += ('0' + (c >> 6));
ret += ('0' + ((c >> 3) & 7));
ret += ('0' + (c & 7));
} else {
EscapeTraits<ST, CT>::appendChar(c, &ret);
ret += c;
}
}
}
return ret;
}
QString GdbMi::escapeCString(const QString &ba)
{
return escapeCStringTpl<QString, ushort>(ba);
}
QByteArray GdbMi::escapeCString(const QByteArray &ba)
{
return escapeCStringTpl<QByteArray, uchar>(ba);
}
QByteArray GdbMi::toString(bool multiline, int indent) const
{
QByteArray result;
......
......@@ -135,7 +135,6 @@ private:
static QByteArray parseCString(const char *&from, const char *to);
static QByteArray escapeCString(const QByteArray &ba);
static QString escapeCString(const QString &ba);
void parseResultOrValue(const char *&from, const char *to);
void parseValue(const char *&from, const char *to);
void parseTuple(const char *&from, const char *to);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment