コード例 #1
0
 function __construct($inputCharsetCode, $outputCharsetCode, $realInputCharsetCode, $realOutputCharsetCode, $inputEncoding, $outputEncoding)
 {
     $this->RequestedInputCharsetCode = $inputCharsetCode;
     $this->RequestedOutputCharsetCode = $outputCharsetCode;
     $this->InputCharsetCode = $realInputCharsetCode;
     $this->OutputCharsetCode = $realOutputCharsetCode;
     $this->InputCharacterEncodingScheme = $inputEncoding;
     $this->OutputCharacterEncodingScheme = $outputEncoding;
     $useMBStringExtension = true;
     if (isset($GLOBALS['eZTextCodecMBStringExtension'])) {
         $useMBStringExtension = $GLOBALS['eZTextCodecMBStringExtension'];
     }
     // NOTE:
     // The method eZMBStringMapper::hasMBStringExtension() has been copied and inlined here
     // Any modification must be reflected in the method
     $hasMBString = (function_exists("mb_convert_encoding") and function_exists("mb_substitute_character") and function_exists("mb_strcut") and function_exists("mb_strlen") and function_exists("mb_strpos") and function_exists("mb_strrpos") and function_exists("mb_strwidth") and function_exists("mb_substr"));
     $useMBString = ($useMBStringExtension and eZTextCodec::useMBString() and $hasMBString);
     // Map for conversion functions using encoding functions
     $encodingConvertMap = array();
     $encodingConvertInitMap = array();
     $encodingStrlenMap = array();
     $encodingStrlenMap['unicode'] = 'strlenUnicode';
     $encodingStrlenMap['utf-8'] = 'strlenUTF8';
     $encodingStrlenMap['singlebyte'] = 'strlenCodepage';
     $encodingStrlenMap['doublebyte'] = 'strlenCodepage';
     // Unicode -> other
     $encodingConvertMap['unicode']['unicode'] = 'convertNone';
     $encodingConvertMap['unicode']['utf-8'] = 'convertUnicodeToUTF8';
     $encodingConvertMap['unicode']['singlebyte'] = 'convertUnicodeToCodepage';
     $encodingConvertMap['unicode']['doublebyte'] = 'convertUnicodeToCodepage';
     $encodingConvertInitMap['unicode']['singlebyte'] = 'initializeOutputCodepage';
     $encodingConvertInitMap['unicode']['doublebyte'] = 'initializeOutputCodepage';
     // UTF8 -> other
     $encodingConvertMap['utf-8']['unicode'] = 'convertUTF8ToUnicode';
     $encodingConvertMap['utf-8']['utf-8'] = 'convertNone';
     $encodingConvertMap['utf-8']['singlebyte'] = 'convertCodepageRev';
     $encodingConvertMap['utf-8']['doublebyte'] = 'convertCodepageRev';
     $encodingConvertInitMap['utf-8']['singlebyte'] = 'initializeOutputCodepage';
     $encodingConvertInitMap['utf-8']['doublebyte'] = 'initializeOutputCodepage';
     // singlebyte -> other
     $encodingConvertMap['singlebyte']['unicode'] = 'convertCodepageToUnicode';
     $encodingConvertMap['singlebyte']['utf-8'] = 'convertCodepage';
     $encodingConvertMap['singlebyte']['singlebyte'] = 'convertCodepageMapper';
     $encodingConvertMap['singlebyte']['doublebyte'] = 'convertCodepageMapper';
     $encodingConvertInitMap['singlebyte']['unicode'] = 'initializeInputCodepage';
     $encodingConvertInitMap['singlebyte']['utf-8'] = 'initializeInputCodepage';
     $encodingConvertInitMap['singlebyte']['singlebyte'] = 'initializeCodepageMapper';
     $encodingConvertInitMap['singlebyte']['doublebyte'] = 'initializeCodepageMapper';
     // doublebyte -> other
     $encodingConvertMap['doublebyte']['unicode'] = 'convertCodepageToUnicode';
     $encodingConvertMap['doublebyte']['utf-8'] = 'convertCodepage';
     $encodingConvertMap['doublebyte']['singlebyte'] = 'convertCodepageMapper';
     $encodingConvertMap['doublebyte']['doublebyte'] = 'convertCodepageMapper';
     $encodingConvertInitMap['doublebyte']['unicode'] = 'initializeInputCodepage';
     $encodingConvertInitMap['doublebyte']['utf-8'] = 'initializeInputCodepage';
     $encodingConvertInitMap['doublebyte']['singlebyte'] = 'initializeCodepageMapper';
     $encodingConvertInitMap['doublebyte']['doublebyte'] = 'convertCodepageMapper';
     $noneConversionFunction = 'convertNone';
     $noneStrlenFunction = 'strlenNone';
     $conversionFunction = null;
     $strlenFunction = null;
     $encodingConvertInitFunction = null;
     // NOTE:
     // The method eZMBStringMapper::charsetList() hash been copied and inlined here
     // Any modification must be reflected in the method
     $mbStringCharsets =& $GLOBALS["eZMBCharsetList"];
     if ($useMBString and !is_array($mbStringCharsets)) {
         $charsetList = array("ucs-4", "ucs-4be", "ucs-4le", "ucs-2", "ucs-2be", "ucs-2le", "utf-32", "utf-32be", "utf-32le", "utf-16", "utf-16be", "utf-16le", "utf-8", "utf-7", "ascii", "euc-jp", "sjis", "eucjp-win", "sjis-win", "iso-2022-jp", "jis", "iso-8859-1", "iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8", "iso-8859-9", "iso-8859-10", "iso-8859-13", "iso-8859-14", "iso-8859-15", "byte2be", "byte2le", "byte4be", "byte4le", "base64", "7bit", "8bit", "utf7-imap");
         $mbStringCharsets = array();
         foreach ($charsetList as $charset) {
             $mbStringCharsets[$charset] = $charset;
         }
     }
     // Is to true if the charsets are the same and they have singlebyte encoding
     $isSinglebyteSame = false;
     $isSame = false;
     // First detect conversion type
     if ($this->InputCharsetCode == $this->OutputCharsetCode) {
         $conversionFunction = $noneConversionFunction;
         $encodingConvertInitFunction = 'initializeInputCodepage';
         $inpenc = $this->InputCharacterEncodingScheme;
         if ($inpenc == 'singlebyte') {
             $isSinglebyteSame = true;
         }
         $isSame = true;
     } else {
         if ($useMBString and isset($mbStringCharsets[$this->InputCharsetCode]) and isset($mbStringCharsets[$this->OutputCharsetCode])) {
             // NOTE:
             // The mbstringmapper object is no longer needed since all functionality is inlined
             //             $this->MBStringMapper = eZMBStringMapper::instance( $this->InputCharsetCode,
             //                                                                 $this->OutputCharsetCode );
             $conversionFunction = "convertMBString";
             $strlenFunction = "strlenMBString";
             $encodingConvertInitFunction = false;
         } else {
             $inpenc = $this->InputCharacterEncodingScheme;
             $outenc = $this->OutputCharacterEncodingScheme;
             if (isset($encodingConvertMap[$inpenc][$outenc])) {
                 $conversionFunction = $encodingConvertMap[$inpenc][$outenc];
             }
         }
     }
     if ($strlenFunction === null) {
         $inpenc = $this->InputCharacterEncodingScheme;
         if ($isSinglebyteSame) {
             $strlenFunction = 'strlenNone';
         } else {
             if ($useMBString and isset($mbStringCharsets[$this->InputCharsetCode])) {
                 $strlenFunction = 'strlenMBString';
             } else {
                 if (isset($encodingStrlenMap[$inpenc])) {
                     $strlenFunction = $encodingStrlenMap[$inpenc];
                     if ($inpenc == 'utf-8') {
                     }
                 }
             }
         }
     }
     if (!$isSame and $conversionFunction and $strlenFunction) {
         $this->initializeConversionFunction($encodingConvertInitMap, $encodingConvertInitFunction);
     }
     if (!$conversionFunction or !$strlenFunction) {
         eZDebug::writeError("Cannot create textcodec from characterset " . $this->RequestedInputCharsetCode . " to characterset " . $this->RequestedOutputCharsetCode, "eZTextCodec");
         if (!$conversionFunction) {
             $conversionFunction = $noneConversionFunction;
         }
         if (!$strlenFunction) {
             $strlenFunction = $noneStrlenFunction;
         }
     }
     $this->ConversionFunction = $conversionFunction;
     $this->StrlenFunction = $strlenFunction;
     $this->RequireConversion = $conversionFunction != $noneConversionFunction;
 }