diff th_string.c @ 378:afbc3bfd3e03

Sync th-libs.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 03 Oct 2011 00:31:46 +0300
parents 9ad157feb99a
children
line wrap: on
line diff
--- a/th_string.c	Mon Oct 03 00:04:33 2011 +0300
+++ b/th_string.c	Mon Oct 03 00:31:46 2011 +0300
@@ -17,16 +17,16 @@
     char *res;
     if (s == NULL)
         return NULL;
-    
+
     if ((res = th_malloc(strlen(s) + 1)) == NULL)
         return NULL;
-    
+
     strcpy(res, s);
     return res;
 }
 
 
-char *th_strncpy(char * dst, const char * src, const size_t n)
+char *th_strncpy(char *dst, const char *src, const size_t n)
 {
     const char *s = src;
     char *d = dst;
@@ -58,14 +58,14 @@
 
 /* Simulate a sprintf() that allocates memory
  */
-char * th_strdup_vprintf(const char *fmt, va_list args)
+char *th_strdup_vprintf(const char *fmt, va_list args)
 {
     int size = 64;
     char *buf, *nbuf = NULL;
 
     if ((buf = th_malloc(size)) == NULL)
         return NULL;
-    
+
     while (1)
     {
         int n;
@@ -86,13 +86,13 @@
             th_free(buf);
             return NULL;
         }
-        
+
         buf = nbuf;
     }
 }
 
 
-char * th_strdup_printf(const char *fmt, ...)
+char *th_strdup_printf(const char *fmt, ...)
 {
     char *res;
     va_list ap;
@@ -128,7 +128,7 @@
 
 /* Compare two strings ignoring case [strcasecmp, strncasecmp]
  */
-int th_strcasecmp(const char * str1, const char * str2)
+int th_strcasecmp(const char *str1, const char *str2)
 {
     const char *s1 = str1, *s2 = str2;
     assert(str1 != NULL);
@@ -147,7 +147,7 @@
 }
 
 
-int th_strncasecmp(const char * str1, const char * str2, size_t n)
+int th_strncasecmp(const char *str1, const char *str2, size_t n)
 {
     const char *s1 = str1, *s2 = str2;
     assert(str1 != NULL);
@@ -170,7 +170,7 @@
 /* Remove all occurences of control characters, in-place.
  * Resulting string is always shorter or same length than original.
  */
-void th_strip_ctrlchars(char * str)
+void th_strip_ctrlchars(char *str)
 {
     char *i, *j;
     assert(str != NULL);
@@ -190,7 +190,7 @@
 
 /* Copy a given string over in *result.
  */
-int th_pstrcpy(char ** result, const char * str)
+int th_pstrcpy(char **result, const char *str)
 {
     assert(result != NULL);
 
@@ -208,7 +208,7 @@
 
 /* Concatenates a given string into string pointed by *result.
  */
-int th_pstrcat(char ** result, const char * str)
+int th_pstrcat(char **result, const char *str)
 {
     assert(result != NULL);
 
@@ -240,7 +240,7 @@
  * Updates iPos into the position of such character and
  * returns pointer to the string.
  */
-const char *th_findnext(const char * str, size_t * pos)
+const char *th_findnext(const char *str, size_t *pos)
 {
     assert(str != NULL);
 
@@ -254,7 +254,7 @@
 
 /* Find next sep-character from string
  */
-const char *th_findsep(const char * str, size_t * pos, char sep)
+const char *th_findsep(const char *str, size_t *pos, char sep)
 {
     assert(str != NULL);
 
@@ -267,7 +267,7 @@
 
 /* Find next sep- or whitespace from string
  */
-const char *th_findseporspace(const char * str, size_t * pos, char sep)
+const char *th_findseporspace(const char *str, size_t *pos, char sep)
 {
     assert(str != NULL);
 
@@ -283,7 +283,7 @@
  * wildcards ? and *. "?" matches any character and "*" matches
  * any number of characters.
  */
-BOOL th_strmatch(const char * str, const char * pattern)
+BOOL th_strmatch(const char *str, const char *pattern)
 {
     BOOL didMatch = TRUE, isAnyMode = FALSE, isEnd = FALSE;
     const char *tmpPattern = NULL;
@@ -293,7 +293,8 @@
         return FALSE;
 
     /* Start comparision */
-    do {
+    do
+    {
         didMatch = FALSE;
         switch (*pattern)
         {
@@ -335,7 +336,8 @@
                     }
                     else
                         didMatch = FALSE;
-                } else
+                }
+                else
                     isEnd = TRUE;
             }
             break;
@@ -381,9 +383,10 @@
                 isEnd = TRUE;
             break;
 
-        }        /* switch */
+        }                       /* switch */
 
-    } while (didMatch && !isEnd);
+    }
+    while (didMatch && !isEnd);
 
     return didMatch;
 }
@@ -391,7 +394,7 @@
 
 /* Compare a string to a pattern. Case-INSENSITIVE version.
  */
-BOOL th_strcasematch(const char * str, const char * pattern)
+BOOL th_strcasematch(const char *str, const char *pattern)
 {
     BOOL didMatch = TRUE, isAnyMode = FALSE, isEnd = FALSE;
     const char *tmpPattern = NULL;
@@ -401,15 +404,18 @@
         return FALSE;
 
     /* Start comparision */
-    do {
-        switch (*pattern) {
+    do
+    {
+        switch (*pattern)
+        {
         case '?':
             /* Any single character matches */
             if (*str)
             {
                 pattern++;
                 str++;
-            } else
+            }
+            else
                 didMatch = FALSE;
             break;
 
@@ -440,7 +446,8 @@
                     }
                     else
                         didMatch = FALSE;
-                } else
+                }
+                else
                     isEnd = TRUE;
             }
             break;
@@ -486,9 +493,10 @@
 
             break;
 
-        }        /* switch */
+        }                       /* switch */
 
-    } while (didMatch && !isEnd);
+    }
+    while (didMatch && !isEnd);
 
     return didMatch;
 }
@@ -498,7 +506,7 @@
 {
     const char *p = str;
     int len, val = 0;
-    
+
     for (len = 0; *p && len < 6; p++, len++)
     {
         if (*p >= '0' && *p <= '9')
@@ -519,7 +527,7 @@
         else
             return -1;
     }
-    
+
     return (len == 6) ? val : -1;
 }
 
@@ -528,7 +536,7 @@
 {
     if (*buf == NULL)
         *bufsize = *len = 0;
-    
+
     if (*buf == NULL || *len + grow >= *bufsize)
     {
         *bufsize += grow + TH_BUFGROW;
@@ -544,7 +552,7 @@
 {
     if (!th_growbuf(buf, bufsize, len, 1))
         return FALSE;
-    
+
     (*buf)[*len] = ch;
     (*len)++;
 
@@ -557,14 +565,13 @@
     size_t slen;
     if (str == NULL)
         return FALSE;
-    
+
     slen = strlen(str);
     if (!th_growbuf(buf, bufsize, len, slen))
         return FALSE;
 
     strcpy(*buf + *len, str);
     (*len) += slen;
-    
+
     return TRUE;
 }
-