00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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
00062
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
00093
00094 function isValid()
00095 {
00096 return get_class( $this->CodePage ) == "ezcodepage";
00097 }
00098
00099
00100
00101
00102 function &codePage()
00103 {
00104 return $this->CodePage;
00105 }
00106
00107
00108
00109
00110 function setCodePage( &$cp )
00111 {
00112 $this->CodePage =& $cp;
00113 }
00114
00115 var $CodePage;
00116 }
00117
00118 ?>