cr-utils.h File Reference

The Croco library basic types definitions And global definitions. More...

#include <stdio.h>
#include <glib.h>
#include "libcroco-config.h"

Go to the source code of this file.

Defines

#define CROCO_LOG_DOMAIN   "LIBCROCO"
#define cr_utils_trace(a_log_level, a_msg)
#define cr_utils_trace_info(a_msg)   cr_utils_trace (G_LOG_LEVEL_INFO, a_msg)
 Traces an info message.
#define cr_utils_trace_debug(a_msg)   cr_utils_trace (G_LOG_LEVEL_DEBUG, a_msg) ;
 Trace a debug message.

Enumerations

enum  CRStatus {
  CR_OK, CR_BAD_PARAM_ERROR, CR_INSTANCIATION_FAILED_ERROR, CR_UNKNOWN_TYPE_ERROR,
  CR_UNKNOWN_PROP_ERROR, CR_UNKNOWN_PROP_VAL_ERROR, CR_UNEXPECTED_POSITION_SCHEME, CR_START_OF_INPUT_ERROR,
  CR_END_OF_INPUT_ERROR, CR_OUTPUT_TOO_SHORT_ERROR, CR_INPUT_TOO_SHORT_ERROR, CR_OUT_OF_BOUNDS_ERROR,
  CR_EMPTY_PARSER_INPUT_ERROR, CR_ENCODING_ERROR, CR_ENCODING_NOT_FOUND_ERROR, CR_PARSING_ERROR,
  CR_SYNTAX_ERROR, CR_NO_ROOT_NODE_ERROR, CR_NO_TOKEN, CR_OUT_OF_MEMORY_ERROR,
  CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR, CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR, CR_ERROR, CR_FILE_NOT_FOUND_ERROR,
  CR_VALUE_NOT_FOUND_ERROR
}
 The status type returned by the methods of the croco library. More...
enum  CRSeekPos { CR_SEEK_CUR, CR_SEEK_BEGIN, CR_SEEK_END }
 Values used by cr_input_seek_position() ;. More...
enum  CREncoding {
  CR_UCS_4 = 1, CR_UCS_1, CR_ISO_8859_1, CR_ASCII,
  CR_UTF_8, CR_UTF_16, CR_AUTO
}
 Encoding values. More...

Functions

enum CRStatus cr_utils_read_char_from_utf8_buf (const guchar *a_in, gulong a_in_len, guint32 *a_out, gulong *a_consumed)
 Reads a character from an utf8 buffer.
enum CRStatus cr_utils_ucs1_to_utf8 (const guchar *a_in, gulong *a_in_len, guchar *a_out, gulong *a_out_len)
 Converts an ucs1 buffer into an utf8 buffer.
enum CRStatus cr_utils_utf8_to_ucs1 (const guchar *a_in, gulong *a_in_len, guchar *a_out, gulong *a_out_len)
 Converts an utf8 buffer into an ucs1 buffer.
enum CRStatus cr_utils_ucs4_to_utf8 (const guint32 *a_in, gulong *a_in_len, guchar *a_out, gulong *a_out_len)
 Converts an ucs4 buffer into an utf8 buffer.
enum CRStatus cr_utils_utf8_str_len_as_ucs4 (const guchar *a_in_start, const guchar *a_in_end, gulong *a_len)
 Given an utf8 string buffer, calculates the length of this string if it was encoded in ucs4.
enum CRStatus cr_utils_ucs1_str_len_as_utf8 (const guchar *a_in_start, const guchar *a_in_end, gulong *a_len)
 Given an ucsA string, this function returns the size (in bytes) this string would have occupied if it was encoded in utf-8.
enum CRStatus cr_utils_utf8_str_len_as_ucs1 (const guchar *a_in_start, const guchar *a_in_end, gulong *a_len)
enum CRStatus cr_utils_ucs4_str_len_as_utf8 (const guint32 *a_in_start, const guint32 *a_in_end, gulong *a_len)
 Given an ucs4 string, this function returns the size (in bytes) this string would have occupied if it was encoded in utf-8.
