]> arthur.barton.de Git - netatalk.git/commitdiff
indent
authorHAT <hat@fa2.so-net.ne.jp>
Wed, 22 Dec 2010 10:51:54 +0000 (19:51 +0900)
committerHAT <hat@fa2.so-net.ne.jp>
Wed, 22 Dec 2010 10:51:54 +0000 (19:51 +0900)
libatalk/unicode/util_unistr.c

index 45ffcd93f19db8a9ccb0e6ee9ec942c83eac16c8..d08f86262e659c2ca643b596c2d672fd04f02de7 100644 (file)
@@ -78,16 +78,16 @@ ucs2_t tolower_w(ucs2_t val)
 ********************************************************************/
 int strlower_w(ucs2_t *s)
 {
-        int ret = 0;
-        while (*s) {
-                ucs2_t v = tolower_w(*s);
-                if (v != *s) {
-                        *s = v;
-                        ret = 1;
-                }
-                s++;
-        }
-        return ret;
+       int ret = 0;
+       while (*s) {
+               ucs2_t v = tolower_w(*s);
+               if (v != *s) {
+                       *s = v;
+                       ret = 1;
+               }
+               s++;
+       }
+       return ret;
 }
 
 /*******************************************************************
@@ -96,16 +96,16 @@ int strlower_w(ucs2_t *s)
 ********************************************************************/
 int strupper_w(ucs2_t *s)
 {
-        int ret = 0;
-        while (*s) {
-                ucs2_t v = toupper_w(*s);
-                if (v != *s) {
-                        *s = v;
-                        ret = 1;
-                }
-                s++;
-        }
-        return ret;
+       int ret = 0;
+       while (*s) {
+               ucs2_t v = toupper_w(*s);
+               if (v != *s) {
+                       *s = v;
+                       ret = 1;
+               }
+               s++;
+       }
+       return ret;
 }
 
 
