Dear all
While browsing the code, I came upon this function. Its length made me stop and take a look….
We should always look into the lib for any usable bits ( Or refactor towards them ). Here, it seems, we should be using indexOf method…
This is what I think it should look like… I have applied Extract Method refactoring after using indexOf… It is simpler and opens doors for more refactorings ;-)
/* Refac. Note — I would like to use size_t instead of int */
/* it seems more natural */
bool lenCString( const QByteArray &rawPayload, int pos, int* len )
{
int startPos = pos;
pos = rawPayload.indexOf( 0, startPos );
if( pos == -1 )
return false;
*len = pos - startPos;
return true;
}
bool QueryHits::prepareReadPayload (const QByteArray &rawPayload)
{
int payloadLength = rawPayload.length();
if (payloadLength (rawPayload.at(0));
for( int i = 0; i
