1/* -*- c++ -*-
2 SPDX-FileCopyrightText: 2002 Marc Mutz <mutz@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6/**
7 @file
8 This file is part of the API for handling @ref MIME data and
9 defines a @ref uuencode @ref Codec class.
10
11 @brief
12 Defines the UUCodec class.
13
14 @authors Marc Mutz \<mutz@kde.org\>
15
16 @glossary @anchor UUEncode @anchor uuencode @b uuencode:
17 a binary to text encoding scheme. For more information, see the
18 <a href="http://en.wikipedia.org/wiki/Uuencode"> Wikipedia Uuencode page</a>.
19*/
20
21#ifndef KCODECS_UUENCODE_H
22#define KCODECS_UUENCODE_H
23
24#include "kcodecs.h"
25
26namespace KCodecs
27{
28/**
29 @brief
30 A class representing the @ref UUEncode @ref codec.
31*/
32class UUCodec : public Codec
33{
34public:
35 /**
36 Constructs a UUEncode codec.
37 */
38 UUCodec()
39 : Codec()
40 {
41 }
42
43 /**
44 Destroys the codec.
45 */
46 ~UUCodec() override
47 {
48 }
49
50 /**
51 @copydoc
52 Codec::name()
53 */
54 const char *name() const override
55 {
56 return "x-uuencode";
57 }
58
59 /**
60 @copydoc
61 Codec::maxEncodedSizeFor()
62 */
63 qsizetype maxEncodedSizeFor(qsizetype insize, NewlineType newline = Codec::NewlineLF) const override
64 {
65 Q_UNUSED(newline);
66 return insize; // we have no encoder!
67 }
68
69 /**
70 @copydoc
71 Codec::maxDecodedSizeFor()
72 */
73 qsizetype maxDecodedSizeFor(qsizetype insize, NewlineType newline = Codec::NewlineLF) const override
74 {
75 // assuming all characters are part of the uuencode stream (which
76 // does almost never hold due to required linebreaking; but
77 // additional non-uu chars don't affect the output size), each
78 // 4-tupel of them becomes a 3-tupel in the decoded octet
79 // stream. So:
80 qsizetype result = ((insize + 3) / 4) * 3;
81 // but all of them may be \n, so
82 if (newline == Codec::NewlineCRLF) {
83 result *= 2; // :-o
84 }
85 return result;
86 }
87
88 /**
89 @copydoc
90 Codec::makeEncoder()
91 */
92 Encoder *makeEncoder(NewlineType newline = Codec::NewlineLF) const override;
93
94 /**
95 @copydoc
96 Codec::makeEncoder()
97 */
98 Decoder *makeDecoder(NewlineType newline = Codec::NewlineLF) const override;
99};
100
101} // namespace KCodecs
102
103#endif // KCODECS_UUENCODE_H
104

source code of kcodecs/src/kcodecsuuencode.h