~ubuntu-branches/ubuntu/karmic/kid3/karmic

« back to all changes in this revision

Viewing changes to kid3/formatreplacer.h

  • Committer: Bazaar Package Importer
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2009-01-15 19:15:40 UTC
  • mfrom: (1.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090115191540-gkr2szzjqbponmsg
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file formatreplacer.h
 
3
 * Replaces format codes in a string.
 
4
 *
 
5
 * \b Project: Kid3
 
6
 * \author Urs Fleisch
 
7
 * \date 06 Jul 2008
 
8
 */
 
9
 
 
10
#ifndef FORMATREPLACER_H
 
11
#define FORMATREPLACER_H
 
12
 
 
13
#include <qstring.h>
 
14
 
 
15
/**
 
16
 * Replaces format codes in a string.
 
17
 */
 
18
class FormatReplacer {
 
19
public:
 
20
        /** Flags for replacePercentCodes(). */
 
21
        enum FormatStringFlags {
 
22
                FSF_SupportUrlEncode  = (1 << 0),
 
23
                FSF_ReplaceSeparators = (1 << 1)
 
24
        };
 
25
 
 
26
        /**
 
27
         * Constructor.
 
28
         *
 
29
         * @param str string with format codes
 
30
         */
 
31
        explicit FormatReplacer(const QString& str = QString());
 
32
 
 
33
        /**
 
34
         * Destructor.
 
35
         */
 
36
        virtual ~FormatReplacer();
 
37
 
 
38
        /**
 
39
         * Set string with format codes.
 
40
         * @param str string with format codes
 
41
         */
 
42
        void setString(const QString& str) { m_str = str; }
 
43
 
 
44
        /**
 
45
         * Get string.
 
46
         * The string set with setString() can be modified using
 
47
         * replaceEscapedChars() and replacePercentCodes().
 
48
         * @return string.
 
49
         */
 
50
        QString getString() const { return m_str; }
 
51
 
 
52
        /**
 
53
         * Replace escaped characters.
 
54
         * Replaces the escaped characters ("\n", "\t", "\r", "\\", "\a", "\b",
 
55
         * "\f", "\v") with the corresponding characters.
 
56
         */
 
57
        void replaceEscapedChars();
 
58
 
 
59
        /**
 
60
         * Replace percent codes.
 
61
         *
 
62
         * @param flags flags: FSF_SupportUrlEncode to support modifier u
 
63
         *              (with code c "%uc") to URL encode,
 
64
         *              FSF_ReplaceSeparators to replace directory separators
 
65
         *              ('/', '\\', ':') in tags.
 
66
         */
 
67
        void replacePercentCodes(unsigned flags = 0);
 
68
 
 
69
protected:
 
70
        /**
 
71
         * Replace a format code (one character %c or multiple characters %{chars}).
 
72
         *
 
73
         * @param code format code
 
74
         *
 
75
         * @return replacement string,
 
76
         *         QString::null if code not found.
 
77
         */
 
78
        virtual QString getReplacement(const QString& code) const = 0;
 
79
 
 
80
private:
 
81
        QString m_str;
 
82
};
 
83
 
 
84
#endif // FORMATREPLACER_H