diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2021-10-12 01:26:06 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2021-10-12 02:38:40 +0200 |
commit | 627c296057a91e73d3cd1631caa1e61ad4f2d124 (patch) | |
tree | bd9122d627103d9cda140964396791d82f079e86 /src/utils.c | |
parent | 13a16d1eb5b34e23aed4b17720bfbdbe85b5b5ca (diff) | |
download | tdv-627c296057a91e73d3cd1631caa1e61ad4f2d124.tar.gz tdv-627c296057a91e73d3cd1631caa1e61ad4f2d124.tar.xz tdv-627c296057a91e73d3cd1631caa1e61ad4f2d124.zip |
query-tool: support more field types
Add options to format the output for the terminal, or IRC messages.
Changed the output format to separate dictionary name with a tab,
so it's now rather similar to tabfiles.
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c index 8c63548..275e4e1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -33,6 +33,27 @@ #include "utils.h" +/// Trivially filter out all tags that aren't part of the Pango markup language, +/// or no frontend can quite handle--this seems to work well. +/// Given the nature of our display, also skip whole keyword elements. +gchar * +xdxf_to_pango_markup_with_reduced_effort (const gchar *xml) +{ + GString *filtered = g_string_new (""); + while (*xml) + { + // GMarkup can read some of the wilder XML constructs, Pango skips them + const gchar *p = NULL; + if (*xml != '<' || xml[1] == '!' || xml[1] == '?' + || g_ascii_isspace (xml[1]) || !*(p = xml + 1 + (xml[1] == '/')) + || (strchr ("biu", *p) && p[1] == '>') || !(p = strchr (p, '>'))) + g_string_append_c (filtered, *xml++); + else if (xml[1] != 'k' || xml[2] != '>' || !(xml = strstr (p, "</k>"))) + xml = ++p; + } + return g_string_free (filtered, FALSE); +} + /// Read the whole stream into a byte array. gboolean stream_read_all (GByteArray *ba, GInputStream *is, GError **error) |