@@ -179,18 +179,18 @@ ucs2_t *strcasechr_w(const ucs2_t *s, ucs2_t c)
 
 int strcmp_w(const ucs2_t *a, const ucs2_t *b)
 {
-        while (*b && *a == *b) { a++; b++; }
-        return (*a - *b);
-        /* warning: if *a != *b and both are not 0 we retrun a random
-                greater or lesser than 0 number not realted to which
-                string is longer */
+       while (*b && *a == *b) { a++; b++; }
+       return (*a - *b);
+       /* warning: if *a != *b and both are not 0 we retrun a random
+          greater or lesser than 0 number not realted to which
+          string is longer */
 }
 
 int strncmp_w(const ucs2_t *a, const ucs2_t *b, size_t len)
 {
-        size_t n = 0;
-        while ((n < len) && *b && *a == *b) { a++; b++; n++;}
-        return (len - n)?(*a - *b):0;
+       size_t n = 0;
+       while ((n < len) && *b && *a == *b) { a++; b++; n++;}
+       return (len - n)?(*a - *b):0;
 }
 
 /*******************************************************************
@@ -236,8 +236,8 @@ case insensitive string comparison
 ********************************************************************/
 int strcasecmp_w(const ucs2_t *a, const ucs2_t *b)
 {
-        while (*b && toupper_w(*a) == toupper_w(*b)) { a++; b++; }
-        return (tolower_w(*a) - tolower_w(*b));
+       while (*b && toupper_w(*a) == toupper_w(*b)) { a++; b++; }
+       return (tolower_w(*a) - tolower_w(*b));
 }
 
 /*******************************************************************
@@ -245,9 +245,9 @@ case insensitive string comparison, lenght limited
 ********************************************************************/
 int strncasecmp_w(const ucs2_t *a, const ucs2_t *b, size_t len)
 {
-        size_t n = 0;
-        while ((n < len) && *b && (toupper_w(*a) == toupper_w(*b))) { a++; b++; n++; }
-        return (len - n)?(tolower_w(*a) - tolower_w(*b)):0;
+       size_t n = 0;
+       while ((n < len) && *b && (toupper_w(*a) == toupper_w(*b))) { a++; b++; n++; }
+       return (len - n)?(tolower_w(*a) - tolower_w(*b)):0;
 }
 
 /*******************************************************************
@@ -256,24 +256,24 @@ duplicate string
 /* if len == 0 then duplicate the whole string */
 ucs2_t *strndup_w(const ucs2_t *src, size_t len)
 {
-        ucs2_t *dest;
+       ucs2_t *dest;
 
-        if (!len) len = strlen_w(src);
-        dest = (ucs2_t *)malloc((len + 1) * sizeof(ucs2_t));
-        if (!dest) {
-                LOG (log_error, logtype_default, "strdup_w: out of memory!");
-                return NULL;
-        }
+       if (!len) len = strlen_w(src);
+       dest = (ucs2_t *)malloc((len + 1) * sizeof(ucs2_t));
+       if (!dest) {
+               LOG (log_error, logtype_default, "strdup_w: out of memory!");
+               return NULL;
+       }
 
-        memcpy(dest, src, len * sizeof(ucs2_t));
-        dest[len] = 0;
+       memcpy(dest, src, len * sizeof(ucs2_t));
+       dest[len] = 0;
 
-        return dest;
+       return dest;
 }
 
 ucs2_t *strdup_w(const ucs2_t *src)
 {
-        return strndup_w(src, 0);
+       return strndup_w(src, 0);
 }
 
 /*******************************************************************
@@ -282,16 +282,16 @@ copy a string with max len
 
 ucs2_t *strncpy_w(ucs2_t *dest, const ucs2_t *src, const size_t max)
 {
-        size_t len;
+       size_t len;
 
-        if (!dest || !src) return NULL;
+       if (!dest || !src) return NULL;
 
-        for (len = 0; (src[len] != 0) && (len < max); len++)
-                dest[len] = src[len];
-        while (len < max)
-                dest[len++] = 0;
+       for (len = 0; (src[len] != 0) && (len < max); len++)
+               dest[len] = src[len];
+       while (len < max)
+               dest[len++] = 0;
 
-        return dest;
+       return dest;
 }
 
 
@@ -301,86 +301,86 @@ append a string of len bytes and add a terminator
 
 ucs2_t *strncat_w(ucs2_t *dest, const ucs2_t *src, const size_t max)
 {
-        size_t start;
-        size_t len;
+       size_t start;
+       size_t len;
 
-        if (!dest || !src) return NULL;
+       if (!dest || !src) return NULL;
 
-        start = strlen_w(dest);
-        len = strnlen_w(src, max);
+       start = strlen_w(dest);
+       len = strnlen_w(src, max);
 
-        memcpy(&dest[start], src, len*sizeof(ucs2_t));
-        dest[start+len] = 0;
+       memcpy(&dest[start], src, len*sizeof(ucs2_t));
+       dest[start+len] = 0;
 
-        return dest;
+       return dest;
 }
 
 
 ucs2_t *strcat_w(ucs2_t *dest, const ucs2_t *src)
 {
-        size_t start;
-        size_t len;
+       size_t start;
+       size_t len;
 
-        if (!dest || !src) return NULL;
+       if (!dest || !src) return NULL;
 
-        start = strlen_w(dest);
-        len = strlen_w(src);
+       start = strlen_w(dest);
+       len = strlen_w(src);
 
-        memcpy(&dest[start], src, len*sizeof(ucs2_t));
-        dest[start+len] = 0;
+       memcpy(&dest[start], src, len*sizeof(ucs2_t));
+       dest[start+len] = 0;
 
-        return dest;
+       return dest;
 }
 
 
 /* ------------------------ */
 static ucs2_t do_precomposition(unsigned int base, unsigned int comb) 
 {
-       int min = 0;
-       int max = sizeof(precompositions) / sizeof(precompositions[0]) - 1;
-       int mid;
-       u_int32_t sought = (base << 16) | comb, that;
-
-       /* binary search */
-       while (max >= min) {
-               mid = (min + max) / 2;
-               that = (precompositions[mid].base << 16) | (precompositions[mid].comb);
-               if (that < sought) {
-                       min = mid + 1;
-               } else if (that > sought) {
-                       max = mid - 1;
-               } else {
-                       return precompositions[mid].replacement;
-               }
-       }
-       /* no match */
-       return 0;
+       int min = 0;
+       int max = sizeof(precompositions) / sizeof(precompositions[0]) - 1;
+       int mid;
+       u_int32_t sought = (base << 16) | comb, that;
+
+       /* binary search */
+       while (max >= min) {
+               mid = (min + max) / 2;
+               that = (precompositions[mid].base << 16) | (precompositions[mid].comb);
+               if (that < sought) {
+                       min = mid + 1;
+               } else if (that > sought) {
+                       max = mid - 1;
+               } else {
+                       return precompositions[mid].replacement;
+               }
+       }
+       /* no match */
+       return 0;
 }
 
 /* -------------------------- */
 static u_int32_t do_decomposition(ucs2_t base) 
 {
-       int min = 0;
-       int max = sizeof(decompositions) / sizeof(decompositions[0]) - 1;
-       int mid;
-       u_int32_t sought = base;
-       u_int32_t result, that;
-
-       /* binary search */
-       while (max >= min) {
-               mid = (min + max) / 2;
-               that = decompositions[mid].replacement;
-               if (that < sought) {
-                       min = mid + 1;
-               } else if (that > sought) {
-                       max = mid - 1;
-               } else {
-                       result = (decompositions[mid].base << 16) | (decompositions[mid].comb);
-                       return result;
-               }
-       }
-       /* no match */
-       return 0;
+       int min = 0;
+       int max = sizeof(decompositions) / sizeof(decompositions[0]) - 1;
+       int mid;
+       u_int32_t sought = base;
+       u_int32_t result, that;
+
+       /* binary search */
+       while (max >= min) {
+               mid = (min + max) / 2;
+               that = decompositions[mid].replacement;
+               if (that < sought) {
+                       min = mid + 1;
+               } else if (that > sought) {
+                       max = mid - 1;
+               } else {
+                       result = (decompositions[mid].base << 16) | (decompositions[mid].comb);
+                       return result;
+               }
+       }
+       /* no match */
+       return 0;
 }
 
 /* we can't use static, this stuff needs to be reentrant */
@@ -395,8 +395,8 @@ size_t precompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen)
        ucs2_t result;
        size_t o_len = *outlen;
 
-       if (!inplen || (inplen & 1) || inplen > o_len)
-               return (size_t)-1;
+       if (!inplen || (inplen & 1) || inplen > o_len)
+               return (size_t)-1;
        
        /*   Actually,                                                 */
        /*   Decomposition and Canonical Ordering are necessary here.  */
@@ -405,22 +405,22 @@ size_t precompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen)
        /*                                                             */
        /*   A new mapping table is needed for CanonicalOrdering.      */
        
-       i = 0;
-       in  = name;
+       i = 0;
+       in  = name;
        out = comp;
-    
-       base = *in;
-       while (*outlen > 2) {
-               i += 2;
-               in++;
-               if (i == inplen) {
-                       *out = base;
+
+       base = *in;
+       while (*outlen > 2) {
+               i += 2;
+               in++;
+               if (i == inplen) {
+                       *out = base;
                        out++;
                        *out = 0;
-                       *outlen -= 2;
-                       return o_len - *outlen;
-               }
-               comb = *in;
+                       *outlen -= 2;
+                       return o_len - *outlen;
+               }
+               comb = *in;
                result = 0;
                
                /* Non-Combination Character */
@@ -435,7 +435,7 @@ size_t precompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen)
                                hangul_vindex = comb - HANGUL_VBASE;
                                base = HANGUL_SBASE + (hangul_lindex * HANGUL_VCOUNT + hangul_vindex) * HANGUL_TCOUNT;
                        }
-               }
+               }
                
                /* Step 2 <LV,T> */
                else if ((HANGUL_TBASE < comb) && (comb < HANGUL_TBASE + HANGUL_TCOUNT)) {
@@ -451,12 +451,12 @@ size_t precompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen)
                }
                
                if (!result) {
-                       *out = base;
-                       out++;
-                       *outlen -= 2;
-                       base = comb;
-               }
-       }
+                       *out = base;
+                       out++;
+                       *outlen -= 2;
+                       base = comb;
+               }
+       }
        
        errno = E2BIG;
        return (size_t)-1;
@@ -478,14 +478,14 @@ size_t decompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen)
        unsigned int result;
        size_t o_len = *outlen;
 
-       if (!inplen || (inplen & 1))
-               return (size_t)-1;
+       if (!inplen || (inplen & 1))
+               return (size_t)-1;
        i = 0;
        in  = name;
        out = comp;
-    
-       while (i < inplen) {
-               base = *in;
+
+       while (i < inplen) {
+               base = *in;
                comblen = 0;
                
                /* check ASCII first. this is frequent. */
@@ -523,24 +523,24 @@ size_t decompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen)
                }
                
                if (*outlen < (comblen + 1) << 1) {
-                               errno = E2BIG;
-                               return (size_t)-1;
-                       }
+                       errno = E2BIG;
+                       return (size_t)-1;
+               }
                
                *out = base;
-                       out++;
-                       *outlen -= 2;
+               out++;
+               *outlen -= 2;
                
                while ( comblen > 0 ) {
                        *out = comb[MAXCOMBLEN-comblen];
-                       out++;
-                       *outlen -= 2;
+                       out++;
+                       *outlen -= 2;
                        comblen--;
-               }
+               }
                
