]> granicus.if.org Git - php/commitdiff
Moved php_quot_print_decode() to quot_print.c so that it can be used
authorMoriyoshi Koizumi <moriyoshi@php.net>
Mon, 6 Jan 2003 15:47:25 +0000 (15:47 +0000)
committerMoriyoshi Koizumi <moriyoshi@php.net>
Mon, 6 Jan 2003 15:47:25 +0000 (15:47 +0000)
outside the iconv module

ext/iconv/iconv.c
ext/standard/quot_print.c
ext/standard/quot_print.h

index acb1347a5f0858fd937f5372f810598101ceeb47..0e55a2ac3ca4b4463e9d3f9e8a18b8624983d11b 100644 (file)
@@ -52,6 +52,7 @@
 
 #include "ext/standard/php_smart_str.h"
 #include "ext/standard/base64.h"
+#include "ext/standard/quot_print.h"
 
 #ifdef HAVE_LIBICONV
 #define LIBICONV_PLUG
@@ -230,75 +231,6 @@ PHP_MINFO_FUNCTION(miconv)
 }
 /* }}} */
 
-unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, size_t *ret_length)
-{
-       register unsigned int i;
-       register unsigned const char *p1;
-       register unsigned char *p2;
-       register unsigned int h_nbl, l_nbl;
-
-       size_t decoded_len;
-       unsigned char *retval;
-
-       static unsigned int hexval_tbl[256] = {
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-                0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 16, 16, 16, 16, 16, 16,
-               16, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
-       };
-
-       i = length, p1 = str; decoded_len = length;
-
-       while (i > 0 && *p1 != '\0') {
-               if (*p1 == '=') {
-                       decoded_len -= 2;
-                       p1 += 2;
-                       i -= 2;
-               }
-               p1++;
-               i--;
-       }
-
-       retval = emalloc(decoded_len + 1);
-       i = length; p1 = str; p2 = retval;
-
-       while (i > 0 && *p1 != '\0') {
-               if (*p1 == '=') {
-                       if (i < 2 ||
-                               (h_nbl = hexval_tbl[p1[1]]) > 15 ||
-                               (l_nbl = hexval_tbl[p1[2]]) > 15) { 
-
-                               efree(retval);
-                               return NULL;
-                       }
-
-                       *(p2++) = (h_nbl << 4) | l_nbl;
-                       i -= 3;
-                       p1 += 3;
-               } else {
-                       *(p2++) = *p1;
-                       i--;
-                       p1++;
-               }
-       }
-
-       *p2 = '\0';
-       *ret_length = decoded_len;
-       return retval;
-}
-
 /* {{{ _php_iconv_appendl() */
 static php_iconv_err_t _php_iconv_appendl(smart_str *d, const char *s, size_t l, iconv_t cd)
 {
index c57cf1fb48bde1644b3b452f49059f9041ca5af2..b60bc517d0facf5bcd427b24f1b3b9def7ff34ad 100644 (file)
@@ -50,6 +50,76 @@ static char php_hex2int(int c)
        }
 }
 
+PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, size_t *ret_length)
+{
+       register unsigned int i;
+       register unsigned const char *p1;
+       register unsigned char *p2;
+       register unsigned int h_nbl, l_nbl;
+
+       size_t decoded_len;
+       unsigned char *retval;
+
+       static unsigned int hexval_tbl[256] = {
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+                0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 16, 16, 16, 16, 16, 16,
+               16, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+               16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16
+       };
+
+       i = length, p1 = str; decoded_len = length;
+
+       while (i > 0 && *p1 != '\0') {
+               if (*p1 == '=') {
+                       decoded_len -= 2;
+                       p1 += 2;
+                       i -= 2;
+               }
+               p1++;
+               i--;
+       }
+
+       retval = emalloc(decoded_len + 1);
+       i = length; p1 = str; p2 = retval;
+
+       while (i > 0 && *p1 != '\0') {
+               if (*p1 == '=') {
+                       if (i < 2 ||
+                               (h_nbl = hexval_tbl[p1[1]]) > 15 ||
+                               (l_nbl = hexval_tbl[p1[2]]) > 15) { 
+
+                               efree(retval);
+                               return NULL;
+                       }
+
+                       *(p2++) = (h_nbl << 4) | l_nbl;
+                       i -= 3;
+                       p1 += 3;
+               } else {
+                       *(p2++) = *p1;
+                       i--;
+                       p1++;
+               }
+       }
+
+       *p2 = '\0';
+       *ret_length = decoded_len;
+       return retval;
+}
+
+
 /*
 *
 * Decoding  Quoted-printable string.
index d7a0087743fb65e191b0984d66804696e551b7ab..9ca350c6a2e9c4b41a2bf9edebf7cad5ee4a1703 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef QUOT_PRINT_H
 #define QUOT_PRINT_H
 
+PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, size_t *ret_length);
+
 PHP_FUNCTION(quoted_printable_decode);
 
 #endif /* QUOT_PRINT_H */