ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilDclTokenizer Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilDclTokenizer:

Static Public Member Functions

static getTokens (string $expression)
 Split expression by & (ignore escaped &-symbols with backslash) More...
 
static getMathTokens (string $math_expression)
 Generate tokens for a math expression. More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Definition at line 19 of file class.ilDclTokenizer.php.

Member Function Documentation

◆ getMathTokens()

static ilDclTokenizer::getMathTokens ( string  $math_expression)
static

Generate tokens for a math expression.

Parameters
string$math_expressionExpression of type math

Definition at line 69 of file class.ilDclTokenizer.php.

References ilDclExpressionParser\getOperators().

Referenced by ilDclExpressionParser\parse().

69  : array
70  {
71  $operators = array_keys(ilDclExpressionParser::getOperators());
72  $pattern = '#((^\[\[)[\d\.]+)|(\(|\)|\\' . implode("|\\", $operators) . ')#';
73  $tokens = preg_split($pattern, $math_expression, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
74 
75  return array_map('trim', $tokens);
76  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTokens()

static ilDclTokenizer::getTokens ( string  $expression)
static

Split expression by & (ignore escaped &-symbols with backslash)

Parameters
string$expressionGlobal expression to parse

Definition at line 25 of file class.ilDclTokenizer.php.

References $results.

Referenced by ilDclExpressionParser\parse().

25  : array
26  {
27  $expression = ltrim($expression, '=');
28  $expression = trim($expression);
29 
30  $matches = [];
31  //Match all & inside [] (e.g. [[Metadaten & OER]])
32  preg_match_all("/\[\[[^\]]*&[^\]]*\]\]/ui", $expression, $matches);
33  $matches_inside_brackets = $matches[0];
34  $replace_random = sha1("replacement_string");
35 
36 
37  //Replace those & with a set of unprobable chars, to be ignored by the following selection of tokens
38  foreach ($matches_inside_brackets as $match) {
39  if (!$match) {
40  continue;
41  }
42  $match_save = str_replace("&", $replace_random, $match);
43  $expression = str_replace($match, $match_save, $expression);
44  }
45 
46  //var_dump($expression);
47  preg_match_all("/([^\\\\&]|\\\\&)*/ui", $expression, $matches);
48  $results = $matches[0];
49 
50  $return = [];
51  foreach ($results as $result) {
52  if (!$result) {
53  continue;
54  }
55  $replace = str_ireplace('\&', '&', $result);
56 
57  //Replace those & before replaced chars back
58  $return[] = str_replace($replace_random, "&", $replace);
59 
60  }
61 
62  return array_map('trim', $return);
63  }
$results
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: