51 QTextCodec* VersitUtils::m_previousCodec = 0; |
51 QTextCodec* VersitUtils::m_previousCodec = 0; |
52 QList<QByteArrayMatcher>* VersitUtils::m_newlineList = 0; |
52 QList<QByteArrayMatcher>* VersitUtils::m_newlineList = 0; |
53 QByteArray VersitUtils::m_encodingMap[256]; |
53 QByteArray VersitUtils::m_encodingMap[256]; |
54 |
54 |
55 /*! |
55 /*! |
56 * Performs backslash escaping for line breaks (CRLFs), semicolons, backslashes and commas according |
|
57 * to RFC 2426. This is called on parameter names and values and property values. |
|
58 * Colons ARE NOT escaped because the examples in RFC2426 suggest that they shouldn't be. |
|
59 */ |
|
60 void VersitUtils::backSlashEscape(QString& text) |
|
61 { |
|
62 /* replaces ; with \; |
|
63 , with \, |
|
64 \ with \\ |
|
65 */ |
|
66 text.replace(QRegExp(QLatin1String("([;,\\\\])")), QLatin1String("\\\\1")); |
|
67 // replaces any CRLFs with \n |
|
68 text.replace(QRegExp(QLatin1String("\r\n|\r|\n")), QLatin1String("\\n")); |
|
69 } |
|
70 |
|
71 /*! |
|
72 * Removes backslash escaping for line breaks (CRLFs), colons, semicolons, backslashes and commas |
|
73 * according to RFC 2426. This is called on parameter names and values and property values. |
|
74 * Colons ARE unescaped because the text of RFC2426 suggests that they should be. |
|
75 */ |
|
76 void VersitUtils::removeBackSlashEscaping(QString& text) |
|
77 { |
|
78 if (!(text.startsWith(QLatin1Char('"')) && text.endsWith(QLatin1Char('"')))) { |
|
79 /* replaces \; with ; |
|
80 \, with , |
|
81 \: with : |
|
82 \\ with \ |
|
83 */ |
|
84 text.replace(QRegExp(QLatin1String("\\\\([;,:\\\\])")), QLatin1String("\\1")); |
|
85 // replaces \n with a CRLF |
|
86 text.replace(QLatin1String("\\n"), QLatin1String("\r\n"), Qt::CaseInsensitive); |
|
87 } |
|
88 } |
|
89 |
|
90 |
|
91 /*! |
|
92 * Encode \a ch with \a codec, without adding an byte-order mark |
56 * Encode \a ch with \a codec, without adding an byte-order mark |
93 */ |
57 */ |
94 QByteArray VersitUtils::encode(char ch, QTextCodec* codec) |
58 QByteArray VersitUtils::encode(char ch, QTextCodec* codec) |
95 { |
59 { |
96 if (codec != m_previousCodec) { |
60 if (codec != m_previousCodec) { |