Logo Search packages:      
Sourcecode: kmess version File versions

void OldRichTextParser::parseMsnPlusString ( QString &  text  )  [static, private]

Replace the very old Messenger Plus characters with HTML markup.

Replace the oldest MSN+ tags with HTML-compatible formatting. This kind of formatting method uses reserved characters - thing which may cause i18n problems - but many MSN+ commands (most notably, the predefined messages with sound) still use it.

Parameters:
text The text to format. The original string will be lost.

Definition at line 388 of file old_richtextparser.cpp.

Referenced by parseMsnString().

{
  bool boldFlag      = false;
  bool italicFlag    = false;
  bool underlineFlag = false;
  bool fontFlag      = false;
  QColor  color;

  QRegExp htmlTest( "^\x04""&#?[a-z0-9]+;" );
  QRegExp fontCapture = QRegExp( "^\x03""([0-9]{1,2})(,([0-9]{1,2}))?" );

  for( int index = 0; index < text.length(); index++ )
  {
    switch( text.at( index ).unicode() )
    {
      case 0x0002: // bold character
        boldFlag = !boldFlag;

        text = text.replace( index, 1, ( boldFlag ) ? "<b>"  : "</b>" );
        index += ( boldFlag ) ? 2 : 3; // Skip the characters we've just added
        break;

        case 0x0003: // color character
          fontFlag = !fontFlag;

          fontCapture.indexIn( text, index, QRegExp::CaretAtOffset );

          color = getHtmlColor( fontCapture.cap(1) );

          // Font background text is ignored, as it's impossible to render in Qt's HTML subset
          if( fontCapture.matchedLength() == -1 )
          {
          // No color found after the special character, close the html tag
            text = text.replace( index, 1, "</font>" );
            index += 6; // Skip the characters we've just added
          }
          else
          {
          // Font color open
            text = text.replace( index, fontCapture.matchedLength(), "<font color='" + color.name() + "'>" );
            index += 21; // Skip the characters we've just added
          }
          break;

      case 0x0004:
        // Sound tag: this character is followed by another which identifies the sound ID
        htmlTest.indexIn( text, index, QRegExp::CaretAtOffset );
        if( htmlTest.matchedLength() != -1 )
        {
          // Some sounds IDs are HTML entities: that has to be taken care of, too
          text = text.replace( index, htmlTest.matchedLength(), "" );
        }
        else
        {
          // we need to delete this character and the following one from the string
          text = text.replace( index, 2, "" );
        }

        // Restart from where we encountered the starting character
        index -= 1;
        break;

        case 0x0005: // italic character
          italicFlag = !italicFlag;

          text = text.replace( index, 1, ( italicFlag ) ? "<i>"  : "</i>" );
          index += ( italicFlag ) ? 2 : 3; // Skip the characters we've just added
          break;

          case 0x001f: // underline character
            underlineFlag = !underlineFlag;

            text = text.replace( index, 1, ( underlineFlag ) ? "<u>"  : "</u>" );
            index += ( underlineFlag ) ? 2 : 3; // Skip the characters we've just added
            break;
    }

  }

  // Close any tag still open. Hopefully, the parser will not complain too much if the closing order is wrong
  if( boldFlag )  text.append( "</b>" );
  if( italicFlag )  text.append( "</i>" );
  if( underlineFlag )  text.append( "</u>" );
  if( fontFlag )  text.append( "</font>" );
}


Generated by  Doxygen 1.6.0   Back to index