return (string) mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset);
}
- return null === $length ? substr($item, $start) : substr($item, $start, $length);
+ return (string) (null === $length ? substr($item, $start) : substr($item, $start, $length));
}
/**
{
twig_escape_filter(new Twig_Environment(), 'foo', 'bar');
}
+
+ public function testTwigFirst()
+ {
+ $twig = new Twig_Environment();
+ $this->assertEquals('a', twig_first($twig, 'abc'));
+ $this->assertEquals(1, twig_first($twig, array(1, 2, 3)));
+ $this->assertEquals('', twig_first($twig, null));
+ $this->assertEquals('', twig_first($twig, ''));
+ }
+
+ public function testTwigLast()
+ {
+ $twig = new Twig_Environment();
+ $this->assertEquals('c', twig_last($twig, 'abc'));
+ $this->assertEquals(3, twig_last($twig, array(1, 2, 3)));
+ $this->assertEquals('', twig_last($twig, null));
+ $this->assertEquals('', twig_last($twig, ''));
+ }
}
function foo_escaper_for_test(Twig_Environment $env, $string, $charset)