2
* \file formatreplacer.h
3
* Replaces format codes in a string.
10
#ifndef FORMATREPLACER_H
11
#define FORMATREPLACER_H
16
* Replaces format codes in a string.
18
class FormatReplacer {
20
/** Flags for replacePercentCodes(). */
21
enum FormatStringFlags {
22
FSF_SupportUrlEncode = (1 << 0),
23
FSF_ReplaceSeparators = (1 << 1)
29
* @param str string with format codes
31
explicit FormatReplacer(const QString& str = QString());
36
virtual ~FormatReplacer();
39
* Set string with format codes.
40
* @param str string with format codes
42
void setString(const QString& str) { m_str = str; }
46
* The string set with setString() can be modified using
47
* replaceEscapedChars() and replacePercentCodes().
50
QString getString() const { return m_str; }
53
* Replace escaped characters.
54
* Replaces the escaped characters ("\n", "\t", "\r", "\\", "\a", "\b",
55
* "\f", "\v") with the corresponding characters.
57
void replaceEscapedChars();
60
* Replace percent codes.
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.
67
void replacePercentCodes(unsigned flags = 0);
71
* Replace a format code (one character %c or multiple characters %{chars}).
73
* @param code format code
75
* @return replacement string,
76
* QString::null if code not found.
78
virtual QString getReplacement(const QString& code) const = 0;
84
#endif // FORMATREPLACER_H