summaryrefslogtreecommitdiffstats
path: root/libass/ass_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'libass/ass_utils.c')
-rw-r--r--libass/ass_utils.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/libass/ass_utils.c b/libass/ass_utils.c
index 40e6533..06ae8c7 100644
--- a/libass/ass_utils.c
+++ b/libass/ass_utils.c
@@ -331,22 +331,26 @@ void ass_msg(ASS_Library *priv, int lvl, char *fmt, ...)
va_end(va);
}
-char *trim_space(char *str)
+/**
+ * Return a string with spaces trimmed at start and end.
+ * \param str input string
+ * \return output string, can be released with free()
+ */
+char *strdup_trimmed(const char *str)
{
- int i;
int left = 0;
int right = strlen(str) - 1;
+ char *out = NULL;
while (isspace(str[left])) left++;
while (right > left && isspace(str[right])) right--;
- if (left > 0)
- for (i = 0; i <= right - left; i++)
- str[i] = str[left+i];
+ out = calloc(1, right-left+2);
- str[right-left+1] = '\0';
+ if (out)
+ memcpy(out, str + left, right-left+1);
- return str;
+ return out;
}
unsigned ass_utf8_get_char(char **str)