ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Nmtokens.php
Go to the documentation of this file.
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