27 private function initLcUc( $lcChars, $ucChars, $reinit =
false ) {
28 # bail if we've already done this, unless we are re-initializing
29 if ( !$reinit && $this->lc2uc && $this->uc2lc ) {
33 # split up the lc and uc lists in a unicode-friendly way
35 preg_match_all(
'/./u', $lcChars, $myLc );
39 preg_match_all(
'/./u', $ucChars, $myUc );
42 # map lc to uc and vice versa
43 $this->lc2uc = array_combine( array_values( $myLc ), array_values( $myUc ) );
44 $this->uc2lc = array_combine( array_values( $myUc ), array_values( $myLc ) );
59 private function addMappings( $mapArray, &$A2B, &$B2A, $exactCase =
false,
60 $prePat =
'', $postPat =
'' ) {
61 foreach ( $mapArray as $WordA => $WordB ) {
62 $ucA = $this->
myUc( $WordA );
63 $ucWordA = $this->
myUcWord( $WordA );
64 $ucB = $this->
myUc( $WordB );
65 $ucWordB = $this->
myUcWord( $WordB );
67 # if there are regexes, only map toward backregs
68 if ( ! preg_match(
'/\$[1-9]/', $WordA ) ) {
69 $A2B[ $prePat . $WordA . $postPat ] = $WordB;
71 $A2B[ $prePat . $ucWordA . $postPat ] = $ucWordB;
72 $A2B[ $prePat . $ucA . $postPat ] = $ucB;
76 if ( ! preg_match(
'/\$[1-9]/', $WordB ) ) {
77 $B2A[ $prePat . $WordB . $postPat ] = $WordA;
79 $B2A[ $prePat . $ucWordB . $postPat ] = $ucWordA;
80 $B2A[ $prePat . $ucB . $postPat ] = $ucA;
87 # init lc and uc, as needed
88 $this->
initLcUc( $lcChars, $ucChars );
89 # load C2L and L2C whole-word exceptions into the same array, since it's just a look up
90 # no regex prefix/suffix needed
91 $this->
addMappings( $this->wordMappings, $this->exceptionMap, $this->exceptionMap );
92 $this->
addMappings( $this->exactCaseMappings, $this->exceptionMap, $this->exceptionMap,
true );
94 # load C2L and L2C bidirectional prefix mappings
96 $this->Cyrl2LatnPatterns, $this->Latn2CyrlPatterns,
false,
'/^',
'/u' );
98 $this->Cyrl2LatnPatterns, $this->Latn2CyrlPatterns,
false,
'/',
'$/u' );
100 # tack on one-way mappings to the ends of the prefix and suffix patterns