enum CRStatus cr_utils_ucs1_str_to_utf8 (const guchar *a_in_start, gulong *a_in_len, guchar **a_out, gulong *a_len)
 Converts an ucs1 string into an utf8 string.
enum CRStatus cr_utils_utf8_str_to_ucs1 (const guchar *a_in_start, gulong *a_in_len, guchar **a_out, gulong *a_out_len)
 Converts an utf8 buffer into an ucs1 buffer.
enum CRStatus cr_utils_utf8_to_ucs4 (const guchar *a_in, gulong *a_in_len, guint32 *a_out, gulong *a_out_len)
 Converts an utf8 buffer into an ucs4 buffer.
enum CRStatus cr_utils_ucs4_str_to_utf8 (const guint32 *a_in, gulong *a_in_len, guchar **a_out, gulong *a_out_len)
 Converts an ucs4 string into an utf8 string.
enum CRStatus cr_utils_utf8_str_to_ucs4 (const guchar *a_in, gulong *a_in_len, guint32 **a_out, gulong *a_out_len)
 Converts an utf8 string into an ucs4 string.
gboolean cr_utils_is_newline (guint32 a_char)
 Returns true if the character is a newline as defined in the css spec in the chap 4.1.1.
gboolean cr_utils_is_white_space (guint32 a_char)
 Returns TRUE if a_char is a white space as defined in the css spec in chap 4.1.1.
gboolean cr_utils_is_nonascii (guint32 a_char)
 Returns true if the character is a nonascii character (as defined in the css spec chap 4.1.1):.
gboolean cr_utils_is_hexa_char (guint32 a_char)
 returns TRUE if the char is part of an hexa num char: i.e hexa_char ::= [0-9A-F]
void cr_utils_dump_n_chars (guchar a_char, FILE *a_fp, glong a_nb)
 Dumps a character a_nb times on a file.
void cr_utils_dump_n_chars2 (guchar a_char, GString *a_string, glong a_nb)
gdouble cr_utils_n_to_0_dot_n (glong a_n, glong decimal_places)
GList * cr_utils_dup_glist_of_string (GList *a_list)
 Duplicates a list of GString instances.
GList * cr_utils_dup_glist_of_cr_string (GList *a_list_of_strings)
 Duplicate a GList where the GList::data is a CRString.


Detailed Description

The Croco library basic types definitions And global definitions.

Definition in file cr-utils.h.


Define Documentation

#define cr_utils_trace a_log_level,
a_msg   ) 
 

Value:

g_log (CROCO_LOG_DOMAIN, \
       G_LOG_LEVEL_CRITICAL, \
       "file %s: line %d: %s\n", \
       __FILE__, \
       __LINE__, \
       a_msg)

Definition at line 111 of file cr-utils.h.

#define cr_utils_trace_debug a_msg   )     cr_utils_trace (G_LOG_LEVEL_DEBUG, a_msg) ;
 

Trace a debug message.

The file, line and enclosing function of the message will be automatically added to the message.

Parameters:
a_msg the msg to trace.

Definition at line 137 of file cr-utils.h.

Referenced by cr_additional_sel_new(), and cr_input_new_from_uri().

#define cr_utils_trace_info a_msg   )     cr_utils_trace (G_LOG_LEVEL_INFO, a_msg)
 

Traces an info message.

The file, line and enclosing function of the message will be automatically added to the message.

Parameters:
a_msg the msg to trace.

Definition at line 127 of file cr-utils.h.

