File indexing completed on 2024-05-12 16:18:07
0001 /*************************************************************************** 0002 * Copyright (C) 2010 Ralf Engels <ralf-engels@gmx.de> * 0003 * Copyright (C) 2012 Edward Toroshchin <amarok@hades.name> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 0021 #ifndef COLLECTIONSCANNER_UTILS_H 0022 #define COLLECTIONSCANNER_UTILS_H 0023 0024 #include <QString> 0025 0026 namespace CollectionScanner 0027 { 0028 0029 /** Removes all characters not allowed by xml 1.0 specification. 0030 We need this because the Qt 4.6 xml scanner is behaving very badly 0031 when encountering such characters in the input. 0032 ...and because Qt 4.whatever xml writer outputs such characters without 0033 any remorse. 0034 see http://en.wikipedia.org/wiki/Valid_Characters_in_XML 0035 */ 0036 inline QString 0037 escapeXml10( QString str ) 0038 { 0039 for( int i = 0; i < str.length(); ++i ) 0040 { 0041 ushort c = str.at(i).unicode(); 0042 if( (c < 0x20 && c != 0x09 && c != 0x0A && c != 0x0D) || 0043 (c > 0xD7FF && c < 0xE000) || 0044 (c > 0xFFFD) ) 0045 str[i] = '?'; 0046 } 0047 return str; 0048 } 0049 0050 } 0051 0052 #endif // COLLECTIONSCANNER_UTILS_H