dkenc.h File Reference

Encoding changes module. More...

Go to the source code of this file.

Functions

unsigned long dkenc_ntohl (unsigned long l)
 Convert long (32 bit integer) from network byte order to host byte order.
unsigned long dkenc_htonl (unsigned long l)
 Convert long (32 bit integer) from host byte order to network byte order.
unsigned short dkenc_ntohs (unsigned short s)
 Convert short (16 bit integer) from network byte order to host byte order.
unsigned short dkenc_htons (unsigned short s)
 Convert short (16 bit integer) from host byte order to network byte order.
int dkenc_utf82uc (dk_udword *ucp, dk_ubyte *u8p, size_t u8l, size_t *u8u)
 Convert an UTF-8 encoded character into the appropriate 32 bit character.
size_t dkenc_uc2utf8 (dk_udword c, dk_ubyte *u8p, size_t u8l)
 Convert 32-bit character to UTF-8.
int dkenc_ipaddr_to_ul (char *s, unsigned long *u)
 Convert text IP address to unsigned long in host representation.
char * dkenc_str_utf82bits8 (char *s, int *p)
 Convert UTF-8 encoded string to 8-bit LATIN-1 encoded string.
char * dkenc_str_bits82utf8 (char *s)
 Convert 8-bit LATIN-1 encoded string to UTF-8 encoded string.
int dkenc_bin_to_ra85 (char *dp, size_t ds, char *sp, size_t ss)
 Convert binary data to reverse ASCII-85 encoded string.
size_t dkenc_ra85_to_bin (char *dp, size_t ds, char *sp, size_t ss)
 Convert reverse ASCII-85 encoded data to binary data.
size_t dkenc_ra85string_to_bin (char *dp, size_t ds, char *sp)
 Convert reverse ASCII-85 encoded string to binary data.
int dkenc_bin_to_a85 (char *dp, size_t ds, char *sp, size_t ss)
 Convert binary data to ASCII-85 encoded string.
size_t dkenc_a85_to_bin (char *dp, size_t ds, char *sp, size_t ss)
 Convert ASCII-85 encoded data to binary data.
size_t dkenc_a85string_to_bin (char *dp, size_t ds, char *sp)
 Convert ASCII-85 encoded string to binary data.
int dkenc_bin_to_hex (char *dp, size_t ds, char *sp, size_t ss)
 Convert binary data to hex encoded string.
size_t dkenc_hex_to_bin (char *dp, size_t ds, char *sp, size_t ss)
 Convert hex encoded data to binary data.
size_t dkenc_hexstring_to_bin (char *dp, size_t ds, char *sp)
 Convert hex encoded string to binary data.
size_t dkenc_size_bin_to_a85 (size_t sz)
 Calculate buffer size needed to convert binary data to ASCII85 or reverse ASCII85 string.
size_t dkenc_size_a85_to_bin (size_t sz)
 Calculate buffer size needed to convert ASCII85 or reverse-ASCII85 encoded data to binary.
size_t dkenc_size_a85string_to_bin (char *s)
 Calculate bufer size needed to convert an ASCII85 or reverse-ASCII85 encoded string to binary.
size_t dkenc_size_bin_to_hex (size_t sz)
 Calculate buffer size needed to convert binary data to hexadecimal string.
size_t dkenc_size_hex_to_bin (size_t sz)
 Calculate bufer size needed to convert a hex encoded string to binary.
size_t dkenc_size_hexstring_to_bin (char *s)
 Calculate bufer size needed to convert a hex encoded string to binary.


Detailed Description

Encoding changes module.

This module contains functions to change encodings.

The dkenc_ntohl() function group is intended as replacement for ntohl() and friends. On Windows systems these functions are in winsock2.dll which is an optional DLL typically not installed on standalone systems. To change byte order for data read from file we need replacement functions.


Function Documentation

size_t dkenc_a85_to_bin ( char *  dp,
size_t  ds,
char *  sp,
size_t  ss 
)

Convert ASCII-85 encoded data to binary data.

