Libcroco
cr-utils.h
Go to the documentation of this file.
1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2 
3 /*
4  * This file is part of The Croco Library
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of version 2.1 of the GNU Lesser General Public
8  * License as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  *
20  * Author: Dodji Seketeli
21  * Look at file COPYRIGHTS for copyright information
22  */
23 
24 #ifndef __CR_DEFS_H__
25 #define __CR_DEFS_H__
26 
27 #include <stdio.h>
28 #include <glib.h>
29 #include "libcroco-config.h"
30 
31 G_BEGIN_DECLS
32 
33 /**
34  *@file
35  *The Croco library basic types definitions
36  *And global definitions.
37  */
38 
39 /**
40  *The status type returned
41  *by the methods of the croco library.
42  */
43 enum CRStatus {
69 } ;
70 
71 /**
72  *Values used by
73  *cr_input_seek_position() ;
74  */
75 enum CRSeekPos {
79 } ;
80 
81 /**
82  *Encoding values.
83  */
85 {
86  CR_UCS_4 = 1/*Must be not NULL*/,
92  CR_AUTO/*should be the last one*/
93 } ;
94 
95 
96 
97 
98 #define CROCO_LOG_DOMAIN "LIBCROCO"
99 
100 #ifdef __GNUC__
101 #define cr_utils_trace(a_log_level, a_msg) \
102 g_log (CROCO_LOG_DOMAIN, \
103  G_LOG_LEVEL_CRITICAL, \
104  "file %s: line %d (%s): %s\n", \
105  __FILE__, \
106  __LINE__, \
107  __PRETTY_FUNCTION__, \
108  a_msg)
109 #else /*__GNUC__*/
110 
111 #define cr_utils_trace(a_log_level, a_msg) \
112 g_log (CROCO_LOG_DOMAIN, \
113  G_LOG_LEVEL_CRITICAL, \
114  "file %s: line %d: %s\n", \
115  __FILE__, \
116  __LINE__, \
117  a_msg)
118 #endif
119 
120 /**
121  *Traces an info message.
122  *The file, line and enclosing function
123  *of the message will be automatically
124  *added to the message.
125  *@param a_msg the msg to trace.
126  */
127 #define cr_utils_trace_info(a_msg) \
128 cr_utils_trace (G_LOG_LEVEL_INFO, a_msg)
129 
130 /**
131  *Trace a debug message.
132  *The file, line and enclosing function
133  *of the message will be automatically
134  *added to the message.
135  *@param a_msg the msg to trace.
136  */
137 #define cr_utils_trace_debug(a_msg) \
138 cr_utils_trace (G_LOG_LEVEL_DEBUG, a_msg) ;
139 
140 
141 /****************************
142  *Encoding transformations and
143  *encoding helpers
144  ****************************/
145 
146 enum CRStatus
147 cr_utils_read_char_from_utf8_buf (const guchar * a_in, gulong a_in_len,
148  guint32 *a_out, gulong *a_consumed) ;
149 
150 enum CRStatus
151 cr_utils_ucs1_to_utf8 (const guchar *a_in, gulong *a_in_len,
152  guchar *a_out, gulong *a_out_len) ;
153 
154 enum CRStatus
155 cr_utils_utf8_to_ucs1 (const guchar * a_in, gulong * a_in_len,
156  guchar *a_out, gulong *a_out_len) ;
157 
158 enum CRStatus
159 cr_utils_ucs4_to_utf8 (const guint32 *a_in, gulong *a_in_len,
160  guchar *a_out, gulong *a_out_len) ;
161 
162 enum CRStatus
163 cr_utils_utf8_str_len_as_ucs4 (const guchar *a_in_start,
164  const guchar *a_in_end,
165  gulong *a_len) ;
166 enum CRStatus
167 cr_utils_ucs1_str_len_as_utf8 (const guchar *a_in_start,
168  const guchar *a_in_end,
169  gulong *a_len) ;
170 enum CRStatus
171 cr_utils_utf8_str_len_as_ucs1 (const guchar *a_in_start,
172  const guchar *a_in_end,
173  gulong *a_len) ;
174 enum CRStatus
175 cr_utils_ucs4_str_len_as_utf8 (const guint32 *a_in_start,
176  const guint32 *a_in_end,
177  gulong *a_len) ;
178 
179 enum CRStatus
180 cr_utils_ucs1_str_to_utf8 (const guchar *a_in_start,
181  gulong *a_in_len,
182  guchar **a_out,
183  gulong *a_len) ;
184 
185 enum CRStatus
186 cr_utils_utf8_str_to_ucs1 (const guchar * a_in_start,
187  gulong * a_in_len,
188  guchar **a_out,
189  gulong *a_out_len) ;
190 
191 enum CRStatus
192 cr_utils_utf8_to_ucs4 (const guchar * a_in,
193  gulong * a_in_len,
194  guint32 *a_out, gulong *a_out_len) ;
195 
196 enum CRStatus
197 cr_utils_ucs4_str_to_utf8 (const guint32 *a_in,
198  gulong *a_in_len,
199  guchar **a_out, gulong *a_out_len) ;
200 
201 enum CRStatus
202 cr_utils_utf8_str_to_ucs4 (const guchar * a_in,
203  gulong *a_in_len,
204  guint32 **a_out,
205  gulong *a_out_len) ;
206 
207 
208 /*****************************************
209  *CSS basic types identification utilities
210  *****************************************/
211 
212 gboolean
213 cr_utils_is_newline (guint32 a_char) ;
214 
215 gboolean
216 cr_utils_is_white_space (guint32 a_char) ;
217 
218 gboolean
219 cr_utils_is_nonascii (guint32 a_char) ;
220 
221 gboolean
222 cr_utils_is_hexa_char (guint32 a_char) ;
223 
224 
225 /**********************************
226  *Miscellaneous utility functions
227  ***********************************/
228 
229 void
230 cr_utils_dump_n_chars (guchar a_char,
231  FILE *a_fp,
232  glong a_nb) ;
233 
234 void
235 cr_utils_dump_n_chars2 (guchar a_char,
236  GString *a_string,
237  glong a_nb) ;
238 GList *
239 cr_utils_dup_glist_of_string (GList const *a_list) ;
240 
241 GList *
242 cr_utils_dup_glist_of_cr_string (GList const * a_list_of_strings) ;
243 
244 G_END_DECLS
245 
246 #endif /*__CR_DEFS_H__*/
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.
Definition: cr-utils.c:710
void cr_utils_dump_n_chars2(guchar a_char, GString *a_string, glong a_nb)
Definition: cr-utils.c:1270
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.
Definition: cr-utils.c:270
CREncoding
Encoding values.
Definition: cr-utils.h:84
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.
Definition: cr-utils.c:428
CRStatus
The status type returned by the methods of the croco library.
Definition: cr-utils.h:43
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.
Definition: cr-utils.c:845
GList * cr_utils_dup_glist_of_string(GList const *a_list)
Duplicates a list of GString instances.
Definition: cr-utils.c:1288
Definition: cr-utils.h:44
CRSeekPos
Values used by cr_input_seek_position() ;.
Definition: cr-utils.h:75
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....
Definition: cr-utils.c:1206
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.
Definition: cr-utils.c:995
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....
Definition: cr-utils.c:1244
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.
Definition: cr-utils.c:1141
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.
Definition: cr-utils.c:941
GList * cr_utils_dup_glist_of_cr_string(GList const *a_list_of_strings)
Duplicate a GList where the GList::data is a CRString.
Definition: cr-utils.c:1314
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...
Definition: cr-utils.c:230
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.
Definition: cr-utils.c:1181
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.
Definition: cr-utils.c:886
void cr_utils_dump_n_chars(guchar a_char, FILE *a_fp, glong a_nb)
Dumps a character a_nb times on a file.
Definition: cr-utils.c:1260
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...
Definition: cr-utils.c:187
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.
Definition: cr-utils.c:748
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: cr-utils.c:1224
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.
Definition: cr-utils.c:69
enum CRStatus cr_utils_utf8_str_len_as_ucs1(const guchar *a_in_start, const guchar *a_in_end, gulong *a_len)
Definition: cr-utils.c:569