4
0
mirror of https://github.com/QuasarApp/qca.git synced 2025-05-08 16:59:33 +00:00

qca-gnupg: some optimization in LineConverter

This commit is contained in:
Ivan Romanov 2014-10-07 01:07:13 +06:00
parent 5d28790cb5
commit 90b1287e52
2 changed files with 62 additions and 68 deletions

@ -25,11 +25,6 @@ void LineConverter::setup(LineConverter::Mode m)
{
state = Normal;
mode = m;
#ifdef Q_OS_WIN
write_conv = true;
#else
write_conv = false;
#endif
prebytes = 0;
list.clear();
}
@ -38,6 +33,9 @@ QByteArray LineConverter::update(const QByteArray &buf)
{
if(mode == Read)
{
// Convert buf to UNIX line ending style
// If buf ends with '\r' set state to Partival
QByteArray out;
if(state == Normal)
@ -63,6 +61,7 @@ QByteArray LineConverter::update(const QByteArray &buf)
// found, not last character
if(n < (buf.size() - 1))
{
// found windows line ending "\r\n"
if(out[n + 1] == '\n')
{
// clip out the '\r'
@ -83,8 +82,9 @@ QByteArray LineConverter::update(const QByteArray &buf)
}
else
{
if(write_conv)
{
// On Windows use DOS line ending style.
// On UNIX don't do any convertation. Return buf as is.
#ifdef Q_OS_WIN
QByteArray out;
int prev = 0;
int at = 0;
@ -117,11 +117,9 @@ QByteArray LineConverter::update(const QByteArray &buf)
prebytes += buf.size() - prev;
return out;
}
else
{
#else
return buf;
}
#endif
}
}
@ -133,7 +131,7 @@ QByteArray LineConverter::final()
if(state == Partial)
{
out.resize(1);
out[0] = '\r';
out[0] = '\n';
}
return out;
}
@ -150,8 +148,7 @@ QByteArray LineConverter::process(const QByteArray &buf)
int LineConverter::writtenToActual(int bytes)
{
if(write_conv)
{
#ifdef Q_OS_WIN
int n = 0;
int counter = bytes;
while(counter > 0)
@ -178,11 +175,9 @@ int LineConverter::writtenToActual(int bytes)
}
}
return bytes - n;
}
else
{
#else
return bytes;
}
#endif
}
} // end namespace gpgQCAPlugin

@ -39,7 +39,6 @@ private:
enum State { Normal, Partial };
Mode mode;
State state;
bool write_conv;
int prebytes;
QList<int> list;
};