HTMLPurifier/AttrDef/HTML/Nmtokens.php Quellcode

Nmtokens.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
7 {
8 
15  public function validate($string, $config, $context)
16  {
17  $string = trim($string);
18 
19  // early abort: '' and '0' (strings that convert to false) are invalid
20  if (!$string) {
21  return false;
22  }
23 
24  $tokens = $this->split($string, $config, $context);
25  $tokens = $this->filter($tokens, $config, $context);
26  if (empty($tokens)) {
27  return false;
28  }
29  return implode(' ', $tokens);
30  }
31 
39  protected function split($string, $config, $context)
40  {
41  // OPTIMIZABLE!
42  // do the preg_match, capture all subpatterns for reformulation
43 
44  // we don't support U+00A1 and up codepoints or
45  // escaping because I don't know how to do that with regexps
46  // and plus it would complicate optimization efforts (you never
47  // see that anyway).
48  $pattern = '/(?:(?<=\s)|\A)' . // look behind for space or string start
49  '((?:--|-?[A-Za-z_])[A-Za-z_\-0-9]*)' .
50  '(?:(?=\s)|\z)/'; // look ahead for space or string end
51  preg_match_all($pattern, $string, $matches);
52  return $matches[1];
53  }
54 
64  protected function filter($tokens, $config, $context)
65  {
66  return $tokens;
67  }
68 }
69 
70 // vim: et sw=4 sts=4




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.