summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@seketeli.org>2003-06-18 14:36:44 +0000
committerDodji Seketeli <dodji@src.gnome.org>2003-06-18 14:36:44 +0000
commit28260b0a57917142eaeedd918d7185a80d66ea6b (patch)
tree9f6f6bf5814cb72b71186b324ef2f3cbccf11091
parent0747aed7f2d145eb7d26f99599bdcdc9498ccc6a (diff)
downloadlibcroco-28260b0a57917142eaeedd918d7185a80d66ea6b.tar.gz
updated the test routine to test
2003-06-18 Dodji Seketeli <dodji@seketeli.org> * tests/test4-main.c: updated the test routine to test cr_statement_at_charset_rule_parse_from_buf(). * src/parser/cr-statement.[ch]: added a new cr_statement_at_charset_rule_parse_from_buf() method to to create an "@charset" statement from a buffer text content. * src/parser/cr-parser.c:Fixeds a small possibility of memleak in cr_parser_parse_charse() Dodji.
-rw-r--r--ChangeLog14
-rw-r--r--src/parser/cr-parser.c10
-rw-r--r--src/parser/cr-statement.c57
-rw-r--r--src/parser/cr-statement.h3
-rw-r--r--tests/test4-main.c28
5 files changed, 108 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index d715867..43800ca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,22 @@
-2003-06-18 dodji <dodji@seketeli.org>
+2003-06-18 Dodji Seketeli <dodji@seketeli.org>
+ * tests/test4-main.c: updated the test routine to test
+ cr_statement_at_charset_rule_parse_from_buf().
+
+ * src/parser/cr-statement.[ch]: added a new
+ cr_statement_at_charset_rule_parse_from_buf() method to
+ to create an "@charset" statement from a buffer text content.
+
+ * src/parser/cr-parser.c:Fixeds a small possibility of memleak
+ in cr_parser_parse_charse()
+
* tests/test4-main.c: fixed a small typo in the "@page" rule
embedded in gv_at_page_buf.
* src/parser/cr-parser.c: fixed a small bug in the
cr_parser_parse_page () function.
-2003-06-17 dodji <dodji@seketeli.org>
+2003-06-17 Dodji Seketeli <dodji@seketeli.org>
* tests/test4-main.c: added test_cr_statement_at_page_rule_parse ()
to test the new cr_statement_at_page_rule_parse_from_buf() function.
diff --git a/src/parser/cr-parser.c b/src/parser/cr-parser.c
index 579ae4f..402fcd0 100644
--- a/src/parser/cr-parser.c
+++ b/src/parser/cr-parser.c
@@ -4781,7 +4781,8 @@ cr_parser_parse_page (CRParser *a_this)
*
*@param a_this the "this pointer" of the current instance of #CRParser.
*@param a_value out parameter. The actual parsed value of the charset
- *declararation.
+ *declararation. Note that for safety check reasons, *a_value must be
+ *set to NULL.
*@return CR_OK upon successfull completion, an error code otherwise.
*/
enum CRStatus
@@ -4833,6 +4834,7 @@ cr_parser_parse_charset (CRParser *a_this, GString **a_value)
if (charset_str)
{
*a_value = charset_str ;
+ charset_str = NULL ;
}
PRIVATE (a_this)->state = CHARSET_PARSED_STATE ;
@@ -4852,6 +4854,12 @@ cr_parser_parse_charset (CRParser *a_this, GString **a_value)
*a_value = NULL ;
}
+ if (charset_str)
+ {
+ g_string_free (charset_str, TRUE) ;
+ charset_str = NULL ;
+ }
+
cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr,
&init_pos) ;
diff --git a/src/parser/cr-statement.c b/src/parser/cr-statement.c
index d66bb8e..11ee840 100644
--- a/src/parser/cr-statement.c
+++ b/src/parser/cr-statement.c
@@ -1134,6 +1134,8 @@ cr_statement_at_page_rule_parse_from_buf (const guchar *a_buf,
*Creates a new instance of #CRStatement of type
*#CRAtCharsetRule.
*@param a_charset the string representing the charset.
+ *Note that the newly built instance of #CRStatement becomes
+ *the owner of a_charset. The caller must not free a_charset !!!.
*@return the newly built instance of #CRStatement or NULL
*if an error arises.
*/
@@ -1143,7 +1145,7 @@ cr_statement_new_at_charset_rule (CRStyleSheet *a_sheet,
{
CRStatement * result = NULL ;
- g_return_val_if_fail (a_sheet, NULL) ;
+ g_return_val_if_fail (a_charset, NULL) ;
result = g_try_malloc (sizeof (CRStatement)) ;
@@ -1173,6 +1175,59 @@ cr_statement_new_at_charset_rule (CRStyleSheet *a_sheet,
}
/**
+ *Parses a buffer that contains an '@charset' rule and
+ *creates an instance of #CRStatement of type AT_CHARSET_RULE_STMT.
+ *@param a_buf the buffer to parse.
+ *@param the character encoding of the buffer.
+ *@return the newly built instance of #CRStatement.
+ */
+CRStatement *
+cr_statement_at_charset_rule_parse_from_buf (const guchar *a_buf,
+ enum CREncoding a_encoding)
+{
+ enum CRStatus status = CR_OK ;
+ CRParser *parser = NULL ;
+ CRStatement *result = NULL ;
+ GString *charset = NULL ;
+
+ g_return_val_if_fail (a_buf, NULL) ;
+
+ parser = cr_parser_new_from_buf (a_buf, strlen (a_buf),
+ a_encoding, FALSE) ;
+ if (!parser)
+ {
+ cr_utils_trace_info ("Instanciation of the parser failed.") ;
+ goto cleanup ;
+ }
+
+ /*Now, invoke the parser to parse the "@charset production"*/
+ cr_parser_try_to_skip_spaces_and_comments (parser) ;
+ if (status != CR_OK)
+ goto cleanup ;
+ status = cr_parser_parse_charset (parser, &charset) ;
+ if (status != CR_OK || !charset)
+ goto cleanup ;
+
+ result = cr_statement_new_at_charset_rule (NULL, charset) ;
+ if (result)
+ charset = NULL ;
+
+ cleanup:
+
+ if (parser)
+ {
+ cr_parser_destroy (parser) ;
+ parser = NULL ;
+ }
+ if (charset)
+ {
+ g_string_free (charset, TRUE) ;
+ }
+
+ return result ;
+}
+
+/**
*Creates an instance of #CRStatement of type #CRAtFontFaceRule.
*@param a_font_decls a list of instances of #CRDeclaration. Each declaration
*is actually a font declaration.
diff --git a/src/parser/cr-statement.h b/src/parser/cr-statement.h
index 23c8895..d1d7686 100644
--- a/src/parser/cr-statement.h
+++ b/src/parser/cr-statement.h
@@ -256,6 +256,9 @@ CRStatement *
cr_statement_new_at_charset_rule (CRStyleSheet *a_sheet,
GString *a_charset) ;
CRStatement *
+cr_statement_at_charset_rule_parse_from_buf (const guchar *a_buf,
+ enum CREncoding a_encoding);
+CRStatement *
cr_statement_at_media_rule_parse_from_buf (const guchar *a_buf,
enum CREncoding a_enc) ;
diff --git a/tests/test4-main.c b/tests/test4-main.c
index 4c77870..1006c23 100644
--- a/tests/test4-main.c
+++ b/tests/test4-main.c
@@ -52,6 +52,10 @@ const guchar *gv_at_page_buf =
"@page { size :8.5in 11in; margin: 2cm }"
;
+const guchar *gv_at_charset_buf =
+"@charset \"ISO-8859-1\" ; "
+;
+
static void
display_help (char *prg_name) ;
@@ -211,6 +215,23 @@ test_cr_statement_at_page_rule_parse (void)
return CR_OK ;
}
+static enum CRStatus
+test_cr_statement_at_charset_rule_parse (void)
+{
+ CRStatement *stmt = NULL ;
+
+ stmt = cr_statement_at_charset_rule_parse_from_buf (gv_at_charset_buf,
+ CR_UTF_8) ;
+ g_return_val_if_fail (stmt, CR_ERROR) ;
+ if (stmt)
+ {
+ cr_statement_destroy (stmt) ;
+ stmt = NULL ;
+ }
+
+ return CR_OK ;
+}
+
/**
*The entry point of the testing routine.
*/
@@ -248,6 +269,13 @@ main (int argc, char ** argv)
return 0 ;
}
+ test_cr_statement_at_charset_rule_parse () ;
+ if (status != CR_OK)
+ {
+ g_print ("\nKO\n") ;
+ return 0 ;
+ }
+
cr_test_utils_parse_cmd_line (argc, argv, &options) ;
if (options.display_help == TRUE)