Parameters:
dp Pointer to destination buffer.
ds Destination buffer size in bytes.
sp Pointer to source buffer.
ss Source buffer size in bytes.
Returns:
The number of bytes written to the destination buffer.

size_t dkenc_a85string_to_bin ( char *  dp,
size_t  ds,
char *  sp 
)

Convert ASCII-85 encoded string to binary data.

Parameters:
dp Pointer to destination buffer.
ds Destination buffer size in bytes.
sp Pointer to source string.
Returns:
The number of bytes written to the destination buffer.

int dkenc_bin_to_a85 ( char *  dp,
size_t  ds,
char *  sp,
size_t  ss 
)

Convert binary data to ASCII-85 encoded string.

Parameters:
dp Pointer to destination buffer.
ds Destination buffer size in bytes.
sp Pointer to source buffer.
ss Source buffer size in bytes.
Returns:
1 on success, 0 on error.

int dkenc_bin_to_hex ( char *  dp,
size_t  ds,
char *  sp,
size_t  ss 
)

Convert binary data to hex encoded string.

Uppercase characters are used for 'A', 'B', 'C', D', 'E' and 'F'.

Parameters:
dp Pointer to destination buffer.
ds Destination buffer size in bytes.
sp Pointer to source buffer.
ss Source buffer size in bytes.
Returns:
1 on success, 0 on error.

int dkenc_bin_to_ra85 ( char *  dp,
size_t  ds,
char *  sp,
size_t  ss 
)

Convert binary data to reverse ASCII-85 encoded string.

Parameters:
dp Pointer to destination buffer.
ds Destination buffer size in bytes.
sp Pointer to source buffer.
ss Source buffer size in bytes.
Returns:
1 on success, 0 on error.

size_t dkenc_hex_to_bin ( char *  dp,
size_t  ds,
char *  sp,
size_t  ss 
)

Convert hex encoded data to binary data.

Both upper- and lowercase characters can be used for 'a', 'b', 'c', 'd', 'e' and 'f'.

Parameters:
dp Pointer to destination buffer.
ds Destination buffer size in bytes.
sp Pointer to source buffer.
ss Source buffer size in bytes.
Returns:
The number of bytes written to the destination buffer.

size_t dkenc_hexstring_to_bin ( char *  dp,
size_t  ds,
char *  sp 
)

Convert hex encoded string to binary data.

Parameters:
dp Pointer to destination buffer.
ds Destination buffer size in bytes.
sp Pointer to source string.
Returns:
The number of bytes written to the destination buffer.

unsigned long dkenc_htonl ( unsigned long  l  ) 

Convert long (32 bit integer) from host byte order to network byte order.

Parameters:
l The long unsigned in host byte order.
Returns:
The long unsigned in network byte order.

unsigned short dkenc_htons ( unsigned short  s  ) 

Convert short (16 bit integer) from host byte order to network byte order.

Parameters:
s The unsigned short in host byte order.
Returns:
The unsigned short in network byte order.

int dkenc_ipaddr_to_ul ( char *  s,
unsigned long *  u 
)

Convert text IP address to unsigned long in host representation.

Parameters:
s String containing the IP address in dotted decimal notation.
u Pointer to unsigned long variable to receive the conversion result.
Returns:
Flag to indicate success (non-zero value) or error (0).

unsigned long dkenc_ntohl ( unsigned long  l  ) 

Convert long (32 bit integer) from network byte order to host byte order.

Parameters:
l Long unsigned in network byte order.
Returns:
The long unsigned in host byte order.

unsigned short dkenc_ntohs ( unsigned short  s  ) 

Convert short (16 bit integer) from network byte order to host byte order.

Parameters:
s The unsigned short number in network byte order.
Returns:
The unsigned short number in host byte order.

size_t dkenc_ra85_to_bin ( char *  dp,
size_t  ds,
char *  sp,
size_t  ss 
)

Convert reverse ASCII-85 encoded data to binary data.

Parameters:
dp Pointer to destination buffer.
ds Destination buffer size in bytes.
sp Pointer to source buffer.
ss Source buffer size in bytes.
Returns:
The number of bytes written to the destination buffer.

