php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #53659
Patch getregex.diff revision 2011-01-05 22:01 UTC by jthijssen at noxlogic dot nl

Patch getregex.diff for SPL related Bug #53659

Patch version 2011-01-05 22:01 UTC

Return to Bug #53659 | Download this patch
Patch Revisions:

Developer: jthijssen@noxlogic.nl

Index: ext/spl/spl_iterators.h
===================================================================
--- ext/spl/spl_iterators.h	(revision 307135)
+++ ext/spl/spl_iterators.h	(working copy)
@@ -154,6 +154,7 @@
 			long             preg_flags;
 			pcre_cache_entry *pce;
 			char             *regex;
+                        uint             regex_len;
 		} regex;
 #endif
 	} u;
Index: ext/spl/tests/regexiterator_getregex.phpt
===================================================================
--- ext/spl/tests/regexiterator_getregex.phpt	(revision 0)
+++ ext/spl/tests/regexiterator_getregex.phpt	(revision 0)
@@ -0,0 +1,29 @@
+--TEST--
+SPL: RegexIterator::getRegex() basic tests
+--CREDITS--
+Joshua Thijssen <jthijssen@noxlogic.nl>
+--FILE--
+<?php
+
+$array = array('cat', 'hat', 'sat');
+$iterator = new ArrayIterator($array);
+
+# Simple regex
+$regexIterator = new RegexIterator($iterator, '/.at/');
+var_dump($regexIterator->getRegex());
+
+# Empty regular expression
+$regexIterator = new RegexIterator($iterator, '//');
+var_dump($regexIterator->getRegex());
+
+# "Complex" email regular expression
+$regexIterator = new RegexIterator($iterator, '|\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b|');
+var_dump($regexIterator->getRegex());
+
+
+
+?>
+--EXPECT--
+string(5) "/.at/"
+string(2) "//"
+string(43) "|\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b|"
Index: ext/spl/internal/regexiterator.inc
===================================================================
--- ext/spl/internal/regexiterator.inc	(revision 307135)
+++ ext/spl/internal/regexiterator.inc	(working copy)
@@ -158,6 +158,13 @@
 	{
 		$this->preg_flags = $preg_flags;
 	}
+
+        /** @return current regular expression
+         */
+        function getRegex()
+        {
+            return $this->regex;
+        }
 }
 
 ?>
Index: ext/spl/spl_iterators.c
===================================================================
--- ext/spl/spl_iterators.c	(revision 307135)
+++ ext/spl/spl_iterators.c	(working copy)
@@ -1466,6 +1466,7 @@
 			}
 			intern->u.regex.mode = mode;
 			intern->u.regex.regex = estrndup(regex, regex_len);
+                        intern->u.regex.regex_len = regex_len;
 			intern->u.regex.pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC);
 			if (intern->u.regex.pce == NULL) {
 				/* pcre_get_compiled_regex_cache has already sent error */
@@ -1942,6 +1943,19 @@
 	}
 } /* }}} */
 
+/* {{{ proto string RegexIterator::getRegex()
+   Returns current regular expression */
+SPL_METHOD(RegexIterator, getRegex)
+{
+	spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
+	}
+
+	RETURN_STRINGL(intern->u.regex.regex, intern->u.regex.regex_len, 1);
+} /* }}} */
+
 /* {{{ proto bool RegexIterator::getMode()
    Returns current operation mode */
 SPL_METHOD(RegexIterator, getMode)
@@ -2206,6 +2220,7 @@
 	SPL_ME(RegexIterator,   setFlags,         arginfo_regex_it_set_flags,      ZEND_ACC_PUBLIC)
 	SPL_ME(RegexIterator,   getPregFlags,     arginfo_recursive_it_void,       ZEND_ACC_PUBLIC)
 	SPL_ME(RegexIterator,   setPregFlags,     arginfo_regex_it_set_preg_flags, ZEND_ACC_PUBLIC)
+        SPL_ME(RegexIterator,   getRegex,         arginfo_recursive_it_void,       ZEND_ACC_PUBLIC)
 	{NULL, NULL, NULL}
 };
 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 20:01:29 2024 UTC