| 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 | UUCodec() |
| 21 | : Codec() |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | ~UUCodec() override |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | const char *name() const override |
| 30 | { |
| 31 | return "x-uuencode" ; |
| 32 | } |
| 33 | |
| 34 | qsizetype maxEncodedSizeFor(qsizetype insize, NewlineType newline = Codec::NewlineLF) const override |
| 35 | { |
| 36 | Q_UNUSED(newline); |
| 37 | return insize; // we have no encoder! |
| 38 | } |
| 39 | |
| 40 | qsizetype maxDecodedSizeFor(qsizetype insize, NewlineType newline = Codec::NewlineLF) const override |
| 41 | { |
| 42 | // assuming all characters are part of the uuencode stream (which |
| 43 | // does almost never hold due to required linebreaking; but |
| 44 | // additional non-uu chars don't affect the output size), each |
| 45 | // 4-tupel of them becomes a 3-tupel in the decoded octet |
| 46 | // stream. So: |
| 47 | qsizetype result = ((insize + 3) / 4) * 3; |
| 48 | // but all of them may be \n, so |
| 49 | if (newline == Codec::NewlineCRLF) { |
| 50 | result *= 2; // :-o |
| 51 | } |
| 52 | return result; |
| 53 | } |
| 54 | |
| 55 | Encoder *makeEncoder(NewlineType newline = Codec::NewlineLF) const override; |
| 56 | |
| 57 | Decoder *makeDecoder(NewlineType newline = Codec::NewlineLF) const override; |
| 58 | }; |
| 59 | |
| 60 | } // namespace KCodecs |
| 61 | |
| 62 | #endif // KCODECS_UUENCODE_H |
| 63 | |