Switch /e preg_replace for callbacks
[lhc/web/wiklou.git] / languages / classes / LanguageEo.php
1 <?php
2
3 /** Esperanto (Esperanto)
4 *
5 * @ingroup Language
6 */
7 class LanguageEo extends Language {
8 function iconv( $in, $out, $string ) {
9 # Por multaj lingvoj, ĉi tiu nur voku la sisteman funkcion iconv()
10 # Ni ankaŭ konvertu X-sistemajn surogotajn
11 if ( strcasecmp( $in, 'x' ) == 0 && strcasecmp( $out, 'utf-8' ) == 0 ) {
12 return preg_replace_callback (
13 '/([cghjsu]x?)((?:xx)*)(?!x)/i',
14 'strrtxuCallback', $string );
15 } else if ( strcasecmp( $in, 'UTF-8' ) == 0 && strcasecmp( $out, 'x' ) == 0 ) {
16 # Double Xs only if they follow cxapelutaj literoj.
17 return preg_replace_callback(
18 '/((?:[cghjsu]|\xc4[\x88\x89\x9c\x9d\xa4\xa5\xb4\xb5]|\xc5[\x9c\x9d\xac\xad])x*)/ei',
19 'strrtuxCallback', $string );
20 }
21 return parent::iconv( $in, $out, $string );
22 }
23
24 function strrtuxCallback( $matches ) {
25 static $ux = array (
26 'x' => 'xx' , 'X' => 'Xx' ,
27 "\xc4\x88" => "Cx" , "\xc4\x89" => "cx" ,
28 "\xc4\x9c" => "Gx" , "\xc4\x9d" => "gx" ,
29 "\xc4\xa4" => "Hx" , "\xc4\xa5" => "hx" ,
30 "\xc4\xb4" => "Jx" , "\xc4\xb5" => "jx" ,
31 "\xc5\x9c" => "Sx" , "\xc5\x9d" => "sx" ,
32 "\xc5\xac" => "Ux" , "\xc5\xad" => "ux"
33 );
34 return strtr( $matches[1], $ux );
35 }
36
37 function strrtxuCallback( $matches ) {
38 static $xu = array (
39 'xx' => 'x' , 'xX' => 'x' ,
40 'Xx' => 'X' , 'XX' => 'X' ,
41 "Cx" => "\xc4\x88" , "CX" => "\xc4\x88" ,
42 "cx" => "\xc4\x89" , "cX" => "\xc4\x89" ,
43 "Gx" => "\xc4\x9c" , "GX" => "\xc4\x9c" ,
44 "gx" => "\xc4\x9d" , "gX" => "\xc4\x9d" ,
45 "Hx" => "\xc4\xa4" , "HX" => "\xc4\xa4" ,
46 "hx" => "\xc4\xa5" , "hX" => "\xc4\xa5" ,
47 "Jx" => "\xc4\xb4" , "JX" => "\xc4\xb4" ,
48 "jx" => "\xc4\xb5" , "jX" => "\xc4\xb5" ,
49 "Sx" => "\xc5\x9c" , "SX" => "\xc5\x9c" ,
50 "sx" => "\xc5\x9d" , "sX" => "\xc5\x9d" ,
51 "Ux" => "\xc5\xac" , "UX" => "\xc5\xac" ,
52 "ux" => "\xc5\xad" , "uX" => "\xc5\xad"
53 );
54 return strtr( $matches[1], $xu ) . strtr( $matches[2], $xu );
55 }
56
57 function checkTitleEncoding( $s ) {
58 # Check for X-system backwards-compatibility URLs
59 $ishigh = preg_match( '/[\x80-\xff]/', $s );
60 $isutf = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
61 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
62
63 if ( $ishigh and !$isutf ) {
64 # Assume Latin1
65 $s = utf8_encode( $s );
66 } else {
67 if ( preg_match( '/(\xc4[\x88\x89\x9c\x9d\xa4\xa5\xb4\xb5]' .
68 '|\xc5[\x9c\x9d\xac\xad])/', $s ) )
69 return $s;
70 }
71
72 // if( preg_match( '/[cghjsu]x/i', $s ) )
73 // return $this->iconv( 'x', 'utf-8', $s );
74 return $s;
75 }
76
77 function initEncoding() {
78 global $wgEditEncoding;
79 $wgEditEncoding = 'x';
80 }
81 }