Referenced by cr_cascade_new(), cr_declaration_new(), cr_doc_handler_new(), cr_font_family_new(), cr_font_size_adjust_new(), cr_font_size_get_larger_predefined_font_size(), cr_font_size_get_smaller_predefined_font_size(), cr_font_size_new(), cr_font_weight_get_bolder(), cr_num_new(), cr_om_parser_new(), cr_om_parser_simply_parse_buf(), cr_om_parser_simply_parse_file(), cr_om_parser_simply_parse_paths_to_cascade(), cr_parser_new_from_file(), cr_parsing_location_new(), cr_rgb_new(), cr_rgb_set_from_term(), cr_sel_eng_get_matched_properties_from_cascade(), cr_sel_eng_get_matched_rulesets(), cr_sel_eng_new(), cr_selector_new(), cr_simple_sel_new(), cr_statement_at_charset_rule_parse_from_buf(), cr_statement_at_import_rule_parse_from_buf(), cr_statement_at_media_rule_parse_from_buf(), cr_statement_at_page_rule_parse_from_buf(), cr_statement_list_to_string(), cr_statement_new_at_charset_rule(), cr_statement_new_at_font_face_rule(), cr_statement_new_at_import_rule(), cr_statement_new_at_media_rule(), cr_statement_new_at_page_rule(), cr_statement_new_ruleset(), cr_statement_to_string(), cr_string_dup(), cr_string_new(), cr_string_new_from_gstring(), cr_string_new_from_string(), cr_style_dup(), cr_style_new(), cr_style_set_props_to_default_values(), cr_style_set_props_to_initial_values(), cr_stylesheet_new(), cr_term_new(), cr_tknzr_new(), and cr_token_new().

#define CROCO_LOG_DOMAIN   "LIBCROCO"
 

Definition at line 98 of file cr-utils.h.


Enumeration Type Documentation

enum CREncoding
 

Encoding values.

Enumerator:
CR_UCS_4 
CR_UCS_1 
CR_ISO_8859_1 
CR_ASCII 
CR_UTF_8 
CR_UTF_16 
CR_AUTO 

Definition at line 84 of file cr-utils.h.

enum CRSeekPos
 

Values used by cr_input_seek_position() ;.

Enumerator:
CR_SEEK_CUR 
CR_SEEK_BEGIN 
CR_SEEK_END 

Definition at line 75 of file cr-utils.h.

enum CRStatus
 

The status type returned by the methods of the croco library.

Enumerator:
CR_OK 
CR_BAD_PARAM_ERROR 
CR_INSTANCIATION_FAILED_ERROR 
CR_UNKNOWN_TYPE_ERROR 
CR_UNKNOWN_PROP_ERROR 
CR_UNKNOWN_PROP_VAL_ERROR 
CR_UNEXPECTED_POSITION_SCHEME 
CR_START_OF_INPUT_ERROR 
CR_END_OF_INPUT_ERROR 
CR_OUTPUT_TOO_SHORT_ERROR 
CR_INPUT_TOO_SHORT_ERROR 
CR_OUT_OF_BOUNDS_ERROR 
CR_EMPTY_PARSER_INPUT_ERROR 
CR_ENCODING_ERROR 
CR_ENCODING_NOT_FOUND_ERROR 
CR_PARSING_ERROR 
CR_SYNTAX_ERROR 
CR_NO_ROOT_NODE_ERROR 
CR_NO_TOKEN 
CR_OUT_OF_MEMORY_ERROR 
CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR 
CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR 
CR_ERROR 
CR_FILE_NOT_FOUND_ERROR 
CR_VALUE_NOT_FOUND_ERROR 

Definition at line 43 of file cr-utils.h.


Function Documentation

void cr_utils_dump_n_chars guchar  a_char,
FILE *  a_fp,
glong  a_nb
 

Dumps a character a_nb times on a file.

Parameters:
a_char the char to dump
a_fp the destination file pointer
a_nb the number of times a_char is to be dumped.

Definition at line 1274 of file cr-utils.c.

void cr_utils_dump_n_chars2 guchar  a_char,
GString *  a_string,
glong  a_nb
 

Definition at line 1284 of file cr-utils.c.

Referenced by cr_declaration_to_string(), cr_style_border_style_to_string(), cr_style_display_type_to_string(), cr_style_float_type_to_string(), cr_style_num_prop_val_to_string(), cr_style_position_type_to_string(), cr_style_rgb_prop_val_to_string(), cr_style_to_string(), and cr_style_white_space_type_to_string().

GList* cr_utils_dup_glist_of_cr_string GList *  a_list_of_strings  ) 
 

