Path

ez.no / exponential / documentation / development / libraries / ez i18n / codepage mapping


Codepage mapping

These documentation pages are no longer maintained. Please visit the new documentation site.

Mapping from one codepage to another can be done using the eZCodePageMapper class, it provides instantaneous mapping from one character code in one charset to the code in the other charset.

This table can be produced by the following code. Table 1 shows the charset to map from, table 2 shows the charset to map to and table 3 shows the characters that could be mapped.

function displayCharsetTable( $values,

                             
$x_start, $x_stop,

                             
$y_start, $y_stop )

{

   print( "<table>\n<tr><td></td>" );

   for ( $x = $x_start; $x < $x_stop; ++$x )

       print( "<td>$x</td>" );

   print( "</tr>\n" );

   for ( $y = $y_start; $y < $y_stop; ++$y )

   {

       print( "<tr><td>$y</td>" );

       for ( $x = $x_start; $x < $x_stop; ++$x )

       {

           if ( isset( $values[$x][$y] ) )

           {

               $value = $values[$x][$y];

               
$char_utf8 = htmlspecialchars( $value[0] );

               $char_code = $value[1];

               print( "<td>
$char_utf8</td>" );

           }

           else

               print( "<td></td>" );

       }

       print( "</tr>\n" );

   }

   print( "</table>\n" );

}

 

function generateCharsetTable( &$values, &$codepage,

                              
$x_start, $x_stop,

                              
$y_start, $y_stop )

{

   $values = array();

   for ( $y = $y_start; $y < $y_stop; ++$y )

   {

       for ( $x = $x_start; $x < $x_stop; ++$x )

       {

           $code = ($y*$y_stop) + $x;

           $utf8 = $codepage->codeToUtf8( $code );

           $values[$x][$y] = array( $utf8, $code );

       }

   }

}

 

header( "Content-Type: text/html; charset=utf8" );

 

include_once( "lib/ezi18n/classes/ezcodepagemapper.php" );

include_once( "lib/ezutils/classes/ezhttptool.php" );

 

$input_charset = "cyrillic";

$output_charset = "wincyrillic";

 

$http =& eZHTTPTool::instance();

if ( $http->hasPostVariable( "ChangeCharset" ) )

{

   if ( $http->hasPostVariable( "InputCharset" ) )

   {

       $input_charset = $http->postVariable( "InputCharset" );

   }

   if ( $http->hasPostVariable( "OutputCharset" ) )

   {

       $output_charset = $http->postVariable( "OutputCharset" );

   }

}

 

$input_codepage =& eZCodePage::instance( $input_charset );

$output_codepage =& eZCodePage::instance( $output_charset );

$codepage_mapper =& eZCodePageMapper::instance( $input_charset, $output_charset );

 

print( "

<form action=\"\" method=\"post\" name=\"CodepageMapping\">

<p>

Table <b>1</b> shows the charset to map from, table <b>2</b> shows the charset to map to

and table <b>3</b> shows the characters that could be mapped.

</p>

 

<p class=\"footnote\">

This page uses utf8 output to allow displaying two different charsets at the same time,

you might not see all characters depending on your font support.

</p>

" );

 

generateCharsetTable( $input_values, $input_codepage,

                     0,
 16,

                     0,
 16 );

generateCharsetTable( $output_values, $output_codepage,

                     0,
 16,

                     0,
 16 );

 

$mapped_values = array();

for ( $y = 0; $y < 16; ++$y )

{

   for ( $x = 0; $x < 16; ++$x )

   {

       $input_code = ($y*16) + $x;

       $output_code = $codepage_mapper->mapInputCode( $input_code );

       $output_utf8 = $output_codepage->codeToUtf8( $output_code );

       $output_x = ( $output_code % 16 );

       $output_y = ( $output_code / 16 );

       $mapped_values[$output_x][$output_y] = array( $output_utf8, $input_code );

   }

}

 

$charset_list = eZCodePage::codepageList();

 

print( "<table width=\"100%\">

<tr><td>

<select name=\"InputCharset\">" );

foreach( $charset_list as $charset )

{

   print( "<option 
value=\"$charset\" " . ( $input_codepage->charsetCode() == $charset ?
 "selected=\"selected\"" : "" ) . ">$charset</option>" );

}

print( "</select>

</td><td>

<select name=\"OutputCharset\">" );

foreach( $charset_list as $charset )

{

   print( "<option 
value=\"$charset\" " . ( $output_codepage->charsetCode() == $charset ?
 "selected=\"selected\"" : "" ) . ">$charset</option>" );

}

print( "</select>

 

</td><td>

<input class=\"stdbutton\" type=\"submit\" Name=\"ChangeCharset\" value=\"Change charset\">

</td></tr>

<tr><td>" );

print( "<h2>1. " . $input_codepage->charsetCode() );

if ( $input_codepage->charsetCode() != $input_codepage->requestedCharsetCode() )

   print( "(" . $input_codepage->requestedCharsetCode() . ")" );

print( "</h2>" );

displayCharsetTable( $input_values,

                    0, 16,

                    0, 16 );

print( "</td><td>" );

print( "<h2>2. " . $output_codepage->charsetCode() );

if ( $output_codepage->charsetCode() != $output_codepage->requestedCharsetCode() )

   print( "(" . $output_codepage->requestedCharsetCode() . ")" );

print( "</h2>" );

displayCharsetTable( $output_values,

                    0, 16,

                    0, 16 );

print( "</td>" );

print( "<td colspan=\"2\">" );

print( "<h2>3. " . $input_codepage->charsetCode() . " => " . $output_codepage->charsetCode() . "</h2>" );

displayCharsetTable( $mapped_values,

                    0, 16,

                    0, 16 );

print( "</td></tr>" );

print( "</table>" );

print( "</form>" );

Comments

log in or create a user account to comment.

Contents

Development

Extensions
Exponential datamodel
Exponential tuning and stability
Importing attribute data
Kernel
Libraries
    eZ xml
    eZ db
    eZ i18n
       Character encoding
       Codepage mapping
    eZ soap
    eZ template
    eZ webdav
Scripting
Standards
System overview
Test Suite
Using Doxygen to create API documenta...


Created

04/07/2003
10:43:57 am
by Bård Farstad

Last updated

04/07/2003
10:43:57 am
by Bård Farstad

Authors

Bård Farstad



This page is part of the Exponential documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.