File indexing completed on 2024-04-21 04:47:53
0001 /**************************************************************************************** 0002 * Copyright (c) 2004 Shintaro Matsuoka <shin@shoegazed.org> * 0003 * Copyright (c) 2006 Martin Aumueller <aumuell@reserv.at> * 0004 * Copyright (c) 2011 Sergey Ivanov <123kash@gmail.com> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) any later * 0009 * version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0013 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License along with * 0016 * this program. If not, see <http://www.gnu.org/licenses/>. * 0017 ****************************************************************************************/ 0018 0019 #ifndef AMAROK_QSTRINGX_H 0020 #define AMAROK_QSTRINGX_H 0021 0022 #include <QStringList> 0023 #include <QMap> 0024 0025 namespace Amarok 0026 { 0027 0028 class QStringx : public QString 0029 { 0030 public: 0031 QStringx(); 0032 explicit QStringx( QChar ch ); 0033 explicit QStringx( const QString &s ); 0034 explicit QStringx( const QByteArray &ba ); 0035 QStringx( const QChar *unicode, uint length ); 0036 explicit QStringx( const char *str ); 0037 virtual ~QStringx(); 0038 0039 // the numbers following % obviously are not taken into account 0040 QString args( const QStringList& args ) const; 0041 0042 // %something% gets replaced by the value corresponding to key "something" in args 0043 // if opt is true: return empty string if it has empty tokens 0044 QString namedArgs( const QMap<QString, QString> &args, bool opt = false ) const; 0045 0046 // %something% gets replaced by the value corresponding to key "something" in args, 0047 // however, if key "something" is not available, 0048 // then replace everything within surrounding { } by an empty string 0049 QString namedOptArgs( const QMap<QString, QString> &args ) const; 0050 0051 private: 0052 enum CharType 0053 { 0054 CTRegular, 0055 CTToken, 0056 CTBraceOpen, 0057 CTBraceClose, 0058 CTBracketOpen, 0059 CTBracketSeparator, 0060 CTBracketClose, 0061 CTNone 0062 }; 0063 0064 CharType testChar( int *pos ) const; 0065 QString parseToken( int *pos, const QMap<QString, QString> &dict ) const; 0066 QString parseBraces( int *pos, const QMap<QString, QString> &dict ) const; 0067 QString parseBrackets( int *pos, const QMap<QString, QString> &dict ) const; 0068 QString parse( int *pos, const QMap<QString, QString> &dict ) const; 0069 }; 0070 0071 } // namespace Amarok 0072 0073 #endif // AMAROK_QSTRINGX_H