Logo Search packages:      
Sourcecode: akonadi version File versions  Download package

int ImapParser::parseQuotedString ( const QByteArray &  data,
QByteArray &  result,
int  start = 0 
) [static]

Parses the next quoted string from data starting at start and puts it into result. The number of parsed characters is returned (this is not equal to result.length()!).

Parameters:
data Source data.
result Parsed string, quotation is removed and 'NIL' is transformed to an empty QByteArray.
start Start parsing at this index.

Definition at line 170 of file imapparser.cpp.

References stripLeadingSpaces().

Referenced by Akonadi::AkAppend::handleLine(), and parseString().

{
  int begin = stripLeadingSpaces( data, start );
  int end = begin;
  result.clear();
  if ( begin >= data.length() )
    return data.length();

  bool foundSlash = false;
  // quoted string
  if ( data[begin] == '"' ) {
    ++begin;
    for ( int i = begin; i < data.length(); ++i ) {
      if ( data[i] == '\\' ) {
        ++i;
        foundSlash = true;
        continue;
      }
      if ( data[i] == '"' ) {
        result = data.mid( begin, i - begin );
        end = i + 1; // skip the '"'
        break;
      }
    }
  }

  // unquoted string
  else {
    bool reachedInputEnd = true;
    for ( int i = begin; i < data.length(); ++i ) {
      if ( data[i] == ' ' || data[i] == '(' || data[i] == ')' || data[i] == '\n' || data[i] == '\r' ) {
        end = i;
        reachedInputEnd = false;
        break;
      }
      if (data[i] == '\\') 
        foundSlash = true;
    }
    if ( reachedInputEnd )
      end = data.length();
    result = data.mid( begin, end - begin );

    // transform unquoted NIL
    if ( result == "NIL" )
      result.clear();
  }

  // strip quotes
  if ( foundSlash ) {
    while ( result.contains( "\\\"" ) )
      result.replace( "\\\"", "\"" );
    while ( result.contains( "\\\\" ) )
      result.replace( "\\\\", "\\" );
  }
  return end;
}


Generated by  Doxygen 1.6.0   Back to index