Commit fc60bccf authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Fixes #5602 Added array modifiers

Showing with 19 additions and 3 deletions
+19 -3
...@@ -379,15 +379,15 @@ class templateHandling ...@@ -379,15 +379,15 @@ class templateHandling
{ {
mb_internal_encoding('UTF-8'); mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8'); mb_regex_encoding('UTF-8');
if (is_array($str) && (strtolower($m) == $m)) { if (is_array($str) && (!is_numeric($m)) && (strtolower($m) == $m)) {
/* $str is an array and $m is lowercase, so it's a string modifier */ /* $str is an array and $m is lowercase, so it's a string modifier */
$str = $str[0]; $str = reset($str);
} }
$result = array($str); $result = array($str);
switch ($m) { switch ($m) {
case 'F': case 'F':
// First // First
$result = array($str[0]); $result = array(reset($str));
break; break;
case 'L': case 'L':
// Last // Last
...@@ -405,6 +405,22 @@ class templateHandling ...@@ -405,6 +405,22 @@ class templateHandling
// Count // Count
$result = array(count($str)); $result = array(count($str));
break; break;
case 'M':
// Match
if (count($args) < 1) {
trigger_error('Missing "M" match modifier parameter');
$args[] = '/.*/';
}
$result = array(array_filter($str, function ($s) use ($args) { return preg_match($args[0], $s); }));
break;
case '4':
// IPv4
$result = array(array_filter($str, 'tests::is_ipv4'));
break;
case '6':
// IPv6
$result = array(array_filter($str, 'tests::is_ipv6'));
break;
case 'c': case 'c':
// comment // comment
$result = array(''); $result = array('');
......
  • bmortier @bmortier

    mentioned in issue #1786 (closed)

    By Côme Chilliet on 2017-09-02T15:38:14 (imported from GitLab)

    ·

    mentioned in issue #1786 (closed)

    By Côme Chilliet on 2017-09-02T15:38:14 (imported from GitLab)

    Toggle commit list
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment