web/Zend/Text/Table/Decorator/Unicode.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category  Zend
       
    16  * @package   Zend_Text_Table
       
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license   http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version   $Id: Unicode.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    20  */
       
    21 
       
    22 /**
       
    23  * @see Zend_Text_Table_Decorator_Interface
       
    24  */
       
    25 require_once 'Zend/Text/Table/Decorator/Interface.php';
       
    26 
       
    27 /**
       
    28  * Unicode Decorator for Zend_Text_Table
       
    29  *
       
    30  * @category  Zend
       
    31  * @package   Zend_Text_Table
       
    32  * @uses      Zend_Text_Table_Decorator_Interface
       
    33  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    34  * @license   http://framework.zend.com/license/new-bsd     New BSD License
       
    35  */
       
    36 class Zend_Text_Table_Decorator_Unicode implements Zend_Text_Table_Decorator_Interface
       
    37 {
       
    38     /**
       
    39      * Defined by Zend_Text_Table_Decorator_Interface
       
    40      *
       
    41      * @return string
       
    42      */
       
    43     public function getTopLeft()
       
    44     {
       
    45         return $this->_uniChar(0x250C);
       
    46     }
       
    47 
       
    48     /**
       
    49      * Defined by Zend_Text_Table_Decorator_Interface
       
    50      *
       
    51      * @return string
       
    52      */
       
    53     public function getTopRight()
       
    54     {
       
    55         return $this->_uniChar(0x2510);
       
    56     }
       
    57 
       
    58     /**
       
    59      * Defined by Zend_Text_Table_Decorator_Interface
       
    60      *
       
    61      * @return string
       
    62      */
       
    63     public function getBottomLeft()
       
    64     {
       
    65         return $this->_uniChar(0x2514);
       
    66     }
       
    67 
       
    68     /**
       
    69      * Defined by Zend_Text_Table_Decorator_Interface
       
    70      *
       
    71      * @return string
       
    72      */
       
    73     public function getBottomRight()
       
    74     {
       
    75         return $this->_uniChar(0x2518);
       
    76     }
       
    77 
       
    78     /**
       
    79      * Defined by Zend_Text_Table_Decorator_Interface
       
    80      *
       
    81      * @return string
       
    82      */
       
    83     public function getVertical()
       
    84     {
       
    85         return $this->_uniChar(0x2502);
       
    86     }
       
    87 
       
    88     /**
       
    89      * Defined by Zend_Text_Table_Decorator_Interface
       
    90      *
       
    91      * @return string
       
    92      */
       
    93     public function getHorizontal()
       
    94     {
       
    95         return $this->_uniChar(0x2500);
       
    96     }
       
    97 
       
    98     /**
       
    99      * Defined by Zend_Text_Table_Decorator_Interface
       
   100      *
       
   101      * @return string
       
   102      */
       
   103     public function getCross()
       
   104     {
       
   105         return $this->_uniChar(0x253C);
       
   106     }
       
   107 
       
   108     /**
       
   109      * Defined by Zend_Text_Table_Decorator_Interface
       
   110      *
       
   111      * @return string
       
   112      */
       
   113     public function getVerticalRight()
       
   114     {
       
   115         return $this->_uniChar(0x251C);
       
   116     }
       
   117 
       
   118     /**
       
   119      * Defined by Zend_Text_Table_Decorator_Interface
       
   120      *
       
   121      * @return string
       
   122      */
       
   123     public function getVerticalLeft()
       
   124     {
       
   125         return $this->_uniChar(0x2524);
       
   126     }
       
   127 
       
   128     /**
       
   129      * Defined by Zend_Text_Table_Decorator_Interface
       
   130      *
       
   131      * @return string
       
   132      */
       
   133     public function getHorizontalDown()
       
   134     {
       
   135         return $this->_uniChar(0x252C);
       
   136     }
       
   137 
       
   138     /**
       
   139      * Defined by Zend_Text_Table_Decorator_Interface
       
   140      *
       
   141      * @return string
       
   142      */
       
   143     public function getHorizontalUp()
       
   144     {
       
   145         return $this->_uniChar(0x2534);
       
   146     }
       
   147 
       
   148     /**
       
   149      * Convert am unicode character code to a character
       
   150      *
       
   151      * @param  integer $code
       
   152      * @return string|false
       
   153      */
       
   154     protected function _uniChar($code)
       
   155     {
       
   156         if ($code <= 0x7F) {
       
   157             $char = chr($code);
       
   158         } else if ($code <= 0x7FF) {
       
   159             $char = chr(0xC0 | $code >> 6)
       
   160                   . chr(0x80 | $code & 0x3F);
       
   161         } else if ($code <= 0xFFFF) {
       
   162             $char =  chr(0xE0 | $code >> 12)
       
   163                   . chr(0x80 | $code >> 6 & 0x3F)
       
   164                   . chr(0x80 | $code & 0x3F);
       
   165         } else if ($code <= 0x10FFFF) {
       
   166             $char =  chr(0xF0 | $code >> 18)
       
   167                   . chr(0x80 | $code >> 12 & 0x3F)
       
   168                   . chr(0x80 | $code >> 6 & 0x3F)
       
   169                   . chr(0x80 | $code & 0x3F);
       
   170         } else {
       
   171             return false;
       
   172         }
       
   173 
       
   174         return $char;
       
   175     }
       
   176 }