]> granicus.if.org Git - libass/commitdiff
Move (r)skip_spaces to ass_utils
authorOleg Oshmyan <chortos@inbox.lv>
Sat, 17 May 2014 21:39:33 +0000 (22:39 +0100)
committerOleg Oshmyan <chortos@inbox.lv>
Fri, 6 Jun 2014 14:08:16 +0000 (15:08 +0100)
libass/ass.c
libass/ass_utils.c
libass/ass_utils.h

index 3817134404aa27355d8b9156fa0635c6daa79a25..2389740f778e106517873f2d48aa772eef5ff7ff 100644 (file)
@@ -153,22 +153,6 @@ void ass_free_style(ASS_Track *track, int sid)
 
 // ==============================================================================================
 
-static void skip_spaces(char **str)
-{
-    char *p = *str;
-    while ((*p == ' ') || (*p == '\t'))
-        ++p;
-    *str = p;
-}
-
-static void rskip_spaces(char **str, char *limit)
-{
-    char *p = *str;
-    while ((p >= limit) && ((*p == ' ') || (*p == '\t')))
-        --p;
-    *str = p;
-}
-
 /**
  * \brief Set up default style
  * \param style style to edit to defaults
@@ -297,12 +281,7 @@ static char *next_token(char **str)
         *p = '\0';
         *str = p + 1;           // ',' found, str will point to the next char (beginning of the next token)
     }
-    --p;                        // end of current token
-    rskip_spaces(&p, start);
-    if (p < start)
-        p = start;              // empty token
-    else
-        ++p;                    // the first space character, or '\0'
+    rskip_spaces(&p, start);    // end of current token: the first space character, or '\0'
     *p = '\0';
     return start;
 }
index 5140506f63c0a6a7da00e516a7ba5b507a427dc6..58ee96d8169494817c0abd4b40c114567082f9b7 100644 (file)
@@ -89,6 +89,22 @@ void ass_aligned_free(void *ptr)
         free(*((void **)ptr - 1));
 }
 
+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;
+}
+
 int mystrtoi(char **p, int *res)
 {
     double temp_res;
@@ -177,8 +193,7 @@ int strtocolor(ASS_Library *library, char **q, uint32_t *res, int hex)
 // Return a boolean value for a string
 char parse_bool(char *str)
 {
-    while (*str == ' ' || *str == '\t')
-        str++;
+    skip_spaces(&str);
     if (!strncasecmp(str, "yes", 3))
         return 1;
     else if (strtol(str, NULL, 10) > 0)
@@ -188,14 +203,12 @@ char parse_bool(char *str)
 
 int parse_ycbcr_matrix(char *str)
 {
-    while (*str == ' ' || *str == '\t')
-        str++;
+    skip_spaces(&str);
     if (*str == '\0')
         return YCBCR_DEFAULT;
 
     char *end = str + strlen(str);
-    while (end[-1] == ' ' || end[-1] == '\t')
-        end--;
+    rskip_spaces(&end, str);
 
     // Trim a local copy of the input that we know is safe to
     // modify. The buffer is larger than any valid string + NUL,
index 7228b360a8fd2f4780fb93d422e48265768386b6..7b16ca6c0059ba4730029fff89bdd6b3f201cb1f 100644 (file)
@@ -52,6 +52,8 @@ int has_avx2(void);
 void *ass_aligned_alloc(size_t alignment, size_t size);
 void ass_aligned_free(void *ptr);
 
+void skip_spaces(char **str);
+void rskip_spaces(char **str, char *limit);
 int mystrtoi(char **p, int *res);
 int mystrtoll(char **p, long long *res);
 int mystrtou32(char **p, int base, uint32_t *res);