Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

charconvert.h File Reference

Character converting functions. More...

Go to the source code of this file.

Functions

u_char * charset_convert (const u_char *toencode, size_t in_len, const u_char *from_charset, const u_char *to_charset, size_t *out_len_p)
u_char * htmlentities (const u_char *string, int sq)
size_t print_htmlentities_encoded (const u_char *string, int sq, FILE *handle)
int utf8_to_unicode (const u_char *s, size_t n, u_int32_t *num)
u_char * htmlentities_charset_convert (const u_char *toencode, const u_char *from, const u_char *to, size_t *outlen, int sq)
u_char * charset_convert_entities (const u_char *toencode, size_t in_len, const u_char *from, const u_char *to, size_t *outlen)
int is_valid_utf8_string (const u_char *str, size_t len)


Detailed Description

Character converting functions.

Author:
Christian Kruse, <cjk@wwwtech.de>
This file contains general character converting functions. Its a wrapper around the libiconv, which provides conversion between many charsets.

Definition in file charconvert.h.


Function Documentation

u_char* charset_convert const u_char *  toencode,
size_t  in_len,
const u_char *  from_charset,
const u_char *  to_charset,
size_t *  out_len_p
 

This function tries to convert a string from charset from_charset to charset to_charset.

Parameters:
toencode The string to convert
in_len The length of the string to convert
from_charset The starting charset
to_charset The target charset
out_len_p Pointer to a size_t variable. Will be filled with the length of the converted string
Returns:
The converted string on success or NULL on failure
Attention:
You have to free() the returned string!

Definition at line 108 of file charconvert.c.

u_char* charset_convert_entities const u_char *  toencode,
size_t  in_len,
const u_char *  from,
const u_char *  to,
size_t *  outlen
 

This function converts a string from a given charset to a given charset. If a character cannot be shown in the target charset it would be replaced by an HTML entity. Everything else will not be touched (e.g. > will be > after calling, too).

Parameters:
toencode The string to encode
in_len The length of the string to encode
from The source character set
to The target character set
outlen A reference to a size_t variable to store the length of the new string in it
Returns:
NULL on failure, the new string on success

Definition at line 400 of file charconvert.c.

u_char* htmlentities const u_char *  string,
int  sq
 

This function converts HTML special characters to their entities. These are < to <, > to >, & to & and " to ". If you set the parameter sq to 1, ' will be encoded to &#39;, too.

Parameters:
string The string to convert
sq Switch which defines if ' shall be converted, too
Returns:
The converted string on success or NULL on failure
Attention:
You have to free() the returned string!

Definition at line 168 of file charconvert.c.

u_char* htmlentities_charset_convert const u_char *  toencode,
const u_char *  from,
const u_char *  to,
size_t *  outlen,
int  sq
 

This function converts a string from a given charset to a given charset and encodes all html active chars (<, >, &, " and optional '). If a character doesn't exist in the target charset, the character will be replaced by an named entity (if exists) or a unicode entity.

Parameters:
toencode The string to encode
from The source character set
to The target character set
outlen A reference to a size_t variable to store the length of the new string in it
sq Boolean; if true, single quotes will be encoded to '
Returns:
NULL on failure, the new string on success

Definition at line 259 of file charconvert.c.

int is_valid_utf8_string const u_char *  str,
size_t  len
 

This function checks if the given string is a valid UTF-8 string

Parameters:
str The string to check
len The length of the string
Returns:
Returns 0 if string is valid and -1 if it is not

Definition at line 79 of file charconvert.c.

size_t print_htmlentities_encoded const u_char *  string,
int  sq,
FILE *  handle
 

This function does the same as htmlentities(), but it writes the encoded string to a file handle

Parameters:
string The string to encode and write
sq Switch which defines if ' shall be converted, too
handle The file handle to write in
Returns:
The number of characters written

Definition at line 209 of file charconvert.c.

int utf8_to_unicode const u_char *  s,
size_t  n,
u_int32_t *  num
 

This function converts a utf8 u_char string sequence to the unicode number.

Parameters:
s The sequence string
n The length of the sequence string (used to check if sequence can be legal)
num Reference to a u_int32_t. The unicode number will be stored in it
Returns:
EILSEQ on failure, length of byte sequence on success

Definition at line 32 of file charconvert.c.


Generated on Sun Apr 25 16:37:39 2004 for Classic Forum by doxygen 1.3.5