KCodecs 5.109.0
Classes | Enumerations | Functions
KCodecs Namespace Reference

A wrapper class for the most commonly used encoding and decoding algorithms. More...

Classes

class  Codec
 An abstract base class of codecs for common mail transfer encodings. More...
 
class  Decoder
 Stateful CTE decoder class. More...
 
class  Encoder
 Stateful encoder class. More...
 

Enumerations

enum  CharsetOption { NoOption = 0 , ForceDefaultCharset = 1 }
 Charset options for RFC2047 encoder. More...
 

Functions

QByteArray base45Decode (const QByteArray &in)
 Decodes the given data that was encoded using the base45 codec.
 
QByteArray base64Decode (const QByteArray &in)
 Decodes the given data that was encoded using the base64 algorithm.
 
void base64Decode (const QByteArray &in, QByteArray &out)
 Decodes the given data that was encoded with the base64 algorithm.
 
QByteArray base64Encode (const QByteArray &in)
 Encodes the given data using the base64 algorithm.
 
void base64Encode (const QByteArray &in, QByteArray &out, bool insertLFs=false)
 Encodes the given data using the base64 algorithm.
 
QString decodeRFC2047String (const QByteArray &src, QByteArray *usedCS, const QByteArray &defaultCS=QByteArray(), CharsetOption option=NoOption)
 Decodes string src according to RFC2047, i.e.
 
QString decodeRFC2047String (const QString &text)
 Decodes string text according to RFC2047, i.e., the construct =?charset?[qb]?encoded?=.
 
QByteArray encodeRFC2047String (const QString &src, const QByteArray &charset)
 Encodes string src according to RFC2047 using charset charset.
 
bool parseEncodedWord (const char *&, const char *, QString *, QByteArray *, QByteArray *, const QByteArray &, CharsetOption)
 
QByteArray quotedPrintableDecode (const QByteArray &in)
 Decodes a quoted-printable encoded data.
 
void quotedPrintableDecode (const QByteArray &in, QByteArray &out)
 Decodes a quoted-printable encoded data.
 
QByteArray quotedPrintableEncode (const QByteArray &in, bool useCRLF=true)
 Encodes the given data using the quoted-printable algorithm.
 
void quotedPrintableEncode (const QByteArray &in, QByteArray &out, bool useCRLF)
 Encodes the given data using the quoted-printable algorithm.
 
QByteArray uudecode (const QByteArray &in)
 Decodes the given data using the uudecode algorithm.
 
void uudecode (const QByteArray &in, QByteArray &out)
 Decodes the given data using the uudecode algorithm.
 

Detailed Description

A wrapper class for the most commonly used encoding and decoding algorithms.

Currently there is support for encoding and decoding input using base64, uu and the quoted-printable specifications.

Usage:

QByteArray input = "Aladdin:open sesame";
QByteArray result = KCodecs::base64Encode(input);
cout << "Result: " << result.data() << endl;
QByteArray base64Encode(const QByteArray &in)
Encodes the given data using the base64 algorithm.
Output should be
Result: QWxhZGRpbjpvcGVuIHNlc2FtZQ==

The above example makes use of the convenience functions (ones that accept/return null-terminated strings) to encode/decode a string. If what you need is to encode or decode binary data, then it is highly recommended that you use the functions that take an input and output QByteArray as arguments. These functions are specifically tailored for encoding and decoding binary data.

A collection of commonly used encoding and decoding algorithms.

Author
Dawit Alemayehu adawi.nosp@m.t@kd.nosp@m.e.org
Rik Hemsley rik@k.nosp@m.de.o.nosp@m.rg

Enumeration Type Documentation

◆ CharsetOption

Charset options for RFC2047 encoder.

Since
5.5
Enumerator
ForceDefaultCharset 

No special option.

Function Documentation

◆ base45Decode()

QByteArray KCodecs::base45Decode ( const QByteArray &  in)

Decodes the given data that was encoded using the base45 codec.

Parameters
indata to be decoded.
Returns
decoded string.
Since
5.84
See also
https://datatracker.ietf.org/doc/draft-faltstrom-base45/

◆ base64Decode() [1/2]

QByteArray KCodecs::base64Decode ( const QByteArray &  in)

Decodes the given data that was encoded using the base64 algorithm.

Parameters
indata to be decoded.
Returns
decoded string.

◆ base64Decode() [2/2]

void KCodecs::base64Decode ( const QByteArray &  in,
QByteArray &  out 
)

Decodes the given data that was encoded with the base64 algorithm.

Use this function if you want the result of the decoding to be placed in another array which cuts down the number of copy operation that have to be performed in the process. This is also the preferred method for decoding an encoded binary data.

NOTE: the output array is first reset and then resized appropriately before use, hence, all data stored in the output array will be lost.

Parameters
indata to be decoded.
outdecoded data.

◆ base64Encode() [1/2]

QByteArray KCodecs::base64Encode ( const QByteArray &  in)

Encodes the given data using the base64 algorithm.

The boolean argument determines if the encoded data is going to be restricted to 76 characters or less per line as specified by RFC 2045. If insertLFs is true, then there will be 76 characters or less per line.

Parameters
indata to be encoded.
insertLFslimit the number of characters per line.
Returns
base64 encoded string.
Since
5.5

