summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOneric <oneric@oneric.stub>2022-10-21 18:17:28 +0200
committerOneric <oneric@oneric.stub>2022-10-22 03:42:54 +0200
commit4958453575f59a029a411a318495da35184f4278 (patch)
tree3a2daed82847aa80ed0f5ecf9a37b1cf13299e94
parentf6e1987c08e25d88b6dfa12dafaffc42f5499011 (diff)
downloadlibass-4958453575f59a029a411a318495da35184f4278.tar.bz2
libass-4958453575f59a029a411a318495da35184f4278.tar.xz
refactor/utils: turn some functions into static inlines
They are used in multiple files but short enough to inline.
-rw-r--r--libass/ass_utils.c39
-rw-r--r--libass/ass_utils.h42
2 files changed, 39 insertions, 42 deletions
diff --git a/libass/ass_utils.c b/libass/ass_utils.c
index 11864b2..7692c9a 100644
--- a/libass/ass_utils.c
+++ b/libass/ass_utils.c
@@ -23,7 +23,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
-#include <limits.h>
#include <inttypes.h>
#include "ass_library.h"
@@ -157,44 +156,6 @@ void *ass_try_realloc_array(void *ptr, size_t nmemb, size_t size)
}
}
-void skip_spaces(char **str)
-{
- char *p = *str;
- while ((*p == ' ') || (*p == '\t'))
- ++p;
- *str = p;
-}
-
-void rskip_spaces(char **str, char *limit)
-{
- char *p = *str;
- while ((p > limit) && ((p[-1] == ' ') || (p[-1] == '\t')))
- --p;
- *str = p;
-}
-
-/**
- * \brief converts numpad-style align to align.
- */
-int numpad2align(int val)
-{
- if (val < -INT_MAX)
- // Pick an alignment somewhat arbitrarily. VSFilter handles
- // INT32_MIN as a mix of 1, 2 and 3, so prefer one of those values.
- val = 2;
- else if (val < 0)
- val = -val;
-
- int res = ((val - 1) % 3) + 1; // horizontal alignment
- if (val <= 3)
- res |= VALIGN_SUB;
- else if (val <= 6)
- res |= VALIGN_CENTER;
- else
- res |= VALIGN_TOP;
- return res;
-}
-
void ass_msg(ASS_Library *priv, int lvl, const char *fmt, ...)
{
va_list va;
diff --git a/libass/ass_utils.h b/libass/ass_utils.h
index b685f3e..c9e9b7c 100644
--- a/libass/ass_utils.h
+++ b/libass/ass_utils.h
@@ -27,6 +27,7 @@
#include <string.h>
#include <assert.h>
#include <errno.h>
+#include <limits.h>
#include <math.h>
#include "ass.h"
@@ -93,9 +94,6 @@ void *ass_try_realloc_array(void *ptr, size_t nmemb, size_t size);
#define ASS_REALLOC_ARRAY(ptr, count) \
(errno = 0, (ptr) = ass_try_realloc_array(ptr, count, sizeof(*ptr)), !errno)
-void skip_spaces(char **str);
-void rskip_spaces(char **str, char *limit);
-int numpad2align(int val);
unsigned ass_utf8_get_char(char **str);
unsigned ass_utf8_put_char(char *dest, uint32_t ch);
void ass_utf16be_to_utf8(char *dst, size_t dst_size, uint8_t *src, size_t src_size);
@@ -110,6 +108,44 @@ int lookup_style(ASS_Track *track, char *name);
/* defined in ass_strtod.c */
double ass_strtod(const char *string, char **endPtr);
+static inline void skip_spaces(char **str)
+{
+ char *p = *str;
+ while ((*p == ' ') || (*p == '\t'))
+ ++p;
+ *str = p;
+}
+
+static inline void rskip_spaces(char **str, char *limit)
+{
+ char *p = *str;
+ while ((p > limit) && ((p[-1] == ' ') || (p[-1] == '\t')))
+ --p;
+ *str = p;
+}
+
+/**
+ * \brief converts numpad-style align to align.
+ */
+static inline int numpad2align(int val)
+{
+ if (val < -INT_MAX)
+ // Pick an alignment somewhat arbitrarily. VSFilter handles
+ // INT32_MIN as a mix of 1, 2 and 3, so prefer one of those values.
+ val = 2;
+ else if (val < 0)
+ val = -val;
+
+ int res = ((val - 1) % 3) + 1; // horizontal alignment
+ if (val <= 3)
+ res |= VALIGN_SUB;
+ else if (val <= 6)
+ res |= VALIGN_CENTER;
+ else
+ res |= VALIGN_TOP;
+ return res;
+}
+
static inline size_t ass_align(size_t alignment, size_t s)
{
if (s > SIZE_MAX - (alignment - 1))