/src/kcodecs/src/kcodecsuuencode.h
Line | Count | Source |
1 | | /* -*- c++ -*- |
2 | | SPDX-FileCopyrightText: 2002 Marc Mutz <mutz@kde.org> |
3 | | |
4 | | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | | */ |
6 | | |
7 | | #ifndef KCODECS_UUENCODE_H |
8 | | #define KCODECS_UUENCODE_H |
9 | | |
10 | | #include "kcodecs.h" |
11 | | |
12 | | namespace KCodecs |
13 | | { |
14 | | /* |
15 | | A class representing the UUEncode codec. |
16 | | */ |
17 | | class UUCodec : public Codec |
18 | | { |
19 | | public: |
20 | 1 | constexpr UUCodec() = default; |
21 | | |
22 | | constexpr ~UUCodec() override = default; |
23 | | |
24 | | constexpr const char *name() const override |
25 | 0 | { |
26 | 0 | return "x-uuencode"; |
27 | 0 | } |
28 | | |
29 | | qsizetype maxEncodedSizeFor(qsizetype insize, NewlineType newline = Codec::NewlineLF) const override |
30 | 0 | { |
31 | 0 | Q_UNUSED(newline); |
32 | 0 | return insize; // we have no encoder! |
33 | 0 | } |
34 | | |
35 | | qsizetype maxDecodedSizeFor(qsizetype insize, NewlineType newline = Codec::NewlineLF) const override |
36 | 106k | { |
37 | | // assuming all characters are part of the uuencode stream (which |
38 | | // does almost never hold due to required linebreaking; but |
39 | | // additional non-uu chars don't affect the output size), each |
40 | | // 4-tupel of them becomes a 3-tupel in the decoded octet |
41 | | // stream. So: |
42 | 106k | qsizetype result = ((insize + 3) / 4) * 3; |
43 | | // but all of them may be \n, so |
44 | 106k | if (newline == Codec::NewlineCRLF) { |
45 | 0 | result *= 2; // :-o |
46 | 0 | } |
47 | 106k | return result; |
48 | 106k | } |
49 | | |
50 | | Encoder *makeEncoder(NewlineType newline = Codec::NewlineLF) const override; |
51 | | |
52 | | Decoder *makeDecoder(NewlineType newline = Codec::NewlineLF) const override; |
53 | | }; |
54 | | |
55 | | } // namespace KCodecs |
56 | | |
57 | | #endif // KCODECS_UUENCODE_H |