summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrigori Goronzy <greg@chown.ath.cx>2011-08-15 22:04:02 +0200
committerGrigori Goronzy <greg@chown.ath.cx>2015-07-10 10:42:40 +0200
commit1fbe520d41d8a92082826b15dbd1cc54a067fa48 (patch)
tree9580e0cab8e4170caf0f4b2f1971bb50d5143fbe
parentc22a4ff9a395546637dbe0f1e9d0ee549dd0069a (diff)
downloadlibass-1fbe520d41d8a92082826b15dbd1cc54a067fa48.tar.bz2
libass-1fbe520d41d8a92082826b15dbd1cc54a067fa48.tar.xz
Trim spaces of font family strings
This adds a trimming utility function that is used for trimming strings of font requests in the font sorter.
-rw-r--r--libass/ass_fontselect.c5
-rw-r--r--libass/ass_utils.c20
-rw-r--r--libass/ass_utils.h1
3 files changed, 23 insertions, 3 deletions
diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c
index 481d4c9..2ca6f9d 100644
--- a/libass/ass_fontselect.c
+++ b/libass/ass_fontselect.c
@@ -263,8 +263,8 @@ static char *select_font(ASS_FontSelector *priv, ASS_Library *library,
req.weight = bold;
req.n_fullname = 1;
req.fullnames = &req_fullname;
- req.fullnames[0] = (char *)family;
- req.family = strdup(family);
+ req.fullnames[0] = trim_space(strdup(family));
+ req.family = trim_space(strdup(family));
char *p = strchr(req.family, ' ');
if (p) *p = 0;
@@ -281,6 +281,7 @@ static char *select_font(ASS_FontSelector *priv, ASS_Library *library,
&& font_infos[info_index].funcs.check_glyph(font_infos[info_index].priv, code) == 0)
info_index++;
+ free(req.fullnames[0]);
free(req.family);
// return best match
diff --git a/libass/ass_utils.c b/libass/ass_utils.c
index a6a063b..0fc8b2a 100644
--- a/libass/ass_utils.c
+++ b/libass/ass_utils.c
@@ -24,7 +24,7 @@
#include <stdint.h>
#include <inttypes.h>
#include <strings.h>
-#include <limits.h>
+#include <ctype.h>
#include "ass_library.h"
#include "ass.h"
@@ -331,6 +331,24 @@ void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...)
va_end(va);
}
+char *trim_space(char *str)
+{
+ int i;
+ int left = 0;
+ int right = strlen(str) - 1;
+
+ while (isspace(str[left])) left++;
+ while (isspace(str[right])) right--;
+
+ if (left > 0)
+ for (i = 0; i <= right - left; i++)
+ str[i] = str[left+i];
+
+ str[right-left+1] = '\0';
+
+ return str;
+}
+
unsigned ass_utf8_get_char(char **str)
{
uint8_t *strp = (uint8_t *) * str;
diff --git a/libass/ass_utils.h b/libass/ass_utils.h
index 45ebbb6..f249bc9 100644
--- a/libass/ass_utils.h
+++ b/libass/ass_utils.h
@@ -90,6 +90,7 @@ int mystrtoi32(char **p, int base, int32_t *res);
int32_t parse_alpha_tag(char *str);
uint32_t parse_color_tag(char *str);
uint32_t parse_color_header(char *str);
+char *trim_space(char *str);
char parse_bool(char *str);
int parse_ycbcr_matrix(char *str);
unsigned ass_utf8_get_char(char **str);