tony2001                Thu Aug 14 10:11:26 2008 UTC

  Added files:                 
    /php-src/ext/standard/tests/strings 
                                        quoted_printable_encode_001.phpt 
                                        quoted_printable_encode_002.phpt 

  Modified files:              
    /php-src/ext/standard       basic_functions.c quot_print.c quot_print.h 
  Log:
  [DOC] add quoted_printable_encode()
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.916&r2=1.917&diff_format=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.916 
php-src/ext/standard/basic_functions.c:1.917
--- php-src/ext/standard/basic_functions.c:1.916        Thu Aug 14 09:41:47 2008
+++ php-src/ext/standard/basic_functions.c      Thu Aug 14 10:11:26 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.916 2008/08/14 09:41:47 tony2001 Exp $ */
+/* $Id: basic_functions.c,v 1.917 2008/08/14 10:11:26 tony2001 Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -2195,6 +2195,12 @@
        ZEND_ARG_INFO(0, str)
 ZEND_END_ARG_INFO()
 /* }}} */
+/* {{{ quot_print.c */
+static
+ZEND_BEGIN_ARG_INFO(arginfo_quoted_printable_encode, 0)
+       ZEND_ARG_INFO(0, str)
+ZEND_END_ARG_INFO()
+/* }}} */
 /* {{{ rand.c */
 static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_srand, 0, 0, 0)
@@ -3405,6 +3411,7 @@
 #endif
 
        PHP_FE(quoted_printable_decode,                                         
                                        arginfo_quoted_printable_decode)
+       PHP_FE(quoted_printable_encode,                                         
                                        arginfo_quoted_printable_encode)
        PHP_FE(convert_cyr_string,                                              
                                                arginfo_convert_cyr_string)
        PHP_FE(get_current_user,                                                
                                                arginfo_get_current_user)
        PHP_FE(set_time_limit,                                                  
                                                arginfo_set_time_limit)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/quot_print.c?r1=1.35&r2=1.36&diff_format=u
Index: php-src/ext/standard/quot_print.c
diff -u php-src/ext/standard/quot_print.c:1.35 
php-src/ext/standard/quot_print.c:1.36
--- php-src/ext/standard/quot_print.c:1.35      Mon Dec 31 07:12:16 2007
+++ php-src/ext/standard/quot_print.c   Thu Aug 14 10:11:26 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: quot_print.c,v 1.35 2007/12/31 07:12:16 sebastian Exp $ */
+/* $Id: quot_print.c,v 1.36 2008/08/14 10:11:26 tony2001 Exp $ */
 
 #include <stdlib.h>
 
@@ -143,6 +143,53 @@
 }
 /* }}} */
 
+#define PHP_QPRINT_MAXL 75
+ 
+PHPAPI unsigned char *php_quot_print_encode(const unsigned char *str, size_t 
length, size_t *ret_length) /* {{{ */
+{
+       unsigned long lp = 0;
+       unsigned char c, *ret, *d;
+       char *hex = "0123456789ABCDEF";
+
+       ret = safe_emalloc(1, 3 * length + 3 * (((3 * length)/PHP_QPRINT_MAXL) 
+ 1), 0);
+       d = ret;
+
+       while (length--) {
+               if (((c = *str++) == '\015') && (*str == '\012') && length > 0) 
{
+                       *d++ = '\015';
+                       *d++ = *str++;
+                       length--;
+                       lp = 0;
+               } else {
+                       if (iscntrl (c) || (c == 0x7f) || (c & 0x80) || (c == 
'=') || ((c == ' ') && (*str == '\015'))) {
+                               if ((lp += 3) > PHP_QPRINT_MAXL) {
+                                       *d++ = '=';
+                                       *d++ = '\015';
+                                       *d++ = '\012';
+                                       lp = 3;
+                               }
+                               *d++ = '=';
+                               *d++ = hex[c >> 4];
+                               *d++ = hex[c & 0xf];
+                       } else {
+                               if ((++lp) > PHP_QPRINT_MAXL) {
+                                       *d++ = '=';
+                                       *d++ = '\015';
+                                       *d++ = '\012';
+                                       lp = 1;
+                               }
+                               *d++ = c;
+                       }
+               }
+       }
+       *d = '\0';
+       *ret_length = d - ret;
+
+       ret = erealloc(ret, *ret_length + 1);
+       return ret;
+}
+/* }}} */
+
 /*
 *
 * Decoding  Quoted-printable string.
@@ -209,6 +256,26 @@
 }
 /* }}} */
 