-               i += 2;
-               in++;
-       }
+               i += 2;
+               in++;
+       }
 
        /* Is Canonical Ordering necessary here? */
        
@@ -550,12 +550,12 @@ size_t decompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen)
 
 size_t utf8_charlen ( char* utf8 )
 {
-        unsigned char *p;
+       unsigned char *p;
 
-        p = (unsigned char*) utf8;
+       p = (unsigned char*) utf8;
        
        if ( *p < 0x80 )
-               return (1);
+               return (1);
        else if ( *p > 0xC1 && *p < 0xe0 && *(p+1) > 0x7f && *(p+1) < 0xC0)
                return (2);
        else if ( *p == 0xe0 && *(p+1) > 0x9f && *(p+1) < 0xc0 && *(p+2) > 0x7f && *(p+2) < 0xc0)
@@ -575,43 +575,42 @@ size_t utf8_charlen ( char* utf8 )
 
 size_t utf8_strlen_validate ( char * utf8 )
 {
-        size_t len;
-        unsigned char *p;
+       size_t len;
+       unsigned char *p;
 
-        p = (unsigned char*) utf8;
-        len = 0;
+       p = (unsigned char*) utf8;
+       len = 0;
 
-        /* see http://www.unicode.org/unicode/reports/tr27/ for an explanation */
+       /* see http://www.unicode.org/unicode/reports/tr27/ for an explanation */
 
-        while ( *p != '\0')
-        {
-                if ( *p < 0x80 )
-                        p++;
+       while ( *p != '\0')
+       {
+               if ( *p < 0x80 )
+                       p++;
 
-                else if ( *p > 0xC1 && *p < 0xe0 && *(p+1) > 0x7f && *(p+1) < 0xC0)
-                        p += 2;
+               else if ( *p > 0xC1 && *p < 0xe0 && *(p+1) > 0x7f && *(p+1) < 0xC0)
+                       p += 2;
 
-                else if ( *p == 0xe0 && *(p+1) > 0x9f && *(p+1) < 0xc0 && *(p+2) > 0x7f && *(p+2) < 0xc0)
-                        p += 3;
+               else if ( *p == 0xe0 && *(p+1) > 0x9f && *(p+1) < 0xc0 && *(p+2) > 0x7f && *(p+2) < 0xc0)
+                       p += 3;
 
-                else if ( *p > 0xe0  && *p < 0xf0 && *(p+1) > 0x7f && *(p+1) < 0xc0 && *(p+2) > 0x7f && *(p+2) < 0xc0)
-                        p += 3;
+               else if ( *p > 0xe0  && *p < 0xf0 && *(p+1) > 0x7f && *(p+1) < 0xc0 && *(p+2) > 0x7f && *(p+2) < 0xc0)
+                       p += 3;
 
-                else if ( *p == 0xf0 && *(p+1) > 0x8f && *(p+1) < 0xc0 && *(p+2) > 0x7f && *(p+2) < 0xc0 && *(p+3) > 0x7f && *(p+3) < 0xc0 )
-                        p += 4;
+               else if ( *p == 0xf0 && *(p+1) > 0x8f && *(p+1) < 0xc0 && *(p+2) > 0x7f && *(p+2) < 0xc0 && *(p+3) > 0x7f && *(p+3) < 0xc0 )
+                       p += 4;
 
-                else if ( *p > 0xf0 && *p < 0xf4 && *(p+1) > 0x7f && *(p+1) < 0xc0 && *(p+2) > 0x7f && *(p+2) < 0xc0 && *(p+3) > 0x7f && *(p+3) < 0xc0 )
-                        p += 4;
+               else if ( *p > 0xf0 && *p < 0xf4 && *(p+1) > 0x7f && *(p+1) < 0xc0 && *(p+2) > 0x7f && *(p+2) < 0xc0 && *(p+3) > 0x7f && *(p+3) < 0xc0 )
+                       p += 4;
 
-                else if ( *p == 0xf4 && *(p+1) > 0x7f && *(p+1) < 0x90 && *(p+2) > 0x7f && *(p+2) < 0xc0 && *(p+3) > 0x7f && *(p+3) < 0xc0 )
-                        p += 4;
+               else if ( *p == 0xf4 && *(p+1) > 0x7f && *(p+1) < 0x90 && *(p+2) > 0x7f && *(p+2) < 0xc0 && *(p+3) > 0x7f && *(p+3) < 0xc0 )
+                       p += 4;
 
-                else
-                        return ((size_t) -1);
+               else
+                       return ((size_t) -1);
 
-                len++;
-        }
+               len++;
+       }
 
-        return (len);
+       return (len);
 }
-