summaryrefslogtreecommitdiff
path: root/src/cr-rgb.c
diff options
context:
space:
mode:
authorDodji <dodji@gnome.org>2004-03-15 22:56:28 +0000
committerDodji Seketeli <dodji@src.gnome.org>2004-03-15 22:56:28 +0000
commit722a570bd3d38db5376a81349001d9bbb15e3506 (patch)
treeedb7ee853f39934daa234b044cddf243fee44a45 /src/cr-rgb.c
parent934fa2ab35547bc858df7f769ef9a5362272580c (diff)
downloadlibcroco-722a570bd3d38db5376a81349001d9bbb15e3506.tar.gz
Merged with libcroco--mainline--0.1--patch-21
2004-03-15 Dodji <dodji@gnome.org> Merged with libcroco--mainline--0.1--patch-21
Diffstat (limited to 'src/cr-rgb.c')
-rw-r--r--src/cr-rgb.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/cr-rgb.c b/src/cr-rgb.c
index 7ceea11..c125675 100644
--- a/src/cr-rgb.c
+++ b/src/cr-rgb.c
@@ -24,6 +24,8 @@
#include <stdio.h>
#include <string.h>
#include "cr-rgb.h"
+#include "cr-term.h"
+#include "cr-parser.h"
static CRRgb gv_standard_colors[] = {
{"aliceblue", 240, 248, 255, 0},
@@ -434,6 +436,42 @@ cr_rgb_set_from_hex_str (CRRgb * a_this, const guchar * a_hex)
}
/**
+ *Set the rgb from a terminal symbol
+ *@param a_this the instance of #CRRgb to set
+ *@param a_value the terminal from which to set
+ */
+enum CRStatus
+cr_rgb_set_from_term (CRRgb *a_this, const struct _CRTerm *a_value)
+{
+ enum CRStatus status = CR_OK ;
+ g_return_val_if_fail (a_this && a_value,
+ CR_BAD_PARAM_ERROR) ;
+
+ switch(a_value->type) {
+ case TERM_RGB:
+ if (a_value->content.rgb) {
+ cr_rgb_set_from_rgb
+ (a_this, a_value->content.rgb) ;
+ }
+ break ;
+ case TERM_IDENT:
+ status = cr_rgb_set_from_name
+ (a_this,
+ a_value->content.str->str) ;
+ break ;
+ case TERM_HASH:
+ status = cr_rgb_set_from_hex_str
+ (a_this,
+ a_value->content.str->str) ;
+ break ;
+ default:
+ status = CR_UNKNOWN_TYPE_ERROR ;
+ }
+
+ return status ;
+}
+
+/**
*Destructor of #CRRgb.
*@param a_this the "this pointer" of the
*current instance of #CRRgb.
@@ -445,3 +483,56 @@ cr_rgb_destroy (CRRgb * a_this)
g_free (a_this);
}
+
+/**
+ *Parses a text buffer that contains a rgb color
+ *
+ *@param a_str a string that contains a color description
+ *@param a_enc the encoding of a_str
+ *@return the parsed color, or NULL in case of error
+ */
+CRRgb *cr_rgb_parse_from_buf (const guchar *a_str,
+ enum CREncoding a_enc)
+{
+ enum CRStatus status = CR_OK ;
+ CRTerm *value = NULL ;
+ CRParser * parser = NULL;
+ CRRgb *result = NULL;
+
+ g_return_val_if_fail (a_str, NULL);
+
+ parser = cr_parser_new_from_buf ((guchar*)a_str, strlen (a_str),
+ a_enc, FALSE) ;
+
+ g_return_val_if_fail (parser, NULL);
+
+ status = cr_parser_try_to_skip_spaces_and_comments (parser) ;
+ if (status != CR_OK)
+ goto cleanup;
+
+ status = cr_parser_parse_term (parser, &value);
+ if (status != CR_OK)
+ goto cleanup;
+
+ result = cr_rgb_new ();
+ if (!result)
+ goto cleanup;
+
+ status = cr_rgb_set_from_term (result, value);
+
+cleanup:
+ if (parser) {
+ cr_parser_destroy (parser);
+ parser = NULL;
+ }
+ if (value) {
+ cr_term_destroy(value);
+ value = NULL;
+ }
+ return result ;
+}
+
+
+
+
+