Duplicate a GList where the GList::data is a CRString.

Parameters:
a_list_of_strings the list to duplicate
Returns:
the duplicated list, or NULL if something bad happened.

Definition at line 1341 of file cr-utils.c.

References cr_string_dup().

GList* cr_utils_dup_glist_of_string GList *  a_list_of_strings  ) 
 

Duplicates a list of GString instances.

Returns:
the duplicated list of GString instances or NULL if something bad happened.
Parameters:
a_list_of_strings the list of strings to be duplicated.

Definition at line 1315 of file cr-utils.c.

gboolean cr_utils_is_hexa_char guint32  a_char  ) 
 

returns TRUE if the char is part of an hexa num char: i.e hexa_char ::= [0-9A-F]

Definition at line 1238 of file cr-utils.c.

gboolean cr_utils_is_newline guint32  a_char  ) 
 

Returns true if the character is a newline as defined in the css spec in the chap 4.1.1.

nl ::=
|
||

Parameters:
a_char the character to test.
Returns:
TRUE if the character is a newline, FALSE otherwise.

Definition at line 1220 of file cr-utils.c.

gboolean cr_utils_is_nonascii guint32  a_char  ) 
 

Returns true if the character is a nonascii character (as defined in the css spec chap 4.1.1):.

nonascii ::= [^-]

Parameters:
a_char the character to test.
Returns:
TRUE if the character is a nonascii char, FALSE otherwise.

Definition at line 1258 of file cr-utils.c.

Referenced by cr_tknzr_get_next_token().

gboolean cr_utils_is_white_space guint32  a_char  ) 
 

Returns TRUE if a_char is a white space as defined in the css spec in chap 4.1.1.

white-space ::= ' '| ||
|

Parameters:
a_char the character to test. return TRUE if is a white space, false otherwise.

Definition at line 1195 of file cr-utils.c.

Referenced by cr_input_consume_white_spaces().

gdouble cr_utils_n_to_0_dot_n glong  a_n,
glong  decimal_places
 

Definition at line 1296 of file cr-utils.c.

enum CRStatus cr_utils_read_char_from_utf8_buf const guchar *  a_in,
gulong  a_in_len,
guint32 *  a_out,
gulong *  a_consumed
 

Reads a character from an utf8 buffer.

Actually decode the next character code (unicode character code) and returns it.

Parameters:
a_in the starting address of the utf8 buffer.
a_in_len the length of the utf8 buffer.
a_out output parameter. The resulting read char.
a_consumed the number of the bytes consumed to decode the returned character code.
Returns:
CR_OK upon successfull completion, an error code otherwise.

Definition at line 428 of file cr-utils.c.

References CR_BAD_PARAM_ERROR, CR_END_OF_INPUT_ERROR, and CR_OK.

Referenced by cr_input_peek_char(), and cr_input_read_char().

enum CRStatus cr_utils_ucs1_str_len_as_utf8 const guchar *  a_in_start,
const guchar *  a_in_end,
gulong *  a_len
 

Given an ucsA string, this function returns the size (in bytes) this string would have occupied if it was encoded in utf-8.

Parameters:
a_in_start a pointer to the beginning of the input buffer.
a_in_end a pointer to the end of the input buffer.
a_len out parameter. The computed length.
Returns:
CR_OK upon successfull completion, an error code otherwise.

Definition at line 230 of file cr-utils.c.

References CR_BAD_PARAM_ERROR.

Referenced by cr_utils_ucs1_str_to_utf8().

enum CRStatus cr_utils_ucs1_str_to_utf8 const guchar *  a_in,
gulong *  a_in_len,
guchar **  a_out,
gulong *  a_out_len
 

Converts an ucs1 string into an utf8 string.

Parameters:
a_in_start the beginning of the input string to convert.
a_in_end the end of the input string to convert.
a_out out parameter. The converted string.
a_out out parameter. The length of the converted string.
Returns:
CR_OK upon successfull completion, an error code otherwise.

Definition at line 950 of file cr-utils.c.

