diff options
author | emersion <contact@emersion.fr> | 2018-09-22 11:25:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-22 11:25:07 +0200 |
commit | b148da848ae9075822cd8ddd743532f3ce78f923 (patch) | |
tree | 0f0e3cf936553aeb28f39c5506eb94b8abcadc8f /common/pango.c | |
parent | fe7e66407cd7339eb4a91558d745a9b214e5cea9 (diff) | |
parent | 2f3650282802a01075f772df0663f170fecca29c (diff) |
Merge pull request #2679 from RyanDwyer/fix-pango-escaping
Fix pango escaping and refactor escape_markup_text
Diffstat (limited to 'common/pango.c')
-rw-r--r-- | common/pango.c | 53 |
1 files changed, 16 insertions, 37 deletions
diff --git a/common/pango.c b/common/pango.c index ea71ac4a..5afd72d8 100644 --- a/common/pango.c +++ b/common/pango.c @@ -7,66 +7,45 @@ #include <stdlib.h> #include <string.h> #include "log.h" +#include "stringop.h" -int escape_markup_text(const char *src, char *dest, int dest_length) { - int length = 0; +size_t escape_markup_text(const char *src, char *dest) { + size_t length = 0; + if (dest) { + dest[0] = '\0'; + } while (src[0]) { switch (src[0]) { case '&': length += 5; - if (dest && dest_length - length >= 0) { - dest += sprintf(dest, "%s", "&"); - } else { - dest_length = -1; - } + lenient_strcat(dest, "&"); break; case '<': length += 4; - if (dest && dest_length - length >= 0) { - dest += sprintf(dest, "%s", "<"); - } else { - dest_length = -1; - } + lenient_strcat(dest, "<"); break; case '>': length += 4; - if (dest && dest_length - length >= 0) { - dest += sprintf(dest, "%s", ">"); - } else { - dest_length = -1; - } + lenient_strcat(dest, ">"); break; case '\'': length += 6; - if (dest && dest_length - length >= 0) { - dest += sprintf(dest, "%s", "'"); - } else { - dest_length = -1; - } + lenient_strcat(dest, "'"); break; case '"': length += 6; - if (dest && dest_length - length >= 0) { - dest += sprintf(dest, "%s", """); - } else { - dest_length = -1; - } + lenient_strcat(dest, """); break; default: - length += 1; - if (dest && dest_length - length >= 0) { - *(dest++) = *src; - } else { - dest_length = -1; + if (dest) { + dest[length] = *src; + dest[length + 1] = '\0'; } + length += 1; } src++; } - // if we could not fit the escaped string in dest, return -1 - if (dest && dest_length == -1) { - return -1; - } return length; } @@ -78,7 +57,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, char *buf; GError *error = NULL; if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) { - pango_layout_set_markup(layout, buf, -1); + pango_layout_set_text(layout, buf, -1); free(buf); } else { wlr_log(WLR_ERROR, "pango_parse_markup '%s' -> error %s", text, |