File indexing completed on 2024-10-06 12:16:34
0001 /* -*- c++ -*- 0002 SPDX-FileCopyrightText: 2002 Marc Mutz <mutz@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 /** 0007 @file 0008 This file is part of the API for handling @ref MIME data and 0009 defines a @ref uuencode @ref Codec class. 0010 0011 @brief 0012 Defines the UUCodec class. 0013 0014 @authors Marc Mutz \<mutz@kde.org\> 0015 0016 @glossary @anchor UUEncode @anchor uuencode @b uuencode: 0017 a binary to text encoding scheme. For more information, see the 0018 <a href="http://en.wikipedia.org/wiki/Uuencode"> Wikipedia Uuencode page</a>. 0019 */ 0020 0021 #ifndef KCODECS_UUENCODE_H 0022 #define KCODECS_UUENCODE_H 0023 0024 #include "kcodecs.h" 0025 0026 namespace KCodecs 0027 { 0028 /** 0029 @brief 0030 A class representing the @ref UUEncode @ref codec. 0031 */ 0032 class UUCodec : public Codec 0033 { 0034 public: 0035 /** 0036 Constructs a UUEncode codec. 0037 */ 0038 UUCodec() 0039 : Codec() 0040 { 0041 } 0042 0043 /** 0044 Destroys the codec. 0045 */ 0046 ~UUCodec() override 0047 { 0048 } 0049 0050 /** 0051 @copydoc 0052 Codec::name() 0053 */ 0054 const char *name() const override 0055 { 0056 return "x-uuencode"; 0057 } 0058 0059 /** 0060 @copydoc 0061 Codec::maxEncodedSizeFor() 0062 */ 0063 int maxEncodedSizeFor(int insize, NewlineType newline = Codec::NewlineLF) const override 0064 { 0065 Q_UNUSED(newline); 0066 return insize; // we have no encoder! 0067 } 0068 0069 /** 0070 @copydoc 0071 Codec::maxDecodedSizeFor() 0072 */ 0073 int maxDecodedSizeFor(int insize, NewlineType newline = Codec::NewlineLF) const override 0074 { 0075 // assuming all characters are part of the uuencode stream (which 0076 // does almost never hold due to required linebreaking; but 0077 // additional non-uu chars don't affect the output size), each 0078 // 4-tupel of them becomes a 3-tupel in the decoded octet 0079 // stream. So: 0080 int result = ((insize + 3) / 4) * 3; 0081 // but all of them may be \n, so 0082 if (newline == Codec::NewlineCRLF) { 0083 result *= 2; // :-o 0084 } 0085 return result; 0086 } 0087 0088 /** 0089 @copydoc 0090 Codec::makeEncoder() 0091 */ 0092 Encoder *makeEncoder(NewlineType newline = Codec::NewlineLF) const override; 0093 0094 /** 0095 @copydoc 0096 Codec::makeEncoder() 0097 */ 0098 Decoder *makeDecoder(NewlineType newline = Codec::NewlineLF) const override; 0099 }; 0100 0101 } // namespace KCodecs 0102 0103 #endif // KCODECS_UUENCODE_H