MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
Functions | Variables
QCodecs Namespace Reference

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

Functions

MBASE_PUBLIC QByteArray quotedPrintableEncode (const QByteArray &in, bool useCRLF=true)
 Encodes the given data using the quoted-printable algorithm.
MBASE_PUBLIC void quotedPrintableEncode (const QByteArray &in, QByteArray &out, bool useCRLF)
 Encodes the given data using the quoted-printable algorithm.
MBASE_PUBLIC QByteArray quotedPrintableDecode (const QByteArray &in)
 Decodes a quoted-printable encoded data.
MBASE_PUBLIC void quotedPrintableDecode (const QByteArray &in, QByteArray &out)
 Decodes a quoted-printable encoded data.
MBASE_PUBLIC QByteArray uuencode (const QByteArray &in)
 Encodes the given data using the uuencode algorithm.
MBASE_PUBLIC void uuencode (const QByteArray &in, QByteArray &out)
 Encodes the given data using the uuencode algorithm.
MBASE_PUBLIC QByteArray uudecode (const QByteArray &in)
 Decodes the given data using the uudecode algorithm.
MBASE_PUBLIC void uudecode (const QByteArray &in, QByteArray &out)
 Decodes the given data using the uudecode algorithm.
MBASE_PUBLIC QByteArray base64Encode (const QByteArray &in, bool insertLFs=false)
 Encodes the given data using the base64 algorithm.
MBASE_PUBLIC void base64Encode (const QByteArray &in, QByteArray &out, bool insertLFs=false)
 Encodes the given data using the base64 algorithm.
MBASE_PUBLIC QByteArray base64Decode (const QByteArray &in)
 Decodes the given data that was encoded using the base64 algorithm.
MBASE_PUBLIC void base64Decode (const QByteArray &in, QByteArray &out)
 Decodes the given data that was encoded with the base64 algorithm.

Variables

static const char Base64EncMap [64]
static const char Base64DecMap [128]
static const char UUEncMap [64]
static const char UUDecMap [128]
static const char hexChars [16]
static const unsigned int maxQPLineLength = 70

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

Function Documentation

QByteArray QCodecs::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 156 of file mcodecs.cpp.

void QCodecs::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 163 of file mcodecs.cpp.

QByteArray QCodecs::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.

Definition at line 279 of file mcodecs.cpp.

void QCodecs::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 287 of file mcodecs.cpp.

QByteArray QCodecs::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.

Definition at line 510 of file mcodecs.cpp.

void QCodecs::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.
outuudecoded data.

Definition at line 517 of file mcodecs.cpp.

QByteArray QCodecs::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 596 of file mcodecs.cpp.

void QCodecs::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 603 of file mcodecs.cpp.

QByteArray QCodecs::base64Encode ( const QByteArray &  in,
bool  insertLFs = false 
)

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.

Definition at line 343 of file mcodecs.cpp.

Referenced by HttpComms::headerReceived(), ShoutCastRequest::setUrl(), and IceCastRequest::setUrl().

void QCodecs::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 350 of file mcodecs.cpp.

QByteArray QCodecs::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 422 of file mcodecs.cpp.

void QCodecs::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 429 of file mcodecs.cpp.

Variable Documentation

const char QCodecs::Base64EncMap[64]
static
Initial value:
{
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E,
0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33,
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F
}

Definition at line 64 of file mcodecs.cpp.

Referenced by base64Encode().

const char QCodecs::Base64DecMap[128]
static
Initial value:
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F,
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00
}

Definition at line 76 of file mcodecs.cpp.

Referenced by base64Decode().

const char QCodecs::UUEncMap[64]
static
Initial value:
{
0x60, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F
}

Definition at line 96 of file mcodecs.cpp.

Referenced by uuencode().

const char QCodecs::UUDecMap[128]
static
Initial value:
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}

Definition at line 108 of file mcodecs.cpp.

Referenced by uudecode().

const char QCodecs::hexChars[16]
static
Initial value:
{
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
}

Definition at line 128 of file mcodecs.cpp.

Referenced by quotedPrintableDecode(), and quotedPrintableEncode().

const unsigned int QCodecs::maxQPLineLength = 70
static

Definition at line 134 of file mcodecs.cpp.

Referenced by quotedPrintableEncode().