source-class-Com.Tecnick.Unicode.Bidi.StepW

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
  1: <?php
  2: /**
  3:  * StepW.php
  4:  *
  5:  * @since       2011-05-23
  6:  * @category    Library
  7:  * @package     Unicode
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-unicode
 12:  *
 13:  * This file is part of tc-lib-unicode software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Unicode\Bidi;
 17: 
 18: use \Com\Tecnick\Unicode\Data\Constant as UniConstant;
 19: 
 20: /**
 21:  * Com\Tecnick\Unicode\Bidi\StepW
 22:  *
 23:  * @since       2015-07-13
 24:  * @category    Library
 25:  * @package     Unicode
 26:  * @author      Nicola Asuni <info@tecnick.com>
 27:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 28:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 29:  * @link        https://github.com/tecnickcom/tc-lib-unicode
 30:  */
 31: class StepW extends \Com\Tecnick\Unicode\Bidi\StepBase
 32: {
 33:     /**
 34:      * Process W steps
 35:      * Resolving Weak Types
 36:      */
 37:     protected function process()
 38:     {
 39:         $this->processStep('processW1');
 40:         $this->processStep('processW2');
 41:         $this->processStep('processW3');
 42:         $this->processStep('processW4');
 43:         $this->processStep('processW5');
 44:         $this->processStep('processW6');
 45:         $this->processStep('processW7');
 46:     }
 47: 
 48:     /**
 49:      * W1. Examine each nonspacing mark (NSM) in the isolating run sequence, and
 50:      *     change the type of the NSM to Other Neutral if the previous character is an isolate initiator or PDI, and
 51:      *     to the type of the previous character otherwise.
 52:      *     If the NSM is at the start of the isolating run sequence, it will get the type of sos.
 53:      *     (Note that in an isolating run sequence, an isolate initiator followed by an NSM or any type
 54:      *     other than PDI must be an overflow isolate initiator.)
 55:      *
 56:      * @param int $idx Current character position
 57:      */
 58:     protected function processW1($idx)
 59:     {
 60:         if ($this->seq['item'][$idx]['type'] == 'NSM') {
 61:             $jdx = ($idx - 1);
 62:             if ($jdx < 0) {
 63:                 $this->seq['item'][$idx]['type'] = $this->seq['sos'];
 64:             } elseif (($this->seq['item'][$jdx]['char'] >= UniConstant::LRI)
 65:                 && ($this->seq['item'][$jdx]['char'] <= UniConstant::PDI)
 66:             ) {
 67:                 $this->seq['item'][$idx]['type'] = 'ON';
 68:             } else {
 69:                 $this->seq['item'][$idx]['type'] = $this->seq['item'][$jdx]['type'];
 70:             }
 71:         }
 72:     }
 73: 
 74:     /**
 75:      * W2. Search backward from each instance of a European number until the first strong type (R, L, AL, or sos)
 76:      *     is found. If an AL is found, change the type of the European number to Arabic number.
 77:      *
 78:      * @param int $idx Current character position
 79:      */
 80:     protected function processW2($idx)
 81:     {
 82:         if ($this->seq['item'][$idx]['type'] == 'EN') {
 83:             $jdx = ($idx - 1);
 84:             while ($jdx >= 0) {
 85:                 if ($this->seq['item'][$jdx]['type'] == 'AL') {
 86:                     $this->seq['item'][$idx]['type'] = 'AN';
 87:                     break;
 88:                 } elseif (in_array($this->seq['item'][$jdx]['type'], array('R','L'))) {
 89:                     break;
 90:                 }
 91:                 --$jdx;
 92:             }
 93:         }
 94:     }
 95: 
 96:     /**
 97:      * W3. Change all ALs to R.
 98:      *
 99:      * @param int $idx Current character position
100:      */
101:     protected function processW3($idx)
102:     {
103:         if ($this->seq['item'][$idx]['type'] == 'AL') {
104:             $this->seq['item'][$idx]['type'] = 'R';
105:         }
106:     }
107: 
108:     /**
109:      * W4. A single European separator between two European numbers changes to a European number.
110:      *     A single common separator between two numbers of the same type changes to that type.
111:      *
112:      * @param int $idx Current character position
113:      */
114:     protected function processW4($idx)
115:     {
116:         if (in_array($this->seq['item'][$idx]['type'], array('ES','CS'))) {
117:             $bdx = ($idx - 1);
118:             $fdx = ($idx + 1);
119:             if (($bdx >= 0)
120:                 && ($fdx < $this->seq['length'])
121:                 && ($this->seq['item'][$bdx]['type'] == $this->seq['item'][$fdx]['type'])
122:             ) {
123:                 if (in_array($this->seq['item'][$bdx]['type'], array('EN','AN'))) {
124:                     $this->seq['item'][$idx]['type'] = $this->seq['item'][$bdx]['type'];
125:                 }
126:             }
127:         }
128:     }
129: 
130:     /**
131:      * W5. A sequence of European terminators adjacent to European numbers changes to all European numbers.
132:      *
133:      * @param int $idx Current character position
134:      */
135:     protected function processW5($idx)
136:     {
137:         if ($this->seq['item'][$idx]['type'] == 'ET') {
138:             $this->processW5a($idx);
139:             $this->processW5b($idx);
140:         }
141:     }
142: 
143:     /**
144:      * W5a
145:      *
146:      * @param int $idx Current character position
147:      */
148:     protected function processW5a($idx)
149:     {
150:         for ($jdx = ($idx - 1); $jdx >= 0; --$jdx) {
151:             if ($this->seq['item'][$jdx]['type'] == 'EN') {
152:                 $this->seq['item'][$idx]['type'] = 'EN';
153:             } else {
154:                 break;
155:             }
156:         }
157:     }
158: 
159:     /**
160:      * W5b
161:      *
162:      * @param int $idx Current character position
163:      */
164:     protected function processW5b($idx)
165:     {
166:         if ($this->seq['item'][$idx]['type'] == 'ET') {
167:             for ($jdx = ($idx + 1); $jdx < $this->seq['length']; ++$jdx) {
168:                 if ($this->seq['item'][$jdx]['type'] == 'EN') {
169:                     $this->seq['item'][$idx]['type'] = 'EN';
170:                 } elseif ($this->seq['item'][$jdx]['type'] != 'ET') {
171:                     break;
172:                 }
173:             }
174:         }
175:     }
176: 
177:     /**
178:      * W6. Otherwise, separators and terminators change to Other Neutral.
179:      *
180:      * @param int $idx Current character position
181:      */
182:     protected function processW6($idx)
183:     {
184:         if (in_array($this->seq['item'][$idx]['type'], array('ET','ES','CS','ON'))) {
185:             $this->seq['item'][$idx]['type'] = 'ON';
186:         }
187:     }
188: 
189:     /**
190:      * W7. Search backward from each instance of a European number until the first strong type (R, L, or sos) is found.
191:      *     If an L is found, then change the type of the European number to L.
192:      *
193:      * @param int $idx Current character position
194:      */
195:     protected function processW7($idx)
196:     {
197:         if ($this->seq['item'][$idx]['type'] == 'EN') {
198:             for ($jdx = ($idx - 1); $jdx >= 0; --$jdx) {
199:                 if ($this->seq['item'][$jdx]['type'] == 'L') {
200:                     $this->seq['item'][$idx]['type'] = 'L';
201:                     break;
202:                 } elseif ($this->seq['item'][$jdx]['type'] == 'R') {
203:                     break;
204:                 }
205:             }
206:             if (($this->seq['sos'] == 'L') && ($jdx < 0)) {
207:                 $this->seq['item'][$idx]['type'] = 'L';
208:             }
209:         }
210:     }
211: }
212: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy