diff --git a/src/common/common.vcxproj b/src/common/common.vcxproj
index c4fb0065..5f2107c2 100644
--- a/src/common/common.vcxproj
+++ b/src/common/common.vcxproj
@@ -43,6 +43,7 @@
+
@@ -79,6 +80,7 @@
+
diff --git a/src/common/common.vcxproj.filters b/src/common/common.vcxproj.filters
index 5b5f19c1..76723605 100644
--- a/src/common/common.vcxproj.filters
+++ b/src/common/common.vcxproj.filters
@@ -98,6 +98,9 @@
Header Files
+
+ Header Files
+
Header Files
@@ -202,6 +205,9 @@
Source Files
+
+ Source Files
+
Source Files
diff --git a/src/common/hexcolor.c b/src/common/hexcolor.c
new file mode 100644
index 00000000..ec7629a0
--- /dev/null
+++ b/src/common/hexcolor.c
@@ -0,0 +1,42 @@
+/* ZoiteChat
+ * Parsing of \004 (hex color) formatting codes: RRGGBB[,RRGGBB].
+ * Kept free of other application dependencies so the xtext widget tests can
+ * compile it on its own.
+ * Distributed under GPL-2.0-or-later; see COPYING. */
+
+#include "hexcolor.h"
+
+static int
+hexcolor_component (const char *s, int avail, guint32 *rgb)
+{
+ int i;
+ guint32 value = 0;
+
+ if (avail < 6)
+ return FALSE;
+ for (i = 0; i < 6; i++)
+ {
+ if (!g_ascii_isxdigit (s[i]))
+ return FALSE;
+ value = (value << 4) | g_ascii_xdigit_value (s[i]);
+ }
+ if (rgb)
+ *rgb = value;
+ return TRUE;
+}
+
+int
+hexcolor_parse (const char *s, int avail, guint32 *fg, guint32 *bg, int *has_bg)
+{
+ if (has_bg)
+ *has_bg = FALSE;
+ if (!hexcolor_component (s, avail, fg))
+ return 0;
+ if (avail >= 7 && s[6] == ',' && hexcolor_component (s + 7, avail - 7, bg))
+ {
+ if (has_bg)
+ *has_bg = TRUE;
+ return 13;
+ }
+ return 6;
+}
diff --git a/src/common/hexcolor.h b/src/common/hexcolor.h
new file mode 100644
index 00000000..32256224
--- /dev/null
+++ b/src/common/hexcolor.h
@@ -0,0 +1,16 @@
+/* ZoiteChat
+ * Parsing of \004 (hex color) formatting codes: RRGGBB[,RRGGBB].
+ * See https://modern.ircdocs.horse/formatting
+ * Distributed under GPL-2.0-or-later; see COPYING. */
+
+#ifndef ZOITECHAT_HEXCOLOR_H
+#define ZOITECHAT_HEXCOLOR_H
+
+#include
+
+/* Parses the parameters following a \004 byte. Returns the number of bytes
+ * consumed (6 or 13), or 0 if no valid RRGGBB follows. fg, bg and has_bg
+ * may be NULL. */
+int hexcolor_parse (const char *s, int avail, guint32 *fg, guint32 *bg, int *has_bg);
+
+#endif
diff --git a/src/common/meson.build b/src/common/meson.build
index f92c6990..e288d165 100644
--- a/src/common/meson.build
+++ b/src/common/meson.build
@@ -25,6 +25,7 @@ common_sources = [
'tree.c',
'url.c',
'userlist.c',
+ 'hexcolor.c',
'util.c'
]
@@ -201,6 +202,7 @@ test('Emoji Data Tests', emoji_data_tests,
hexcolor_tests = executable('hexcolor_tests',
[
'tests/test-hexcolor.c',
+ 'hexcolor.c',
'util.c',
],
include_directories: [config_h_include, include_directories('.')],
diff --git a/src/common/tests/test-hexcolor.c b/src/common/tests/test-hexcolor.c
index d474249b..b635a976 100644
--- a/src/common/tests/test-hexcolor.c
+++ b/src/common/tests/test-hexcolor.c
@@ -19,6 +19,7 @@
#include
+#include "../hexcolor.h"
#include "../util.h"
static void
diff --git a/src/common/util.c b/src/common/util.c
index 4ad005c0..001dc083 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -47,6 +47,7 @@
#include "zoitechatc.h"
#include
#include "util.h"
+#include "hexcolor.h"
#if defined (__FreeBSD__) || defined (__APPLE__)
#include
@@ -301,42 +302,6 @@ strip_color (const char *text, int len, int flags)
return new_str;
}
-static int
-hexcolor_component (const char *s, int avail, guint32 *rgb)
-{
- int i;
- guint32 value = 0;
-
- if (avail < 6)
- return FALSE;
- for (i = 0; i < 6; i++)
- {
- if (!g_ascii_isxdigit (s[i]))
- return FALSE;
- value = (value << 4) | g_ascii_xdigit_value (s[i]);
- }
- if (rgb)
- *rgb = value;
- return TRUE;
-}
-
-// Parses the parameters of a \004 (hex color) code: RRGGBB[,RRGGBB].
-int
-hexcolor_parse (const char *s, int avail, guint32 *fg, guint32 *bg, int *has_bg)
-{
- if (has_bg)
- *has_bg = FALSE;
- if (!hexcolor_component (s, avail, fg))
- return 0;
- if (avail >= 7 && s[6] == ',' && hexcolor_component (s + 7, avail - 7, bg))
- {
- if (has_bg)
- *has_bg = TRUE;
- return 13;
- }
- return 6;
-}
-
/* CL: strip_color2 strips src and writes the output at dst; pass the same pointer
in both arguments to strip in place. */
int
diff --git a/src/common/util.h b/src/common/util.h
index f6b2d4d6..4774f3bc 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -59,7 +59,6 @@ void util_exec (const char *cmd);
#define STRIP_ALL 7
gchar *strip_color (const char *text, int len, int flags);
int strip_color2 (const char *src, int len, char *dst, int flags);
-int hexcolor_parse (const char *s, int avail, guint32 *fg, guint32 *bg, int *has_bg);
int strip_hidden_attribute (char *src, char *dst);
char *errorstring (int err);
int waitline (int sok, char *buf, int bufsize, int);
diff --git a/src/fe-gtk/meson.build b/src/fe-gtk/meson.build
index d74ff813..4f3d0aef 100644
--- a/src/fe-gtk/meson.build
+++ b/src/fe-gtk/meson.build
@@ -280,7 +280,7 @@ test('Emoji Font Tests', emoji_font_tests,
)
xtext_tests = executable('xtext_tests',
- 'tests/test-xtext.c',
+ ['tests/test-xtext.c', '../common/hexcolor.c'],
include_directories: [config_h_include],
dependencies: [gtk_dep],
)
diff --git a/src/fe-gtk/xtext.c b/src/fe-gtk/xtext.c
index 23cc2143..c9235567 100644
--- a/src/fe-gtk/xtext.c
+++ b/src/fe-gtk/xtext.c
@@ -35,6 +35,7 @@
#include "../common/zoitechat.h"
#include "../common/fe.h"
#include "../common/util.h"
+#include "../common/hexcolor.h"
#include "../common/zoitechatc.h"
#include "../common/url.h"