Changeset 20748 for lang/php

Show
Ignore:
Timestamp:
10/05/08 06:21:43 (2 months ago)
Author:
drry
Message:
  • fixed regexes.
  • et cetera.
Location:
lang/php/HTML_CSS_Mobile/trunk/HTML/CSS
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/php/HTML_CSS_Mobile/trunk/HTML/CSS/Mobile.php

    r20747 r20748  
    9999                        } 
    100100                } 
    101                  
     101 
    102102                return $this; 
    103103        } 
     
    124124                // loadHTML/saveHTMLのバグに対応。XML宣言の一時退避 
    125125                $declaration = ''; 
    126                 if (preg_match('/^<\?xml\s+.+?\?>\n?/i', $document, $e))  
     126                if (preg_match('/^<\?xml\s[^>]+?\?>\s*/', $document, $e)) 
    127127                { 
    128128                        $declaration = $e[0]; 
     
    130130                } 
    131131 
    132                 // 数値文字参照・実体参照をエスケープ 
    133                 $document = preg_replace('/&(#\d+|\w+);/', 'HTMLCSSINLINERESCAPE%$1%::::::::', $document); 
     132                // 文字参照をエスケープ 
     133                $document = preg_replace('/&(#(?:\d+|x[0-9a-fA-F]+)|[A-Za-z0-9]+);/', 'HTMLCSSINLINERESCAPE%$1%::::::::', $document); 
    134134 
    135135                // 機種依存文字がエラーになる問題を回避するため、UTF-8に変換して処理 
     
    155155                } 
    156156                /**************************************** 
    157                  * 本処理  
     157                 * 本処理 
    158158                 ****************************************/ 
    159159 
     
    198198                                        $inline_style .= $k . ':' . $v . ';'; 
    199199                                } 
    200                                 foreach ($elements as $element)  
     200                                foreach ($elements as $element) 
    201201                                { 
    202202                                        if ($attr_style = $element->attributes->getNamedItem('style')) 
     
    222222                { 
    223223                        $new_style = implode(PHP_EOL, $add_style); 
     224                        $new_style = str_replace(']]>', ']]]><![CDATA[]>', $new_style); 
    224225                        $new_style = implode(PHP_EOL, array('<![CDATA[', $new_style, ']]>')); 
    225226 
     
    243244 
    244245                // エスケープしていた参照を復元 
    245                 $result = preg_replace('/HTMLCSSINLINERESCAPE%(#\d+|\w+)%::::::::/', '&$1;', $result); 
     246                $result = preg_replace('/HTMLCSSINLINERESCAPE%(#(?:\d+|x[0-9a-fA-F]+)|[A-Za-z0-9]+)%::::::::/', '&$1;', $result); 
    246247 
    247248                // 退避したXML宣言を復元 
     
    321322        { 
    322323                // 文字コードをDOM利用のためにUTF-8化 
    323                 $css_encoding = mb_detect_encoding($css_string, 'UTF-8, eucjp-win, sjis-win,  iso-2022-jp'); 
     324                $css_encoding = mb_detect_encoding($css_string, 'UTF-8, eucjp-win, sjis-win, iso-2022-jp'); 
    324325                if ($css_encoding != 'UTF-8') 
    325326                { 
     
    329330                $html_css = new HTML_CSS(); 
    330331                $css_error = $html_css->parseString($css_string); 
    331                 if ($css_error)  
     332                if ($css_error) 
    332333                { 
    333334                        throw new RuntimeException('ERROR: css parse error'); 
  • lang/php/HTML_CSS_Mobile/trunk/HTML/CSS/lib/selectorToXPath.php

    r17637 r20748  
    2626 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
    2727 * THE SOFTWARE. 
    28  */  
     28 */ 
    2929 
    3030/** 
     
    3434 * のPHP移殖版 
    3535 *   理解のいたる範囲で移植したので劣化コピーかもしれない。 
    36  */  
     36 */ 
    3737class selectorToXPath 
    3838{ 
     
    4343      'element'    => '/^(\*|[a-z_][a-z0-9_-]*)/i', 
    4444      'id_class'   => '/^([#.])([a-z0-9*_-]*)/i', 
    45       'attribute'  => '/^\[\s*([^~\|=\s]+)\s*([~\|]?=)\s*"([^"]+)"\s*\]/i', 
    46       'attr_box'   => '/^\[([^\]]*)\]/i', 
    47       'attr_not'   => '/^:not\((.*?)\)/i', 
     45      'attribute'  => '/^\[\s*([^~|=\s]+)\s*([~|]?=)\s*"([^"]+)"\s*\]/', 
     46      'attr_box'   => '/^\[([^\]]*)\]/', 
     47      'attr_not'   => '/^:not\(([^)]*)\)/i', 
    4848      'pseudo'     => '/^:([a-z0-9_-]+)(\(([a-z0-9_-]+)\))?/i', 
    4949      'combinator' => '/^(\s*[>+~\s])/i', 
    50       'comma'      => '/^,/i', 
     50      'comma'      => '/^,/', 
    5151    ); 
    5252