KCodecs

kcodecsidentity.cpp
Go to the documentation of this file.
1 /* -*- c++ -*-
2  SPDX-FileCopyrightText: 2004 Marc Mutz <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
19 #include "kcodecsidentity.h"
20 
21 #include <qdebug.h>
22 
23 #include <QByteArray>
24 
25 #include <cstring>
26 
27 using namespace KCodecs;
28 
29 class IdentityEnDecoder : public Encoder, public Decoder
30 {
31 protected:
32  friend class KCodecs::IdentityCodec;
33  IdentityEnDecoder(Codec::NewlineType newline)
34  : Encoder(Codec::NewlineLF)
35  {
36  if (newline == Codec::NewlineCRLF) {
37  qWarning() << "IdentityEnDecoder: CRLF isn't yet supported!";
38  }
39  }
40 
41 public:
42  ~IdentityEnDecoder() {}
43 
44  bool encode(const char *&scursor, const char *const send,
45  char *&dcursor, const char *const dend) override
46  {
47  return decode(scursor, send, dcursor, dend);
48  }
49 
50  bool decode(const char *&scursor, const char *const send,
51  char *&dcursor, const char *const dend) override;
52 
53  bool finish(char *&dcursor, const char *const dend) override
54  {
55  Q_UNUSED(dcursor);
56  Q_UNUSED(dend);
57  return true;
58  }
59 };
60 
61 Encoder *IdentityCodec::makeEncoder(Codec::NewlineType newline) const
62 {
63  return new IdentityEnDecoder(newline);
64 }
65 
66 Decoder *IdentityCodec::makeDecoder(Codec::NewlineType newline) const
67 {
68  return new IdentityEnDecoder(newline);
69 }
70 
71 /********************************************************/
72 /********************************************************/
73 /********************************************************/
74 
75 bool IdentityEnDecoder::decode(const char *&scursor, const char *const send,
76  char *&dcursor, const char *const dend)
77 {
78  const int size = qMin(send - scursor, dcursor - dend);
79  if (size > 0) {
80  std::memmove(dcursor, scursor, size);
81  dcursor += size;
82  scursor += size;
83  }
84  return scursor == send;
85 }
86 
87 QByteArray IdentityCodec::encode(const QByteArray &src, Codec::NewlineType newline) const
88 {
89  if (newline == Codec::NewlineCRLF) {
90  qWarning() << "IdentityCodec::encode(): CRLF not yet supported!";
91  }
92  return src;
93 }
94 
95 QByteArray IdentityCodec::decode(const QByteArray &src, Codec::NewlineType newline) const
96 {
97  if (newline == Codec::NewlineCRLF) {
98  qWarning() << "IdentityCodec::decode(): CRLF not yet supported!";
99  }
100  return src;
101 }
An abstract base class of codecs for common mail transfer encodings.
Definition: kcodecs.h:367
QByteArray decode(const QByteArray &src, Codec::NewlineType newline=Codec::NewlineLF) const override
QByteArray encode(const QByteArray &src, Codec::NewlineType newline=Codec::NewlineLF) const override
Encoder * makeEncoder(Codec::NewlineType newline=Codec::NewlineCRLF) const override
This file is part of the API for handling MIME data and defines the Identity, seven-bit-text, eight-bit-text, and eight-bit-binary Codec classes.
A wrapper class for the most commonly used encoding and decoding algorithms.
Definition: kcodecs.cpp:49
Stateful encoder class.
Definition: kcodecs.h:689
A class representing the Identify codec.
Stateful CTE decoder class.
Definition: kcodecs.h:632
Decoder * makeDecoder(Codec::NewlineType newline=Codec::NewlineCRLF) const override
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun May 24 2020 23:03:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.