[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZMBStringMapper class 4 // 5 // Created on: <12-Jul-2002 12:56:48 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezmbstringmapper.php 30 */ 31 32 /*! 33 \class eZMBStringMapper ezmbstringmapper.php 34 \ingroup eZI18N 35 \brief The class eZMBStringMapper does 36 37 The mbstring extension supports the following charset: 38 UCS-4, UCS-4BE, UCS-4LE, UCS-2, UCS-2BE, UCS-2LE, UTF-32, UTF-32BE, UTF-32LE, UCS-2LE, UTF-16, 39 UTF-16BE, UTF-16LE, UTF-8, UTF-7, ASCII, EUC-JP, SJIS, eucJP-win, SJIS-win, ISO-2022-JP, JIS, 40 ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, 41 ISO-8859-9, ISO-8859-10, ISO-8859-13, ISO-8859-14, ISO-8859-15, byte2be, byte2le, byte4be, 42 byte4le, BASE64, 7bit, 8bit and UTF7-IMAP. 43 */ 44 45 include_once ( "lib/ezi18n/classes/ezcharsetinfo.php" ); 46 47 class eZMBStringMapper 48 { 49 /*! 50 Constructor 51 */ 52 function eZMBStringMapper( $input_charset_code, $output_charset_code ) 53 { 54 $this->RequestedInputCharsetCode = $input_charset_code; 55 $this->InputCharsetCode = eZCharsetInfo::realCharsetCode( $input_charset_code ); 56 $this->RequestedOutputCharsetCode = $output_charset_code; 57 $this->OutputCharsetCode = eZCharsetInfo::realCharsetCode( $output_charset_code ); 58 $this->Valid = false; 59 if ( !$this->isCharsetSupported( $input_charset_code ) ) 60 { 61 eZDebug::writeError( "Input charset $input_charset_code not supported", "eZMBStringMapper" ); 62 } 63 else if ( !$this->isCharsetSupported( $output_charset_code ) ) 64 { 65 eZDebug::writeError( "Output charset $output_charset_code not supported", "eZMBStringMapper" ); 66 } 67 else if ( $this->hasMBStringExtension() ) 68 $this->Valid = true; 69 else 70 eZDebug::writeError( "No mbstring functions available", "eZMBStringMapper" ); 71 } 72 73 /*! 74 \static 75 \note This function is duplicated in eZTextCodec::eZTextCodec(), remember to update both places. 76 */ 77 function &charsetList() 78 { 79 $charsets =& $GLOBALS["eZMBCharsetList"]; 80 if ( !is_array( $charsets ) ) 81 { 82 $charsetList = array( "ucs-4", "ucs-4be", "ucs-4le", "ucs-2", "ucs-2be", "ucs-2le", "utf-32", "utf-32be", "utf-32le", "utf-16", 83 "utf-16be", "utf-16le", "utf-8", "utf-7", "ascii", "euc-jp", "sjis", "eucjp-win", "sjis-win", "iso-2022-jp", "jis", 84 "iso-8859-1", "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8", 85 "iso-8859-9", "iso-8859-10", "iso-8859-13", "iso-8859-14", "iso-8859-15", "byte2be", "byte2le", "byte4be", 86 "byte4le", "base64", "7bit", "8bit", "utf7-imap" ); 87 $charsets = array(); 88 foreach ( $charsetList as $charset ) 89 { 90 $charsets[$charset] = $charset; 91 } 92 } 93 return $charsets; 94 } 95 96 /*! 97 \static 98 \return \c true if the mbstring can be used. 99 \note The following function must be present for the function to return \c true. 100 mb_convert_encoding 101 mb_substitute_character 102 mb_strcut 103 mb_strlen 104 mb_strpos 105 mb_strrpos 106 mb_strwidth 107 mb_substr 108 \note This function is duplicated in eZTextCodec::eZTextCodec(), remember to update both places. 109 */ 110 function hasMBStringExtension() 111 { 112 return ( function_exists( "mb_convert_encoding" ) and 113 function_exists( "mb_substitute_character" ) and 114 function_exists( "mb_strcut" ) and 115 function_exists( "mb_strlen" ) and 116 function_exists( "mb_strpos" ) and 117 function_exists( "mb_strrpos" ) and 118 function_exists( "mb_strwidth" ) and 119 function_exists( "mb_substr" ) ); 120 } 121 122 function inputCharsetCode() 123 { 124 return $this->InputCharsetCode; 125 } 126 127 function outputCharsetCode() 128 { 129 return $this->OutputCharsetCode; 130 } 131 132 function requestedInputCharsetCode() 133 { 134 return $this->RequestedInputCharsetCode; 135 } 136 137 function requestedOutputCharsetCode() 138 { 139 return $this->RequestedOutputCharsetCode; 140 } 141 142 function isCharsetSupported( $charset_code ) 143 { 144 $charset_code = eZCharsetInfo::realCharsetCode( $charset_code ); 145 return in_array( $charset_code, eZMBStringMapper::charsetList() ); 146 } 147 148 function substituteCharacter() 149 { 150 if ( !$this->Valid ) 151 return null; 152 return mb_substitute_character(); 153 } 154 155 function setSubstituteCharacter( $char ) 156 { 157 if ( $this->Valid ) 158 mb_substitute_character( $char ); 159 } 160 161 function convertString( $str ) 162 { 163 if ( !$this->Valid ) 164 return $str; 165 return mb_convert_encoding( $str, $this->OutputCharsetCode, $this->InputCharsetCode ); 166 } 167 168 function strlen( $str ) 169 { 170 return mb_strlen( $str, $this->InputCharsetCode ); 171 } 172 173 function strpos( $haystack, $needle, $offset = 0 ) 174 { 175 return mb_strpos( $haystack, $needle, $offset, $this->InputCharsetCode ); 176 } 177 178 function strrpos( $haystack, $needle ) 179 { 180 return mb_strrpos( $haystack, $needle, $this->InputCharsetCode ); 181 } 182 183 function substr( $str, $start, $length ) 184 { 185 return mb_substr( $str, $start, $length, $this->InputCharsetCode ); 186 } 187 188 function instance( $input_charset_code, $output_charset_code ) 189 { 190 $mb =& $GLOBALS["eZMBStringMapper-$input_charset_code-$output_charset_code"]; 191 if ( get_class( $mb ) != "ezmbstringmapper" ) 192 { 193 $mb = new eZMBStringMapper( $input_charset_code, $output_charset_code ); 194 } 195 return $mb; 196 } 197 } 198 199 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |