eZ Publish  [4.0]
ezcodepagecodec.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZCodePageCodec class
00004 //
00005 // Created on: <07-Mar-2002 10:19:23 amos>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*!
00032   \class eZCodePageCodec ezcodepagecodec.php
00033   \ingroup eZI18N
00034   \brief The class eZCodePageCodec does
00035 
00036 */
00037 
00038 //include_once( "lib/ezi18n/classes/eztextcodec.php" );
00039 //include_once( "lib/ezi18n/classes/ezutf8codec.php" );
00040 
00041 class eZCodePageCodec extends eZTextCodec
00042 {
00043     /*!
00044      Initializes the codepage codec with $name
00045     */
00046     function eZCodePageCodec( $name )
00047     {
00048         $this->eZTextCodec( $name );
00049         $this->CodePage = false;
00050     }
00051 
00052     function toUnicode( $str )
00053     {
00054         $ustr = "";
00055         if ( !is_string( $str ) or
00056              !$this->isValid() )
00057             return $ustr;
00058         $len = strlen( $str );
00059         for ( $i = 0; $i < $len; ++$i )
00060         {
00061 //             $char_code = $this->CodePage->
00062 //             $ustr .= $this->toUtf8( $char_code );
00063             $char = $str[$i];
00064             $ustr .= $this->CodePage->charToUtf8( $char );
00065         }
00066         return $ustr;
00067     }
00068 
00069     function fromUnicode( $str )
00070     {
00071         $ustr = "";
00072         if ( !is_string( $str ) or
00073              !$this->isValid() )
00074             return $ustr;
00075         $utf8_codec = eZUTF8Codec::instance();
00076         $len = strlen( $str );
00077         for ( $i = 0; $i < $len; )
00078         {
00079             $char_code = $utf8_codec->fromUtf8( $str, $i, $l );
00080             if ( $char_code !== false )
00081             {
00082                 $i += $l;
00083                 $ustr .= chr( $this->CodePage->unicodeToChar( $char_code ) );
00084             }
00085             else
00086                 ++$i;
00087         }
00088         return $ustr;
00089     }
00090 
00091     /*!
00092      Returns true if a codepage has been set.
00093     */
00094     function isValid()
00095     {
00096         return $this->CodePage instanceof eZCodePage;
00097     }
00098 
00099     /*!
00100      Returns the codepage.
00101     */
00102     function codePage()
00103     {
00104         return $this->CodePage;
00105     }
00106 
00107     /*!
00108      Sets the current codepage which is used for utf8/text translation.
00109     */
00110     function setCodePage( $cp )
00111     {
00112         $this->CodePage = $cp;
00113     }
00114 
00115     public $CodePage;
00116 }
00117 
00118 ?>