KCodecs

KCodecs Namespace Reference

Classes

class  Base64Codec
 
class  BinaryCodec
 
class  Codec
 
class  Decoder
 
class  EightBitCodec
 
class  Encoder
 
class  IdentityCodec
 
class  QuotedPrintableCodec
 
class  Rfc2047BEncodingCodec
 
class  Rfc2047QEncodingCodec
 
class  Rfc2231EncodingCodec
 
class  SevenBitCodec
 
class  UUCodec
 

Enumerations

enum  CharsetOption { NoOption = 0, ForceDefaultCharset = 1 }
 

Functions

KCODECS_EXPORT QByteArray base64Decode (const QByteArray &in)
 
KCODECS_EXPORT void base64Decode (const QByteArray &in, QByteArray &out)
 
KCODECS_EXPORT QByteArray base64Encode (const QByteArray &in)
 
KCODECS_EXPORT QByteArray base64Encode (const QByteArray &in, bool insertLFs)
 
KCODECS_EXPORT void base64Encode (const QByteArray &in, QByteArray &out, bool insertLFs=false)
 
static char binToHex (uchar value)
 
QByteArray cachedCharset (const QByteArray &name)
 
KCODECS_EXPORT QString decodeRFC2047String (const QString &text)
 
KCODECS_EXPORT QString decodeRFC2047String (const QByteArray &src, QByteArray *usedCS, const QByteArray &defaultCS=QByteArray(), CharsetOption option=NoOption)
 
KCODECS_EXPORT QByteArray encodeRFC2047String (const QString &src, const QByteArray &charset)
 
static uchar highNibble (uchar ch)
 
static bool keep (uchar ch)
 
static uchar lowNibble (uchar ch)
 
KCODECS_EXPORT QByteArray quotedPrintableDecode (const QByteArray &in)
 
KCODECS_EXPORT void quotedPrintableDecode (const QByteArray &in, QByteArray &out)
 
static int QuotedPrintableDecoder_maxDecodedSizeFor (int insize, Codec::NewlineType newline)
 
KCODECS_EXPORT QByteArray quotedPrintableEncode (const QByteArray &in, bool useCRLF=true)
 
KCODECS_EXPORT void quotedPrintableEncode (const QByteArray &in, QByteArray &out, bool useCRLF)
 
static uchar uuDecode (uchar c)
 
KCODECS_EXPORT QByteArray uudecode (const QByteArray &in)
 
KCODECS_EXPORT void uudecode (const QByteArray &in, QByteArray &out)
 
KCODECS_EXPORT QByteArray uuencode (const QByteArray &in)
 
KCODECS_EXPORT void uuencode (const QByteArray &in, QByteArray &out)
 

Variables

static QList< QByteArraycharsetCache
 
const uchar eTextMap [16]
 

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";
cout << "Result: " << result.data() << endl;
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[email protected][email protected][email protected]e.org
Rik Hemsley [email protected][email protected]de.o[email protected]rg

Enumeration Type Documentation

Charset options for RFC2047 encoder.

Since
5.5
Enumerator
ForceDefaultCharset 

No special option.

Definition at line 283 of file kcodecs.h.

Function Documentation

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.

Definition at line 115 of file kcodecs.cpp.

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.

Definition at line 121 of file kcodecs.cpp.

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

Definition at line 94 of file kcodecs.cpp.

QByteArray KCodecs::base64Encode ( const QByteArray in,
bool  insertLFs 
)

KCodecs::base64Encode(QByteArray)

Deprecated:
Since 5.5, use KCodecs::base64Encode(QByteArray) instead.

Definition at line 101 of file kcodecs.cpp.

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.

Definition at line 108 of file kcodecs.cpp.

static char KCodecs::binToHex ( uchar  value)
inlinestatic

Converts a 4-bit value into its hexadecimal characater representation.

So input of value [0,15] returns ['0','1',... 'F']. Input values greater than 15 will produce undesired results.

Parameters
valueis an unsigned character containing the 4-bit input value.

Definition at line 47 of file kcodecsqp.cpp.

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

Definition at line 351 of file kcodecs.cpp.

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 detected 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

Definition at line 357 of file kcodecs.cpp.

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" <[email protected][email protected]exam[email protected]ple.c[email protected]om"> would be encoded as <encoded word for "Jöhn Döe"> [email protected][email protected]exam[email protected]ple.c[email protected]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

Definition at line 415 of file kcodecs.cpp.

static uchar KCodecs::highNibble ( uchar  ch)
inlinestatic

Returns the high-order 4 bits of an 8-bit value in another 8-bit value.

Parameters
chis an unsigned character containing the 8-bit input value.

Definition at line 60 of file kcodecsqp.cpp.

static bool KCodecs::keep ( uchar  ch)
inlinestatic

Returns true if the specified value is a not Control character or question mark; else true.

Parameters
chis an unsigned character containing the 8-bit input value.

Definition at line 79 of file kcodecsqp.cpp.

static uchar KCodecs::lowNibble ( uchar  ch)
inlinestatic

Returns the low-order 4 bits of an 8-bit value in another 8-bit value.

Parameters
chis an unsigned character containing the 8-bit input value.

Definition at line 69 of file kcodecsqp.cpp.

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

Definition at line 83 of file kcodecs.cpp.

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.

Definition at line 89 of file kcodecs.cpp.

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.

Definition at line 72 of file kcodecs.cpp.

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.

Definition at line 78 of file kcodecs.cpp.

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.

Definition at line 141 of file kcodecs.cpp.

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.

Definition at line 147 of file kcodecs.cpp.

QByteArray KCodecs::uuencode ( const QByteArray in)

Encodes the given data using the uuencode algorithm.

The output is split into lines starting with the number of encoded octets in the line and ending with a newline. No line is longer than 45 octets (60 characters), excluding the line terminator.

Parameters
indata to be uuencoded
Returns
uuencoded string.
Deprecated:
Not implemented, always returns an empty bytearray.

Definition at line 127 of file kcodecs.cpp.

void KCodecs::uuencode ( const QByteArray in,
QByteArray out 
)

Encodes the given data using the uuencode algorithm.

Use this function if you want the result of the encoding to be placed in another array and cut down the number of copy operation that have to be performed in the process. This is the preffered 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 uuencoded.
outan empty byte array
Deprecated:
Not implemented, always set out to an empty bytearray.

Definition at line 135 of file kcodecs.cpp.

Variable Documentation

const uchar KCodecs::eTextMap[16]
Initial value:
= {
0x00, 0x00, 0x00, 0x00,
0x40, 0x35, 0xFF, 0xC0,
0x7F, 0xFF, 0xFF, 0xE0,
0x7F, 0xFF, 0xFF, 0xE0
}

Definition at line 32 of file kcodecsqp.cpp.

This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 22:44:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.