Index: trunk/extensions/RegexFun/RELEASE-NOTES |
— | — | @@ -1,5 +1,11 @@ |
2 | 2 | Changelog: |
3 | 3 | ========== |
| 4 | + * (trunk) 2011 -- version 1.0.1 |
| 5 | + - Bug in '#regex_var' solved: default value now gets returned in case '#regex' went wront or |
| 6 | + not called before. |
| 7 | + - '#regexall' last parameter, 'length' can be empty '' which is the specified default now. It |
| 8 | + simply means there is not limit and all items should be returned. |
| 9 | + |
4 | 10 | * November 4, 2011 -- Version 1.0 (initial public release). |
5 | 11 | Introduces the following parser functions defined within 'ExtRegexFun' class: |
6 | 12 | - #regex |
Index: trunk/extensions/RegexFun/RegexFun.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | * |
8 | 8 | * Info on mediawiki.org: http://www.mediawiki.org/wiki/Extension:Regex_Fun |
9 | 9 | * |
10 | | - * @version: 1.0 |
| 10 | + * @version: 1.0.1 |
11 | 11 | * @license: ISC license |
12 | 12 | * @author: Daniel Werner < danweetz@web.de > |
13 | 13 | * |
— | — | @@ -52,7 +52,7 @@ |
53 | 53 | * |
54 | 54 | * @var string |
55 | 55 | */ |
56 | | - const VERSION = '1.0'; |
| 56 | + const VERSION = '1.0.1'; |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Sets up parser functions |
— | — | @@ -298,25 +298,29 @@ |
299 | 299 | * @param $pattern String regular expression pattern - must use /, | or % as delimiter |
300 | 300 | * @param $separator String to separate all the matches |
301 | 301 | * @param $offset Integer first match to print out. Negative values possible: -1 means last match. |
302 | | - * @param $limit Integer maximum matches for print out |
| 302 | + * @param $length Integer maximum matches for print out |
303 | 303 | * |
304 | 304 | * @return String result of all matching text parts separated by a string |
305 | 305 | */ |
306 | | - public static function regexall( &$parser , $subject = '' , $pattern = '' , $separator = ', ' , $offset = 0 , $limit = null ) { |
| 306 | + public static function regexall( &$parser , $subject = '' , $pattern = '' , $separator = ', ' , $offset = 0 , $length = '' ) { |
307 | 307 | // validate and check for wrong input: |
308 | 308 | $continue = self::validateRegexCall( $parser, $subject, $pattern, $specialFlags, false ); |
309 | 309 | if( ! $continue ) { |
310 | 310 | return self::invalidRegexParsingOutput( $pattern );; |
311 | 311 | } |
| 312 | + |
312 | 313 | // adjust default values: |
313 | 314 | $offset = (int)$offset; |
314 | | - if( $limit !== null ) { |
315 | | - $limit = (int)$limit; |
| 315 | + |
| 316 | + if( trim( $length ) === '' ) { |
| 317 | + $length = null; |
| 318 | + } else { |
| 319 | + $length = (int)$length; |
316 | 320 | } |
317 | 321 | |
318 | 322 | if( preg_match_all( $pattern, $subject, $matches, PREG_SET_ORDER ) ) { |
319 | 323 | |
320 | | - $matches = array_slice( $matches, $offset, $limit ); |
| 324 | + $matches = array_slice( $matches, $offset, $length ); |
321 | 325 | $output = ''; //$end = ($end or ($end >= count($matches)) ? $end : count($matches) ); |
322 | 326 | |
323 | 327 | for( $count = 0; $count < count( $matches ); $count++ ) { |
— | — | @@ -342,7 +346,7 @@ |
343 | 347 | $lastMatches = self::getLastMatches( $parser ); |
344 | 348 | |
345 | 349 | if( $lastMatches === null ) { // last regex was invalid or none executed yet |
346 | | - return ''; |
| 350 | + return $defaultVal; |
347 | 351 | } |
348 | 352 | |
349 | 353 | // if requested index is numerical: |
Index: trunk/extensions/RegexFun/README |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | Use of the 'e' modifier behind the expression will be detected, the effect of using 'e' now is |
13 | 13 | adapted for mediawiki. With 'e' the replacement string will be parsed after references are replaced. |
14 | 14 | - #regexall: Searches the whole string for as many matches as possible and returns them separated by a separator. |
15 | | - - #regex_var: Allows to access references of the last used 'regex' or 'regexsearch' function. |
| 15 | + - #regex_var: Allows to access subexpression references of the last used 'regex' function. |
16 | 16 | - #regexquote: Runs php function 'preg_quote' on a string to use user-input savelly in regex functions. In case the |
17 | 17 | first character is a character with special meaning in MW, it will be replaced with its hexadecimal |
18 | 18 | notation e.g. '\x23' instead of '#'. This will prevent from things going terribly wrong when using |