ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
split($string, $config, $context)
Splits a space separated list of tokens into its constituent parts.
Definition: Nmtokens.php:39
Base class for all validating attribute definitions.
Definition: AttrDef.php:13
filter($tokens, $config, $context)
Template method for removing certain tokens based on arbitrary criteria.
Definition: Nmtokens.php:64
Validates contents based on NMTOKENS attribute type.
Definition: Nmtokens.php:6
validate($string, $config, $context)
Definition: Nmtokens.php:15