source: branches/version-2_5-dev/data/module/Compat/Compat/Function/convert_uudecode.php @ 20764

Revision 20764, 2.9 KB checked in by nanasess, 13 years ago (diff)

#601 (コピーライトの更新)

  • Property svn:eol-style set to LF
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2// +----------------------------------------------------------------------+
3// | PHP Version 4                                                        |
4// +----------------------------------------------------------------------+
5// | Copyright (c) 1997-2004 The PHP Group                                |
6// +----------------------------------------------------------------------+
7// | This source file is subject to version 3.0 of the PHP license,       |
8// | that is bundled with this package in the file LICENSE, and is        |
9// | available at through the world-wide-web at                           |
10// | http://www.php.net/license/3_0.txt.                                  |
11// | If you did not receive a copy of the PHP license and are unable to   |
12// | obtain it through the world-wide-web, please send a note to          |
13// | license@php.net so we can mail you a copy immediately.               |
14// +----------------------------------------------------------------------+
15// | Authors: Michael Wallner <mike@php.net>                              |
16// |          Aidan Lister <aidan@php.net>                                |
17// +----------------------------------------------------------------------+
18//
19// $Id: convert_uudecode.php,v 1.8 2005/01/26 04:55:13 aidan Exp $
20
21
22/**
23 * Replace convert_uudecode()
24 *
25 * @category    PHP
26 * @package     PHP_Compat
27 * @link        http://php.net/function.convert_uudecode
28 * @author      Michael Wallner <mike@php.net>
29 * @author      Aidan Lister <aidan@php.net>
30 * @version     $Revision: 1.8 $
31 * @since       PHP 5
32 * @require     PHP 4.0.0 (user_error)
33 */
34if (!function_exists('convert_uudecode')) {
35    function convert_uudecode($string)
36    {
37        // Sanity check
38        if (!is_scalar($string)) {
39            user_error('convert_uuencode() expects parameter 1 to be string, ' .
40                gettype($string) . ' given', E_USER_WARNING);
41            return false;
42        }
43
44        if (strlen($string) < 8) {
45            user_error('convert_uuencode() The given parameter is not a valid uuencoded string', E_USER_WARNING);
46            return false;
47        }
48
49        $decoded = '';
50        foreach (explode("\n", $string) as $line) {
51
52            $c = count($bytes = unpack('c*', substr(trim($line), 1)));
53
54            while ($c % 4) {
55                $bytes[++$c] = 0;
56            }
57
58            foreach (array_chunk($bytes, 4) as $b) {
59                $b0 = $b[0] == 0x60 ? 0 : $b[0] - 0x20;
60                $b1 = $b[1] == 0x60 ? 0 : $b[1] - 0x20;
61                $b2 = $b[2] == 0x60 ? 0 : $b[2] - 0x20;
62                $b3 = $b[3] == 0x60 ? 0 : $b[3] - 0x20;
63               
64                $b0 <<= 2;
65                $b0 |= ($b1 >> 4) & 0x03;
66                $b1 <<= 4;
67                $b1 |= ($b2 >> 2) & 0x0F;
68                $b2 <<= 6;
69                $b2 |= $b3 & 0x3F;
70               
71                $decoded .= pack('c*', $b0, $b1, $b2);
72            }
73        }
74
75        return rtrim($decoded, "\0");
76    }
77}
78
79?>
Note: See TracBrowser for help on using the repository browser.