References CR_BAD_PARAM_ERROR, CR_OK, cr_utils_ucs1_str_len_as_utf8(), and cr_utils_ucs1_to_utf8().

enum CRStatus cr_utils_ucs1_to_utf8 const guchar *  a_in,
gulong *  a_in_len,
guchar *  a_out,
gulong *  a_out_len
 

Converts an ucs1 buffer into an utf8 buffer.

The caller must know the size of the resulting buffer and allocate it prior to calling this function.

Parameters:
a_in the input ucs1 buffer.
a_in_len in/out parameter. The length of the input buffer. After return, points to the number of bytes actually consumed even in case of encoding error.
a_out out parameter. The output utf8 converted buffer.
a_out_len in/out parameter. The size of the output buffer. If the output buffer size is shorter than the actual needed size, this function just convert what it can.
Returns:
CR_OK upon successfull completion, an error code otherwise.

Definition at line 889 of file cr-utils.c.

References CR_BAD_PARAM_ERROR, and CR_OK.

Referenced by cr_utils_ucs1_str_to_utf8().

enum CRStatus cr_utils_ucs4_str_len_as_utf8 const guint32 *  a_in_start,
const guint32 *  a_in_end,
gulong *  a_len
 

Given an ucs4 string, this function returns the size (in bytes) this string would have occupied if it was encoded in utf-8.

Parameters:
a_in_start a pointer to the beginning of the input buffer.
a_in_end a pointer to the end of the input buffer.
a_len out parameter. The computed length.
Returns:
CR_OK upon successfull completion, an error code otherwise.

Definition at line 187 of file cr-utils.c.

References CR_BAD_PARAM_ERROR.

Referenced by cr_utils_ucs4_str_to_utf8().

enum CRStatus cr_utils_ucs4_str_to_utf8 const guint32 *  a_in,
gulong *  a_in_len,
guchar **  a_out,
gulong *  a_out_len
 

Converts an ucs4 string into an utf8 string.

Parameters:
a_in the input string to convert.
a_in_len in/out parameter. The length of the input string. After return, points to the actual number of characters consumed. This can be usefull to debug the input string in case of encoding error.
a_out out parameter. Points to the output string. It is allocated by this function and must be freed by the caller.
a_out_len out parameter. The length (in bytes) of the output string.
Returns:
CR_OK upon successfull completion, an error code otherwise.

Definition at line 848 of file cr-utils.c.

References CR_BAD_PARAM_ERROR, CR_OK, cr_utils_ucs4_str_len_as_utf8(), and cr_utils_ucs4_to_utf8().

enum CRStatus cr_utils_ucs4_to_utf8 const guint32 *  a_in,
gulong *  a_in_len,
guchar *  a_out,
gulong *  a_out_len
 

Converts an ucs4 buffer into an utf8 buffer.

Parameters:
a_in the input ucs4 buffer to convert.
a_in_len in/out parameter. The size of the input buffer to convert. After return, this parameter contains the actual number of characters consumed.
a_out the output converted utf8 buffer. Must be allocated by the caller.
a_out_len in/out parameter. The size of the output buffer. If this size is actually smaller than the real needed size, the function just converts what it can and returns a success status. After return, this param points to the actual number of bytes in the buffer.
Returns:
CR_OK upon successfull completion, an error code otherwise.

Definition at line 751 of file cr-utils.c.

References CR_BAD_PARAM_ERROR, and CR_OK.

Referenced by cr_utils_ucs4_str_to_utf8().

enum CRStatus cr_utils_utf8_str_len_as_ucs1 const guchar *  a_in_start,
const guchar *  a_in_end,
gulong *  a_len
 

Definition at line 572 of file cr-utils.c.

References CR_BAD_PARAM_ERROR.

enum CRStatus cr_utils_utf8_str_len_as_ucs4 const guchar *  a_in_start,
const guchar *  a_in_end,
gulong *  a_len
 

Given an utf8 string buffer, calculates the length of this string if it was encoded in ucs4.

