Verified Commit 82c096c4 authored by Fushan Wen's avatar Fushan Wen
Browse files

dict: Do not use static array, move it to member variable

parent 8b45a93d
......@@ -20,6 +20,13 @@ DictEngine::DictEngine(QObject *parent)
, m_dictName(QStringLiteral("wn")) // In case we need to switch it later
, m_serverName(QStringLiteral("dict.org")) // Default, good dictionary
{
m_definitionResponses = {
QByteArrayLiteral("250"), /**< ok (optional timing information here) */
QByteArrayLiteral("552"), /**< No match */
QByteArrayLiteral("550"), /**< Invalid database */
QByteArrayLiteral("501"), /**< Syntax error, illegal parameters */
QByteArrayLiteral("503"), /**< Command parameter not implemented */
};
}
DictEngine::~DictEngine()
......@@ -109,15 +116,7 @@ void DictEngine::getDefinition()
m_tcpSocket->write(command);
m_tcpSocket->flush();
static const std::array<QByteArray, 5> responses{
QByteArrayLiteral("250"), /**< ok (optional timing information here) */
QByteArrayLiteral("552"), /**< No match */
QByteArrayLiteral("550"), /**< Invalid database */
QByteArrayLiteral("501"), /**< Syntax error, illegal parameters */
QByteArrayLiteral("503"), /**< Command parameter not implemented */
};
while (std::none_of(responses.cbegin(), responses.cend(), [&ret](const QByteArray &code) {
while (std::none_of(m_definitionResponses.cbegin(), m_definitionResponses.cend(), [&ret](const QByteArray &code) {
return ret.contains(code);
})) {
m_tcpSocket->waitForReadyRead();
......
......@@ -47,4 +47,7 @@ private:
QString m_dictName;
QString m_serverName;
QMap<QString, QMap<QString, QString>> m_availableDictsCache;
// https://datatracker.ietf.org/doc/html/rfc2229
std::array<QByteArray, 5> m_definitionResponses;
};
Supports Markdown
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