File indexing completed on 2024-09-22 04:52:48
0001 /* 0002 Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org> 0003 Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org> 0004 0005 This program is free software; you can redistribute it and/or modify 0006 it under the terms of the GNU Lesser General Public License (LGPL) 0007 version 2 as published by the Free Software Foundation. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 GNU Lesser General Public License for more details. 0013 0014 You should have received a copy of the GNU Lesser General Public 0015 License along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 0018 The encoding and decoding utilities in KCodecs with the exception of 0019 quoted-printable are based on the java implementation in HTTPClient 0020 package by Ronald Tschalär Copyright (C) 1996-1999. // krazy:exclude=copyright 0021 0022 The quoted-printable codec as described in RFC 2045, section 6.7. is by 0023 Rik Hemsley (C) 2001. 0024 */ 0025 0026 #ifndef KCODECS_H 0027 #define KCODECS_H 0028 0029 #define KBase64 KCodecs 0030 0031 #define KDECORE_EXPORT 0032 0033 #include <QtCore> 0034 0035 class QByteArray; 0036 class QIODevice; 0037 0038 /** 0039 * A wrapper class for the most commonly used encoding and 0040 * decoding algorithms. Currently there is support for encoding 0041 * and decoding input using base64, uu and the quoted-printable 0042 * specifications. 0043 * 0044 * \b Usage: 0045 * 0046 * \code 0047 * QByteArray input = "Aladdin:open sesame"; 0048 * QByteArray result = KCodecs::base64Encode(input); 0049 * cout << "Result: " << result.data() << endl; 0050 * \endcode 0051 * 0052 * <pre> 0053 * Output should be 0054 * Result: QWxhZGRpbjpvcGVuIHNlc2FtZQ== 0055 * </pre> 0056 * 0057 * The above example makes use of the convenience functions 0058 * (ones that accept/return null-terminated strings) to encode/decode 0059 * a string. If what you need is to encode or decode binary data, then 0060 * it is highly recommended that you use the functions that take an input 0061 * and output QByteArray as arguments. These functions are specifically 0062 * tailored for encoding and decoding binary data. 0063 * 0064 * @short A collection of commonly used encoding and decoding algorithms. 0065 * @author Dawit Alemayehu <adawit@kde.org> 0066 * @author Rik Hemsley <rik@kde.org> 0067 */ 0068 namespace KCodecs 0069 { 0070 /** 0071 * Encodes the given data using the quoted-printable algorithm. 0072 * 0073 * @param in data to be encoded. 0074 * @param useCRLF if true the input data is expected to have 0075 * CRLF line breaks and the output will have CRLF line 0076 * breaks, too. 0077 * @return quoted-printable encoded string. 0078 */ 0079 KDECORE_EXPORT QByteArray quotedPrintableEncode(const QByteArray & in, 0080 bool useCRLF = true); 0081 0082 /** 0083 * Encodes the given data using the quoted-printable algorithm. 0084 * 0085 * Use this function if you want the result of the encoding 0086 * to be placed in another array which cuts down the number 0087 * of copy operation that have to be performed in the process. 0088 * This is also the preferred method for encoding binary data. 0089 * 0090 * NOTE: the output array is first reset and then resized 0091 * appropriately before use, hence, all data stored in the 0092 * output array will be lost. 0093 * 0094 * @param in data to be encoded. 0095 * @param out encoded data. 0096 * @param useCRLF if true the input data is expected to have 0097 * CRLF line breaks and the output will have CRLF line 0098 * breaks, too. 0099 */ 0100 KDECORE_EXPORT void quotedPrintableEncode(const QByteArray & in, QByteArray& out, 0101 bool useCRLF); 0102 0103 /** 0104 * Decodes a quoted-printable encoded data. 0105 * 0106 * Accepts data with CRLF or standard unix line breaks. 0107 * 0108 * @param in data to be decoded. 0109 * @return decoded string. 0110 */ 0111 KDECORE_EXPORT QByteArray quotedPrintableDecode(const QByteArray & in); 0112 0113 /** 0114 * Decodes a quoted-printable encoded data. 0115 * 0116 * Accepts data with CRLF or standard unix line breaks. 0117 * Use this function if you want the result of the decoding 0118 * to be placed in another array which cuts down the number 0119 * of copy operation that have to be performed in the process. 0120 * This is also the preferred method for decoding an encoded 0121 * binary data. 0122 * 0123 * NOTE: the output array is first reset and then resized 0124 * appropriately before use, hence, all data stored in the 0125 * output array will be lost. 0126 * 0127 * @param in data to be decoded. 0128 * @param out decoded data. 0129 */ 0130 KDECORE_EXPORT void quotedPrintableDecode(const QByteArray & in, QByteArray& out); 0131 0132 } 0133 0134 #endif // KCODECS_H