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

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:  * StepP.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\Type as UniType;
19: use \Com\Tecnick\Unicode\Data\Constant as UniConstant;
20: 
21: /**
22:  * Com\Tecnick\Unicode\Bidi\StepP
23:  *
24:  * @since       2015-07-13
25:  * @category    Library
26:  * @package     Unicode
27:  * @author      Nicola Asuni <info@tecnick.com>
28:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
29:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
30:  * @link        https://github.com/tecnickcom/tc-lib-unicode
31:  */
32: class StepP
33: {
34:     /**
35:      * Array of UTF-8 codepoints
36:      *
37:      * @var array
38:      */
39:     protected $ordarr = array();
40: 
41:     /**
42:      * P Steps for Bidirectional algorithm
43:      *
44:      * @param array  $ordarr   Array of UTF-8 codepoints
45:      */
46:     public function __construct($ordarr)
47:     {
48:         $this->ordarr = $ordarr;
49:     }
50: 
51:     /**
52:      * Get the Paragraph Embedding Level
53:      *
54:      * @return int
55:      */
56:     public function getPel()
57:     {
58:         // P2. In each paragraph, find the first character of type L, AL, or R
59:         //     while skipping over any characters between an isolate initiator and its matching PDI or,
60:         //     if it has no matching PDI, the end of the paragraph.
61:         // P3. If a character is found in P2 and it is of type AL or R,
62:         //     then set the paragraph embedding level to one; otherwise, set it to zero.
63:         $isolate = 0;
64:         foreach ($this->ordarr as $ord) {
65:             $isolate = $this->getIsolateLevel($ord, $isolate);
66:             if (($isolate == 0) && isset(UniType::$uni[$ord])) {
67:                 $type = UniType::$uni[$ord];
68:                 if ($type === 'L') {
69:                     return 0;
70:                 }
71:                 if (($type === 'R') || ($type === 'AL')) {
72:                     return 1;
73:                 }
74:             }
75:         }
76:         return 0;
77:     }
78: 
79:     /**
80:      * Update the level of explicit directional isolates
81:      *
82:      * @return int
83:      */
84:     protected function getIsolateLevel($ord, $isolate)
85:     {
86:         if (($ord == UniConstant::LRI) || ($ord == UniConstant::RLI) || ($ord == UniConstant::FSI)) {
87:             ++$isolate;
88:         } elseif ($ord == UniConstant::PDI) {
89:             --$isolate;
90:         }
91:         return max(0, $isolate);
92:     }
93: }
94: 
 

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