Commit 31038492 authored by David Faure's avatar David Faure

KMime: remove QStringOrQPair from the public API

Those two methods were not used outside kmime_header_parsing.cpp,
so better internalize all this.

The only exception was an unfinished non-automated test program,
adjusted accordingly.
parent 307220ac
Pipeline #35761 passed with stage
in 6 minutes and 48 seconds
......@@ -36,6 +36,16 @@ using namespace KMime::Types;
namespace KMime
{
namespace Types
{
// Optimization to avoid allocating QStrings when the value isn't encoded
struct KMIME_EXPORT QStringOrQPair {
QStringOrQPair() : qstring(), qpair(nullptr, 0) {}
QString qstring;
QPair<const char *, int> qpair;
};
} // namespace Types
namespace HeaderParsing
{
......@@ -1219,7 +1229,7 @@ bool parseAddressList(const char *&scursor, const char *const send,
// FIXME: Get rid of the very ugly "QStringOrQPair" thing. At this level, we are supposed to work
// on byte arrays, not strings! The result parameter should be a simple
// QPair<QByteArray,QByteArray>, which is the attribute name and the value.
bool parseParameter(const char *&scursor, const char *const send,
static bool parseParameter(const char *&scursor, const char *const send,
QPair<QString, QStringOrQPair> &result, bool isCRLF)
{
// parameter = regular-parameter / extended-parameter
......@@ -1303,9 +1313,9 @@ bool parseParameter(const char *&scursor, const char *const send,
// FIXME: Get rid of QStringOrQPair: Use a simply QMap<QByteArray, QByteArray> for "result"
// instead!
bool parseRawParameterList(const char *&scursor, const char *const send,
QMap<QString, QStringOrQPair> &result,
bool isCRLF)
static bool parseRawParameterList(const char *&scursor, const char *const send,
QMap<QString, QStringOrQPair> &result,
bool isCRLF)
{
// we use parseParameter() consecutively to obtain a map of raw
// attributes to raw values. "Raw" here means that we don't do
......
......@@ -34,16 +34,6 @@ class Base;
namespace Types
{
// for when we can't make up our mind what to use...
// FIXME: Remove this thing, we should _always_ know whether we are handling a
// byte array or a string.
// In most places where this is used, it should simply be replaced by QByteArray
struct KMIME_EXPORT QStringOrQPair {
QStringOrQPair() : qstring(), qpair(nullptr, 0) {}
QString qstring;
QPair<const char *, int> qpair;
};
} // namespace KMime::Types
namespace HeaderParsing
......@@ -204,20 +194,11 @@ Q_REQUIRED_RESULT KMIME_EXPORT bool parseAddressList(const char *&scursor,
Types::AddressList &result,
bool isCRLF = false);
Q_REQUIRED_RESULT KMIME_EXPORT bool parseParameter(const char *&scursor, const char *const send,
QPair<QString, Types::QStringOrQPair> &result,
bool isCRLF = false);
Q_REQUIRED_RESULT KMIME_EXPORT bool parseParameterList(const char *&scursor,
const char *const send,
QMap<QString, QString> &result,
bool isCRLF = false);
Q_REQUIRED_RESULT KMIME_EXPORT bool parseRawParameterList(const char *&scursor,
const char *const send,
QMap<QString, Types::QStringOrQPair> &result,
bool isCRLF = false);
/**
* Extract the charset embedded in the parameter list if there is one.
*
......
......@@ -34,8 +34,6 @@ static const char *tokenTypes[] = {
"group",
"address",
"address-list",
"parameter",
"raw-parameter-list",
"parameter-list",
"time",
"date-time"
......@@ -124,6 +122,7 @@ int main(int argc, char *argv[])
}
assert(action == Token);
Q_UNUSED(action); // avoid warning in release mode
int index;
for (index = 0 ; index < tokenTypesLen ; ++index) {
......@@ -161,14 +160,15 @@ int main(int argc, char *argv[])
break;
case 1: {
// atom
QString result = QStringLiteral("with 8bit: ");
cout << "with 8bit: " << endl;
QString result;
bool ok = parseAtom(iit, iend, result, true);
cout << (ok ? "OK" : "BAD") << endl
<< "result:\n" << result
<< endl;
result = QStringLiteral("without 8bit: ");
cout << "without 8bit: " << endl;
#ifdef COMPILE_FAIL
ok = parseAtom(indata.begin(), iend, result, false);
#else
......@@ -183,14 +183,15 @@ int main(int argc, char *argv[])
break;
case 2: {
// token
QString result = QStringLiteral("with 8bit: ");
cout << "with 8bit: " << endl;
QString result;
bool ok = parseToken(iit, iend, result, ParseTokenAllow8Bit);
cout << (ok ? "OK" : "BAD") << endl
<< "result:\n" << result
<< endl;
result = QStringLiteral("without 8bit: ");
cout << "without 8bit: " << endl;
#ifdef COMPILE_FAIL
ok = parseToken(indata.begin(), iend, result, ParseTokenNoFlag);
#else
......@@ -386,40 +387,6 @@ int main(int argc, char *argv[])
}
break;
case 16: {
// parameter
QPair<QString, KMime::Types::QStringOrQPair> result;
bool ok = parseParameter(iit, iend, result, withCRLF);
cout << (ok ? "OK" : "BAD") << endl
<< "result.first (attribute):\n" << result.first << endl
<< "result.second.qstring (value):\n" << result.second.qstring << endl
<< "result.second.qpair (value):\n"
<< QByteArray(result.second.qpair.first, result.second.qpair.second + 1).data()
<< endl;
}
break;
case 17: {
// raw-parameter-list
QMap<QString, KMime::Types::QStringOrQPair> result;
bool ok = parseRawParameterList(iit, iend, result, withCRLF);
cout << (ok ? "OK" : "BAD") << endl
<< "result: " << result.count() << " raw parameters:"
<< endl;
int i = 0;
for (QMap<QString, KMime::Types::QStringOrQPair>::ConstIterator it = result.constBegin();
it != result.constEnd() ; ++it, ++i) {
cout << "result[" << i << "].key() (attribute):\n"
<< it.key() << endl
<< "result[" << i << "].data().qstring (value):\n"
<< it.value().qstring << endl
<< "result[" << i << "].data().qpair (value):\n"
<< QByteArray(it.value().qpair.first, it.value().qpair.second + 1).data()
<< endl;
}
}
break;
case 18: {
// parameter-list
QMap<QString, QString> result;
bool ok = parseParameterList(iit, iend, result, withCRLF);
......@@ -438,7 +405,7 @@ int main(int argc, char *argv[])
}
}
break;
case 19: {
case 17: {
// time
int hour, mins, secs;
long int secsEastOfGMT;
......@@ -456,7 +423,7 @@ int main(int argc, char *argv[])
<< endl;
}
break;
case 20: {
case 18: {
// date-time
QDateTime result;
bool ok = parseDateTime(iit, iend, result, withCRLF);
......
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