+/* {{{ proto string quoted_printable_encode(string str) U */
+PHP_FUNCTION(quoted_printable_encode)
+{
+       char *str, *new_str;
+       int str_len;
+       size_t new_str_len;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, 
&str_len) != SUCCESS) {
+               return;
+       }
+
+       if (!str_len) {
+               RETURN_EMPTY_STRING();
+       }
+
+       new_str = (char *)php_quot_print_encode((unsigned char *)str, 
(size_t)str_len, &new_str_len);
+       RETURN_STRINGL(new_str, new_str_len, 0);
+}
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/quot_print.h?r1=1.16&r2=1.17&diff_format=u
Index: php-src/ext/standard/quot_print.h
diff -u php-src/ext/standard/quot_print.h:1.16 
php-src/ext/standard/quot_print.h:1.17
--- php-src/ext/standard/quot_print.h:1.16      Mon Dec 31 07:12:16 2007
+++ php-src/ext/standard/quot_print.h   Thu Aug 14 10:11:26 2008
@@ -16,13 +16,15 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: quot_print.h,v 1.16 2007/12/31 07:12:16 sebastian Exp $ */
+/* $Id: quot_print.h,v 1.17 2008/08/14 10:11:26 tony2001 Exp $ */
 
 #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, int replace_us_by_ws);
+PHPAPI unsigned char *php_quot_print_encode(const unsigned char *str, size_t 
length, size_t *ret_length);
 
 PHP_FUNCTION(quoted_printable_decode);
+PHP_FUNCTION(quoted_printable_encode);
 
 #endif /* QUOT_PRINT_H */

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/quoted_printable_encode_001.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/strings/quoted_printable_encode_001.phpt
+++ php-src/ext/standard/tests/strings/quoted_printable_encode_001.phpt
--TEST--
quoted_printable_encode() tests - 1
--FILE--
<?php

var_dump(quoted_printable_encode());
var_dump(quoted_printable_encode(""));
var_dump(quoted_printable_encode("test"));
var_dump(quoted_printable_encode("test", "more"));

$a = array("str");
var_dump(quoted_printable_encode($a));
var_dump(quoted_printable_encode(1));
var_dump(quoted_printable_encode(NULL));
var_dump(quoted_printable_encode(false));

echo "Done\n";
?>
--EXPECTF--     
Warning: quoted_printable_encode() expects exactly 1 parameter, 0 given in %s 
on line %d
NULL
string(0) ""
string(4) "test"

Warning: quoted_printable_encode() expects exactly 1 parameter, 2 given in %s 
on line %d
NULL

Warning: quoted_printable_encode() expects parameter 1 to be binary string, 
array given in %s on line %d
NULL
string(1) "1"
string(0) ""
string(0) ""
Done

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/quoted_printable_encode_002.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/strings/quoted_printable_encode_002.phpt
+++ php-src/ext/standard/tests/strings/quoted_printable_encode_002.phpt
--TEST--
quoted_printable_encode() tests - 2
--INI--
unicode.runtime_encoding = utf-8
unicode.script_encoding = utf-8
unicode.output_encoding = utf-8
--FILE--
<?php

$s = str_repeat("\0", 200);
var_dump($d = quoted_printable_encode($s));
var_dump(quoted_printable_decode($d));

$s = str_repeat("строка в юникоде", 50);
var_dump($d = quoted_printable_encode($s));
var_dump(quoted_printable_decode($d));

class foo {
        function __toString() {
                return "this is a foo";
        }
}

$o = new Foo;
var_dump(quoted_printable_encode($o));

echo "Done\n";
?>
--EXPECTF--     
string(621) 
"=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=
=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=
=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=
=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=
=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=
=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=
=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=
=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00"
string(200) "
string(4474) "=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 
=D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=
=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=
=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=
=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =
=D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=
=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=
=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=
=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=
=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=
=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=
=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =
=D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B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4=D0=B5=D1=81=D1=82=D1=80=D0=BE=
=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=
=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=
=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=
=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=
=D0=BA=D0=BE=D0=B4=D0=B5"
string(1500) "строка в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в!
  юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникодестрока в 
юникодестрока в юникоде"
string(13) "this is a foo"
Done

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to