Beispiel #1
0
 static function resolveEntities($text)
 {
     com_wiris_util_xml_WXmlUtils::initEntities();
     $sb = new StringBuf();
     $i = 0;
     $n = strlen($text);
     while ($i < $n) {
         $c = com_wiris_util_xml_WXmlUtils::getUtf8Char($text, $i);
         if ($c === 60 && $i + 12 < $n && _hx_char_code_at($text, $i + 1) === 33) {
             if (_hx_substr($text, $i, 9) === "<![CDATA[") {
                 $e = _hx_index_of($text, "]]>", $i);
                 if ($e !== -1) {
                     $sb->add(_hx_substr($text, $i, $e - $i + 3));
                     $i = $e + 3;
                     continue;
                 }
                 unset($e);
             }
         }
         if ($c > 127) {
             $special = com_wiris_util_xml_WXmlUtils_1($c, $i, $n, $sb, $text);
             $sb->add($special);
             $i += strlen($special) - 1;
             unset($special);
         } else {
             if ($c === 38) {
                 $i++;
                 $c = _hx_char_code_at($text, $i);
                 if (com_wiris_util_xml_WXmlUtils::isNameStart($c)) {
                     $name = new StringBuf();
                     $name->b .= chr($c);
                     $i++;
                     $c = _hx_char_code_at($text, $i);
                     while (com_wiris_util_xml_WXmlUtils::isNameChar($c)) {
                         $name->b .= chr($c);
                         $i++;
                         $c = _hx_char_code_at($text, $i);
                     }
                     $ent = $name->b;
                     if ($c === 59 && com_wiris_util_xml_WXmlUtils::$entities->exists($ent) && !com_wiris_util_xml_WXmlUtils::isXmlEntity($ent)) {
                         $val = com_wiris_util_xml_WXmlUtils::$entities->get($ent);
                         $sb->add(com_wiris_util_xml_WXmlUtils_2($c, $ent, $i, $n, $name, $sb, $text, $val));
                         unset($val);
                     } else {
                         $sb->add("&");
                         $sb->add($name);
                         $sb->b .= chr($c);
                     }
                     unset($name, $ent);
                 } else {
                     if ($c === 35) {
                         $i++;
                         $c = _hx_char_code_at($text, $i);
                         if ($c === 120) {
                             $hex = new StringBuf();
                             $i++;
                             $c = _hx_char_code_at($text, $i);
                             while (com_wiris_util_xml_WXmlUtils::isHexDigit($c)) {
                                 $hex->b .= chr($c);
                                 $i++;
                                 $c = _hx_char_code_at($text, $i);
                             }
                             $hent = $hex->b;
                             if ($c === 59 && !com_wiris_util_xml_WXmlUtils::isXmlEntity("#x" . $hent)) {
                                 $dec = Std::parseInt("0x" . $hent);
                                 $sb->add(com_wiris_util_xml_WXmlUtils_3($c, $dec, $hent, $hex, $i, $n, $sb, $text));
                                 unset($dec);
                             } else {
                                 $sb->add("&#x");
                                 $sb->add($hent);
                                 $sb->b .= chr($c);
                             }
                             unset($hex, $hent);
                         } else {
                             if (48 <= $c && $c <= 57) {
                                 $dec = new StringBuf();
                                 while (48 <= $c && $c <= 57) {
                                     $dec->b .= chr($c);
                                     $i++;
                                     $c = _hx_char_code_at($text, $i);
                                 }
                                 if ($c === 59 && !com_wiris_util_xml_WXmlUtils::isXmlEntity("#" . Std::string($dec))) {
                                     $sb->add(com_wiris_util_xml_WXmlUtils_4($c, $dec, $i, $n, $sb, $text));
                                 } else {
                                     $sb->add("&#" . $dec->b);
                                     $sb->b .= chr($c);
                                 }
                                 unset($dec);
                             }
                         }
                     }
                 }
             } else {
                 $sb->b .= chr($c);
             }
         }
         $i++;
         unset($c);
     }
     return $sb->b;
 }