summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parse/language.c30
-rw-r--r--src/stylesheet.c26
-rw-r--r--src/stylesheet.h5
3 files changed, 58 insertions, 3 deletions
diff --git a/src/parse/language.c b/src/parse/language.c
index 78b2045..c583c51 100644
--- a/src/parse/language.c
+++ b/src/parse/language.c
@@ -359,18 +359,44 @@ css_error handleStartAtRule(css_language *c, const parserutils_vector *vector)
if (atkeyword->ilower == c->strings[CHARSET]) {
if (c->state == BEFORE_CHARSET) {
+ const css_token *charset;
+ css_rule *rule;
+ css_error error;
+
/* any0 = STRING */
if (ctx == 0)
return CSS_INVALID;
- token = parserutils_vector_iterate(vector, &ctx);
- if (token == NULL || token->type != CSS_TOKEN_STRING)
+ charset = parserutils_vector_iterate(vector, &ctx);
+ if (charset == NULL ||
+ charset->type != CSS_TOKEN_STRING)
return CSS_INVALID;
token = parserutils_vector_iterate(vector, &ctx);
if (token != NULL)
return CSS_INVALID;
+ error = css_stylesheet_rule_create(c->sheet,
+ CSS_RULE_CHARSET, &rule);
+ if (error != CSS_OK)
+ return error;
+
+ error = css_stylesheet_rule_set_charset(c->sheet, rule,
+ charset->idata);
+ if (error != CSS_OK) {
+ css_stylesheet_rule_destroy(c->sheet, rule);
+ return error;
+ }
+
+ error = css_stylesheet_add_rule(c->sheet, rule);
+ if (error != CSS_OK) {
+ css_stylesheet_rule_destroy(c->sheet, rule);
+ return error;
+ }
+
+ /* Rule is now owned by the sheet,
+ * so no need to destroy it */
+
c->state = BEFORE_RULES;
} else {
return CSS_INVALID;
diff --git a/src/stylesheet.c b/src/stylesheet.c
index 72c5f02..ce971bc 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -674,6 +674,32 @@ css_error css_stylesheet_rule_append_style(css_stylesheet *sheet,
}
/**
+ * Set the charset of a CSS rule
+ *
+ * \param sheet The stylesheet context
+ * \param rule The rule to add to (must be of type CSS_RULE_CHARSET)
+ * \param charset The charset
+ * \return CSS_OK on success, appropriate error otherwise
+ */
+css_error css_stylesheet_rule_set_charset(css_stylesheet *sheet,
+ css_rule *rule, const parserutils_hash_entry *charset)
+{
+ css_rule_charset *r = (css_rule_charset *) rule;
+
+ if (sheet == NULL || rule == NULL || charset == NULL)
+ return CSS_BADPARM;
+
+ /* Ensure rule is a CSS_RULE_CHARSET */
+ if (rule->type != CSS_RULE_CHARSET)
+ return CSS_INVALID;
+
+ /* Set rule's encoding field */
+ r->encoding = charset;
+
+ return CSS_OK;
+}
+
+/**
* Add a rule to a stylesheet
*
* \param sheet The stylesheet to add to
diff --git a/src/stylesheet.h b/src/stylesheet.h
index f32bbe3..ff32d97 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -133,7 +133,7 @@ typedef struct css_rule_import {
typedef struct css_rule_charset {
css_rule base;
- char *encoding; /** \todo use MIB enum? */
+ const parserutils_hash_entry *encoding; /** \todo use MIB enum? */
} css_rule_charset;
struct css_stylesheet {
@@ -206,6 +206,9 @@ css_error css_stylesheet_rule_add_selector(css_stylesheet *sheet,
css_error css_stylesheet_rule_append_style(css_stylesheet *sheet,
css_rule *rule, css_style *style);
+css_error css_stylesheet_rule_set_charset(css_stylesheet *sheet,
+ css_rule *rule, const parserutils_hash_entry *charset);
+
/** \todo registering other rule-type data with css_rules */
css_error css_stylesheet_add_rule(css_stylesheet *sheet, css_rule *rule);