◆ base64Encode() [2/2]

void KCodecs::base64Encode ( const QByteArray &  in,
QByteArray &  out,
bool  insertLFs = false 
)

Encodes the given data using the base64 algorithm.

Use this function if you want the result of the encoding to be placed in another array which cuts down the number of copy operation that have to be performed in the process. This is also the preferred method for encoding binary data.

The boolean argument determines if the encoded data is going to be restricted to 76 characters or less per line as specified by RFC 2045. If insertLFs is true, then there will be 76 characters or less per line.

NOTE: the output array is first reset and then resized appropriately before use, hence, all data stored in the output array will be lost.

Parameters
indata to be encoded.
outencoded data.
insertLFslimit the number of characters per line.

◆ decodeRFC2047String() [1/2]

QString KCodecs::decodeRFC2047String ( const QByteArray &  src,
QByteArray *  usedCS,
const QByteArray &  defaultCS = QByteArray(),
CharsetOption  option = NoOption 
)

Decodes string src according to RFC2047, i.e.

the construct =?charset?[qb]?encoded?=

Parameters
srcsource string.
usedCSthe name of any detected charset or, in case of multiple different ones, "UTF-8" as that of a super charset is returned here
defaultCSthe charset to use in case the detected one isn't known to us.
optionoptions for the encoder
Returns
the decoded string.
Since
5.5

◆ decodeRFC2047String() [2/2]

QString KCodecs::decodeRFC2047String ( const QString &  text)

Decodes string text according to RFC2047, i.e., the construct =?charset?[qb]?encoded?=.

Parameters
textsource string
Returns
the decoded string

◆ encodeRFC2047String()

QByteArray KCodecs::encodeRFC2047String ( const QString &  src,
const QByteArray &  charset 
)

Encodes string src according to RFC2047 using charset charset.

This function also makes commas, quotes and other characters part of the encoded name, for example the string "Jöhn Döe" <john@.nosp@m.exam.nosp@m.ple.c.nosp@m.om"> would be encoded as <encoded word for "Jöhn Döe"> john@.nosp@m.exam.nosp@m.ple.c.nosp@m.om, i.e. the opening and closing quote mark would be part of the encoded word. Therefore don't use this function for input strings that contain semantically meaningful characters, like the quoting marks in this example.

Parameters
srcsource string.
charsetcharset to use. If it can't encode the string, UTF-8 will be used instead.
Returns
the encoded string.
Since
5.5

◆ quotedPrintableDecode() [1/2]

QByteArray KCodecs::quotedPrintableDecode ( const QByteArray &  in)

Decodes a quoted-printable encoded data.

Accepts data with CRLF or standard unix line breaks.

Parameters
indata to be decoded.
Returns
decoded string.
Since
5.5

◆ quotedPrintableDecode() [2/2]

void KCodecs::quotedPrintableDecode ( const QByteArray &  in,
QByteArray &  out 
)

Decodes a quoted-printable encoded data.

Accepts data with CRLF or standard unix line breaks. Use this function if you want the result of the decoding to be placed in another array which cuts down the number of copy operation that have to be performed in the process. This is also the preferred method for decoding an encoded binary data.

NOTE: the output array is first reset and then resized appropriately before use, hence, all data stored in the output array will be lost.

Parameters
indata to be decoded.
outdecoded data.

◆ quotedPrintableEncode() [1/2]

QByteArray KCodecs::quotedPrintableEncode ( const QByteArray &  in,
bool  useCRLF = true 
)

Encodes the given data using the quoted-printable algorithm.

Parameters
indata to be encoded.
useCRLFif true the input data is expected to have CRLF line breaks and the output will have CRLF line breaks, too.
Returns
quoted-printable encoded string.

◆ quotedPrintableEncode() [2/2]

void KCodecs::quotedPrintableEncode ( const QByteArray &  in,
QByteArray &  out,
bool  useCRLF 
)

Encodes the given data using the quoted-printable algorithm.

Use this function if you want the result of the encoding to be placed in another array which cuts down the number of copy operation that have to be performed in the process. This is also the preferred method for encoding binary data.

NOTE: the output array is first reset and then resized appropriately before use, hence, all data stored in the output array will be lost.

Parameters
indata to be encoded.
outencoded data.
useCRLFif true the input data is expected to have CRLF line breaks and the output will have CRLF line breaks, too.

◆ uudecode() [1/2]

QByteArray KCodecs::uudecode ( const QByteArray &  in)

Decodes the given data using the uudecode algorithm.

Any 'begin' and 'end' lines like those generated by the utilities in unix and unix-like OS will be automatically ignored.

Parameters
indata to be decoded.
Returns
decoded string.

◆ uudecode() [2/2]

void KCodecs::uudecode ( const QByteArray &  in,
QByteArray &  out 
)

Decodes the given data using the uudecode algorithm.

Use this function if you want the result of the decoding to be placed in another array which cuts down the number of copy operation that have to be performed in the process. This is the preferred method for decoding binary data.

Any 'begin' and 'end' lines like those generated by the utilities in unix and unix-like OS will be automatically ignored.

NOTE: the output array is first reset and then resized appropriately before use, hence, all data stored in the output array will be lost.

Parameters
indata to be decoded.
outuudecoded data.