HTMLPurifier 4.4.0
/home/ezyang/Dev/htmlpurifier/library/HTMLPurifier/AttrDef/HTML/Nmtokens.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class HTMLPurifier_AttrDef_HTML_Nmtokens extends HTMLPurifier_AttrDef
00007 {
00008 
00009     public function validate($string, $config, $context) {
00010 
00011         $string = trim($string);
00012 
00013         // early abort: '' and '0' (strings that convert to false) are invalid
00014         if (!$string) return false;
00015 
00016         $tokens = $this->split($string, $config, $context);
00017         $tokens = $this->filter($tokens, $config, $context);
00018         if (empty($tokens)) return false;
00019         return implode(' ', $tokens);
00020 
00021     }
00022 
00026     protected function split($string, $config, $context) {
00027         // OPTIMIZABLE!
00028         // do the preg_match, capture all subpatterns for reformulation
00029 
00030         // we don't support U+00A1 and up codepoints or
00031         // escaping because I don't know how to do that with regexps
00032         // and plus it would complicate optimization efforts (you never
00033         // see that anyway).
00034         $pattern = '/(?:(?<=\s)|\A)'. // look behind for space or string start
00035                    '((?:--|-?[A-Za-z_])[A-Za-z_\-0-9]*)'.
00036                    '(?:(?=\s)|\z)/'; // look ahead for space or string end
00037         preg_match_all($pattern, $string, $matches);
00038         return $matches[1];
00039     }
00040 
00046     protected function filter($tokens, $config, $context) {
00047         return $tokens;
00048     }
00049 
00050 }
00051 
00052 // vim: et sw=4 sts=4