From: Fabien Potencier Date: Tue, 16 Oct 2012 12:38:15 +0000 (+0200) Subject: fixed previous merge X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=bac6bc7851c51692af1d855065e88b564e047b3b;p=konrad%2Ftwig.git fixed previous merge --- diff --git a/CHANGELOG b/CHANGELOG index d065a1d..e32e5e3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ * 1.10.3 (2012-XX-XX) - * n/a + * added a split filter * 1.10.2 (2012-10-15) diff --git a/doc/filters/split.rst b/doc/filters/split.rst index 14faf1f..92e1e41 100644 --- a/doc/filters/split.rst +++ b/doc/filters/split.rst @@ -1,24 +1,31 @@ ``split`` -======== +========= -The ``split`` filter returns a list of items from a string that's separated by the provided delimiter: +The ``split`` filter splits a string by the given delimiter and returns a list +of strings: .. code-block:: jinja {{ "one,two,three"|split(',') }} - {# returns [one, two, three] #} + {# returns ['one', 'two', 'three'] #} -A limit parameter is available which the returned list will contain a maximum of limit elements with the last element containing the rest of string. -If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string. -If the limit parameter is negative, all components except the last -limit are returned. -If the limit parameter is zero, then this is treated as 1. +You can also pass a ``limit`` argument: + + * If ``limit`` is positive, the returned array will contain a maximum of + limit elements with the last element containing the rest of string; + + * If ``limit`` is negative, all components except the last -limit are + returned; + + * If ``limit`` is zero, then this is treated as 1. .. code-block:: jinja {{ "one,two,three,four,five"|split(',', 3) }} {# returns [one, two, "three,four,five"] #} -If delimiter is an empty string, then value will be splitted by equal chunks. Length is set by limit parameter (1 char by default). +If the ``delimiter`` is an empty string, then value will be split by equal +chunks. Length is set by the ``limit`` argument (one character by default). .. code-block:: jinja @@ -30,8 +37,8 @@ If delimiter is an empty string, then value will be splitted by equal chunks. Le .. note:: - Internally, Twig uses the PHP `explode`_ or `str_split`_ (if delimiter is empty) functions for string splitting. - -.. _`explode`: http://php.net/explode + Internally, Twig uses the PHP `explode`_ or `str_split`_ (if delimiter is + empty) functions for string splitting. +.. _`explode`: http://php.net/explode .. _`str_split`: http://php.net/str_split diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 62fad73..d436340 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -654,10 +654,6 @@ function twig_join_filter($value, $glue = '') /** * Splits the string into an array. * - * The second parameter is option for the limit. - * If delimiter is an empty string, then string is split by equal chunks. Chunk length is 1 char by default, or set - * by limit - * *
  *  {{ "one,two,three"|split(',') }}
  *  {# returns [one, two, three] #}
@@ -673,10 +669,10 @@ function twig_join_filter($value, $glue = '')
  * 
* * @param string $value A string - * @param string $delimiter The separator to explode by + * @param string $delimiter The delimiter * @param integer $limit The limit * - * @return string The explode'ed string + * @return array The split string as an array */ function twig_split_filter($value, $delimiter, $limit = null) {