size_t dkenc_ra85string_to_bin ( char *  dp,
size_t  ds,
char *  sp 
)

Convert reverse ASCII-85 encoded string to binary data.

Parameters:
dp Pointer to destination buffer.
ds Destination buffer size in bytes.
sp Pointer to source string.

size_t dkenc_size_a85_to_bin ( size_t  sz  ) 

Calculate buffer size needed to convert ASCII85 or reverse-ASCII85 encoded data to binary.

Parameters:
sz Source data size.
Returns:
Needed destination buffer size.

size_t dkenc_size_a85string_to_bin ( char *  s  ) 

Calculate bufer size needed to convert an ASCII85 or reverse-ASCII85 encoded string to binary.

Parameters:
s The encoded string.
Returns:
Needed destination buffer size.

size_t dkenc_size_bin_to_a85 ( size_t  sz  ) 

Calculate buffer size needed to convert binary data to ASCII85 or reverse ASCII85 string.

Parameters:
sz Source data size.
Returns:
Needed destination buffer size.

size_t dkenc_size_bin_to_hex ( size_t  sz  ) 

Calculate buffer size needed to convert binary data to hexadecimal string.

Parameters:
sz Source data size.
Returns:
Needed destination buffer size.

size_t dkenc_size_hex_to_bin ( size_t  sz  ) 

Calculate bufer size needed to convert a hex encoded string to binary.

Parameters:
s The encoded string.
Returns:
Needed destination buffer size.

size_t dkenc_size_hexstring_to_bin ( char *  s  ) 

Calculate bufer size needed to convert a hex encoded string to binary.

Parameters:
s The encoded string.
Returns:
Needed destination buffer size.

char* dkenc_str_bits82utf8 ( char *  s  ) 

Convert 8-bit LATIN-1 encoded string to UTF-8 encoded string.

The function returns a pointer to a new string in dynamically allocated memory. You must release the string after usage, call dk_delete().

Parameters:
s The LATIN-1 encoded string.
Returns:
Pointer (dynamic) on success, NULL on error (not enough memory).

char* dkenc_str_utf82bits8 ( char *  s,
int *  p 
)

Convert UTF-8 encoded string to 8-bit LATIN-1 encoded string.

The function returns a pointer to a new string in dynamically allocated memory. You must release the string after usage, call dk_delete().

Parameters:
s UTF-8 encoded string.
p Pointer to a variable to receive the error code (if any).
Returns:
Pointer (dynamic) on success, NULL on error. On error the error code variable is set to
  • DK_ERR_MATH_OOR if the decoding result character is out of range.
  • DK_ERR_INVALID_ARGS if s is NULL or a decoding error occured.
  • DK_ERR_MEMORY if there is not enough memory.

size_t dkenc_uc2utf8 ( dk_udword  c,
dk_ubyte u8p,
size_t  u8l 
)

Convert 32-bit character to UTF-8.

Parameters:
c The character to convert.
u8p Buffer to receive the UTF-8 encoded result.
u8l Length of u8p.
Returns:
The number of bytes stored into u8p (0 on error).
Parameters:
c The 32-bit character.
u8p Buffer to receive UTF-8 encoded result.
u8l Length of u8l.
Returns:
The number of bytes produced.

int dkenc_utf82uc ( dk_udword ucp,
dk_ubyte u8p,
size_t  u8l,
size_t *  u8u 
)

Convert an UTF-8 encoded character into the appropriate 32 bit character.

Parameters:
ucp Pointer to a variable for conversion result.
u8p Pointer to buffer containing UTF-8 encoded data.
u8l Number of bytes available in u8p.
u8u Pointer to variable to store the number of bytes used from u8p.
Returns:
Flag to indicate success (non-zero value) or error (0).
Convert an UTF-8 encoded character into the appropriate 32 bit character.

Parameters:
ucp Pointer to variable for result.
u8p Buffer containing UTF-8 encoded text.
u8l Number of bytes in buffer.
u8u Pointer to variable to receive number of bytes used.
Returns:
1 on success, 0 on error.


Generated on Mon Feb 16 17:12:04 2009 for dklibs by  doxygen 1.5.6