Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

xmlencodeattr.cpp

Go to the documentation of this file.
00001 /*
00002  * xmlencodeattr.h
00003  *
00004  * copyright   : (c) 2003 by Joseph Wenninger
00005  *               except for a small modification it's identical to qdom.cpp:encodeAttr
00006  * email       : jowenn@handhelds.org
00007  *
00008  */
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "xmlencodeattr.h"
00019 QString encodeAttr( const QString& str )
00020 {
00021     QString tmp( str );
00022     uint len = tmp.length();
00023     uint i = 0;
00024     while ( i < len ) {
00025         if ( tmp[(int)i] == '<' ) {
00026             tmp.replace( i, 1, "&lt;" );
00027             len += 3;
00028             i += 4;
00029         } else if ( tmp[(int)i] == '"' ) {
00030             tmp.replace( i, 1, "&quot;" );
00031             len += 5;
00032             i += 6;
00033         } else if ( tmp[(int)i] == '&' ) {
00034             tmp.replace( i, 1, "&amp;" );
00035             len += 4;
00036             i += 5;
00037         } else if ( tmp[(int)i] == '>'  ) {
00038             tmp.replace( i, 1, "&gt;" );
00039             len += 3;
00040             i += 4;
00041         } else {
00042             ++i;
00043         }
00044     }
00045 
00046     return tmp;
00047 }
00048 

Generated on Sat Nov 5 16:17:08 2005 for OPIE by  doxygen 1.4.2