[geany/geany] 8a0422: Support normal and abbreviated HTML hex triplets in color schemes

Matthew Brush git-noreply at xxxxx
Thu Jul 26 00:02:28 UTC 2012


Branch:      refs/heads/document-messages
Author:      Matthew Brush <matt at geany.org>
Committer:   Matthew Brush <matt at geany.org>
Date:        Sun, 25 Dec 2011 21:43:20
Commit:      8a04222301008c7429d3c23c0fca3ba0e3a3cbf1
             https://github.com/geany/geany/commit/8a04222301008c7429d3c23c0fca3ba0e3a3cbf1

Log Message:
-----------
Support normal and abbreviated HTML hex triplets in color schemes


Modified Paths:
--------------
    src/highlighting.c

Modified: src/highlighting.c
27 files changed, 25 insertions(+), 2 deletions(-)
===================================================================
@@ -206,15 +206,38 @@ static gboolean read_named_style(const gchar *named_style, GeanyLexerStyle *styl
 }
 
 
+/* Parses a color in `str` which can be an HTML color (ex. #0099cc),
+ * an abbreviated HTML color (ex. #09c) or a hex string color
+ * (ex. 0x0099cc). The result of the conversion is stored into the
+ * location pointed to by `clr`. */
 static void parse_color(const gchar *str, gint *clr)
 {
 	gint c;
+	gchar hex_clr[9] = { 0 };
+	const gchar *start;
+
+	g_return_if_fail(clr != NULL);
 
-	/* ignore empty strings */
 	if (G_UNLIKELY(! NZV(str)))
 		return;
 
-	c = utils_strtod(str, NULL, FALSE);
+	if (str[0] == '#')
+		start = str + 1;
+	else if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
+		start = str + 2;
+	else
+		start = str;
+
+	if (strlen(start) == 3)
+	{
+		snprintf(hex_clr, 9, "0x%c%c%c%c%c%c", start[0], start[0],
+			start[1], start[1], start[2], start[2]);
+	}
+	else
+		snprintf(hex_clr, 9, "0x%s", start);
+
+	c = utils_strtod(hex_clr, NULL, FALSE);
+
 	if (c > -1)
 	{
 		*clr = c;


@@ Diff output truncated at 100000 characters. @@


--------------
This E-Mail was brought to you by github_commit_mail.py (Source: TBD).



More information about the Commits mailing list