Parameters:
a_in_start a pointer to the begining of the input utf8 string.
a_in_end a pointre to the end of the input utf8 string (points to the last byte of the buffer)
a_len out parameter the calculated length.
Returns:
CR_OK upon succesfull completion, an error code otherwise.

Definition at line 69 of file cr-utils.c.

References CR_BAD_PARAM_ERROR.

Referenced by cr_utils_utf8_str_to_ucs1(), and cr_utils_utf8_str_to_ucs4().

enum CRStatus cr_utils_utf8_str_to_ucs1 const guchar *  a_in,
gulong *  a_in_len,
guchar **  a_out,
gulong *  a_out_len
 

Converts an utf8 buffer into an ucs1 buffer.

Parameters:
a_in_start the start of the input buffer.
a_in_end the end of the input buffer.
a_out out parameter. The resulting converted ucs4 buffer. Must be freed by the caller.
a_out_len out parameter. The length of the converted buffer.
Returns:
CR_OK upon successfull completion, an error code otherwise. Note that out parameters are valid if and only if this function returns CR_OK.

Definition at line 1155 of file cr-utils.c.

References CR_BAD_PARAM_ERROR, CR_OK, cr_utils_utf8_str_len_as_ucs4(), and cr_utils_utf8_to_ucs1().

enum CRStatus cr_utils_utf8_str_to_ucs4 const guchar *  a_in,
gulong *  a_in_len,
guint32 **  a_out,
gulong *  a_out_len
 

Converts an utf8 string into an ucs4 string.

Parameters:
a_in the input string to convert.
a_in_len in/out parameter. The length of the input string. After return, points to the actual number of bytes consumed. This can be usefull to debug the input stream in case of encoding error.
a_out out parameter. Points to the output string. It is allocated by this function and must be freed by the caller.
a_out_len out parameter. The length of the output string.
Returns:
CR_OK upon successfull completion, an error code otherwise.

Definition at line 713 of file cr-utils.c.

References CR_BAD_PARAM_ERROR, CR_OK, cr_utils_utf8_str_len_as_ucs4(), and cr_utils_utf8_to_ucs4().

enum CRStatus cr_utils_utf8_to_ucs1 const guchar *  a_in,
gulong *  a_in_len,
guchar *  a_out,
gulong *  a_out_len
 

Converts an utf8 buffer into an ucs1 buffer.

The caller must know the size of the resulting converted buffer, and allocated it prior to calling this function.

Parameters:
a_in the input utf8 buffer to convert.
a_in_len in/out parameter. The size of the input utf8 buffer. After return, points to the number of bytes consumed by the function even in case of encoding error.
a_out out parameter. Points to the resulting buffer. Must be allocated by the caller. If the size of a_out is shorter than its required size, this function converts what it can and return a successfull status.
a_out_len in/out parameter. The size of the output buffer. After return, points to the number of bytes consumed even in case of encoding error.
Returns:
CR_OK upon successfull completion, an error code otherwise.

Definition at line 1007 of file cr-utils.c.

References CR_BAD_PARAM_ERROR, and CR_OK.

Referenced by cr_utils_utf8_str_to_ucs1().

enum CRStatus cr_utils_utf8_to_ucs4 const guchar *  a_in,
gulong *  a_in_len,
guint32 *  a_out,
gulong *  a_out_len
 

Converts an utf8 buffer into an ucs4 buffer.

Parameters:
a_in the input utf8 buffer to convert.
a_in_len in/out parameter. The size of the input buffer to convert. After return, this parameter contains the actual number of bytes consumed.
a_out the output converted ucs4 buffer. Must be allocated by the caller.
a_out_len in/out parameter. The size of the output buffer. If this size is actually smaller than the real needed size, the function just converts what it can and returns a success status. After return, this param points to the actual number of characters decoded.
Returns:
CR_OK upon successfull completion, an error code otherwise.

Definition at line 270 of file cr-utils.c.

References CR_BAD_PARAM_ERROR, and CR_OK.

Referenced by cr_utils_utf8_str_to_ucs4().


Generated on Wed Mar 15 18:23:58 2006 for Libcroco by  doxygen 1.4.6