• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

KCodecs Namespace Reference


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 <adawit@kde.org>

Rik Hemsley <rik@kde.org>


Functions

void base64Decode (const QByteArray &in, QByteArray &out)
QByteArray base64Decode (const QByteArray &in)
void base64Encode (const QByteArray &in, QByteArray &out, bool insertLFs=false)
QByteArray base64Encode (const QByteArray &in, bool insertLFs=false)
void quotedPrintableDecode (const QByteArray &in, QByteArray &out)
QByteArray quotedPrintableDecode (const QByteArray &in)
void quotedPrintableEncode (const QByteArray &in, QByteArray &out, bool useCRLF)
QByteArray quotedPrintableEncode (const QByteArray &in, bool useCRLF=true)
void uudecode (const QByteArray &in, QByteArray &out)
QByteArray uudecode (const QByteArray &in)
void uuencode (const QByteArray &in, QByteArray &out)
QByteArray uuencode (const QByteArray &in)

Variables

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

Function Documentation

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:
in data to be decoded.
out decoded data.

Definition at line 430 of file kcodecs.cpp.

QByteArray KCodecs::base64Decode ( const QByteArray &  in  ) 

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

Parameters:
in data to be decoded.
Returns:
decoded string.

Definition at line 423 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:
in data to be encoded.
out encoded data.
insertLFs limit the number of characters per line.

Definition at line 351 of file kcodecs.cpp.

QByteArray KCodecs::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:
in data to be encoded.
insertLFs limit the number of characters per line.
Returns:
base64 encoded string.

Definition at line 344 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:
in data to be decoded.
out decoded data.

Definition at line 286 of file kcodecs.cpp.

QByteArray KCodecs::quotedPrintableDecode ( const QByteArray &  in  ) 

Decodes a quoted-printable encoded data.

Accepts data with CRLF or standard unix line breaks.

Parameters:
in data to be decoded.
Returns:
decoded string.

Definition at line 278 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:
in data to be encoded.
out encoded data.
useCRLF if true the input data is expected to have CRLF line breaks and the output will have CRLF line breaks, too.

Definition at line 162 of file kcodecs.cpp.

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

Encodes the given data using the quoted-printable algorithm.

Parameters:
in data to be encoded.
useCRLF if 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 155 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:
in data to be decoded.
out uudecoded data.

Definition at line 604 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:
in data to be decoded.
Returns:
decoded string.

Definition at line 597 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:
in data to be uuencoded.
out uudecoded data.

Definition at line 518 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:
in data to be uuencoded
Returns:
uuencoded string.

Definition at line 511 of file kcodecs.cpp.


Variable Documentation

const char KCodecs::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 75 of file kcodecs.cpp.

const char KCodecs::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 63 of file kcodecs.cpp.

const char KCodecs::hexChars[16] [static]

Initial value:

{
  '0', '1', '2', '3', '4', '5', '6', '7',
  '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
}

Definition at line 127 of file kcodecs.cpp.

const unsigned int KCodecs::maxQPLineLength = 70 [static]

Definition at line 133 of file kcodecs.cpp.

const char KCodecs::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 107 of file kcodecs.cpp.

const char KCodecs::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 95 of file kcodecs.cpp.

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal