summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThies C. Arntzen <thies@php.net>2000-06-23 11:48:02 +0000
committerThies C. Arntzen <thies@php.net>2000-06-23 11:48:02 +0000
commitcfa7028d664e90f9150093645cfa8f2606b80012 (patch)
treeec8f4f6b3cc312e57a78e4899fb628feef162ac9
parent7d3341bee35d63e28a9fd235b2e72f56878d04b3 (diff)
downloadphp-git-cfa7028d664e90f9150093645cfa8f2606b80012.tar.gz
@- added spliti() function. (Thies)
-rw-r--r--ext/ereg/ereg.c35
-rw-r--r--ext/ereg/php_ereg.h1
-rw-r--r--ext/standard/basic_functions.c1
-rw-r--r--ext/standard/reg.c35
-rw-r--r--ext/standard/reg.h1
5 files changed, 57 insertions, 16 deletions
diff --git a/ext/ereg/ereg.c b/ext/ereg/ereg.c
index 3f8f28be04..069c2e9219 100644
--- a/ext/ereg/ereg.c
+++ b/ext/ereg/ereg.c
@@ -492,17 +492,16 @@ PHP_FUNCTION(eregi_replace)
}
/* }}} */
-/* ("root", "passwd", "uid", "gid", "other:stuff:like:/bin/sh")
- = split(":", $passwd_file, 5); */
-/* {{{ proto array split(string pattern, string string [, int limit])
- Split string into array by regular expression */
-PHP_FUNCTION(split)
+static void php_split(INTERNAL_FUNCTION_PARAMETERS, int icase)
{
pval **spliton, **str, **arg_count = NULL;
regex_t re;
regmatch_t subs[1];
char *strp, *endp;
- int err, size, count;
+ int err, size, count, copts = 0;
+
+ if (icase)
+ copts = REG_ICASE;
switch (ZEND_NUM_ARGS()) {
case 2:
@@ -526,7 +525,7 @@ PHP_FUNCTION(split)
strp = (*str)->value.str.val;
endp = (*str)->value.str.val + strlen((*str)->value.str.val);
- err = regcomp(&re, (*spliton)->value.str.val, REG_EXTENDED);
+ err = regcomp(&re, (*spliton)->value.str.val, REG_EXTENDED | copts);
if (err) {
php_error(E_WARNING, "unexpected regex error (%d)", err);
RETURN_FALSE;
@@ -586,11 +585,31 @@ PHP_FUNCTION(split)
add_next_index_stringl(return_value, strp, size, 1);
regfree(&re);
+}
+
+/* ("root", "passwd", "uid", "gid", "other:stuff:like:/bin/sh")
+ = split(":", $passwd_file, 5); */
+/* {{{ proto array split(string pattern, string string [, int limit])
+ Split string into array by regular expression */
+
+PHP_FUNCTION(split)
+{
+ php_split(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+}
- return;
+/* }}} */
+
+/* {{{ proto array spliti(string pattern, string string [, int limit])
+ Split string into array by regular expression case-insensitive */
+
+PHP_FUNCTION(spliti)
+{
+ php_split(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
+
/* }}} */
+
/* {{{ proto string sql_regcase(string string)
Make regular expression for case insensitive match */
PHPAPI PHP_FUNCTION(sql_regcase)
diff --git a/ext/ereg/php_ereg.h b/ext/ereg/php_ereg.h
index 0ffa7438bd..57c403eb09 100644
--- a/ext/ereg/php_ereg.h
+++ b/ext/ereg/php_ereg.h
@@ -40,6 +40,7 @@ PHP_FUNCTION(eregi);
PHP_FUNCTION(eregi_replace);
PHP_FUNCTION(ereg_replace);
PHP_FUNCTION(split);
+PHP_FUNCTION(spliti);
PHPAPI PHP_FUNCTION(sql_regcase);
typedef struct {
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index f55b5916a1..74d156e34d 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -346,6 +346,7 @@ function_entry basic_functions[] = {
PHP_FE(eregi, third_argument_force_ref)
PHP_FE(eregi_replace, NULL)
PHP_FE(split, NULL)
+ PHP_FE(spliti, NULL)
PHP_FALIAS(join, implode, NULL)
PHP_FE(sql_regcase, NULL)
diff --git a/ext/standard/reg.c b/ext/standard/reg.c
index 3f8f28be04..069c2e9219 100644
--- a/ext/standard/reg.c
+++ b/ext/standard/reg.c
@@ -492,17 +492,16 @@ PHP_FUNCTION(eregi_replace)
}
/* }}} */
-/* ("root", "passwd", "uid", "gid", "other:stuff:like:/bin/sh")
- = split(":", $passwd_file, 5); */
-/* {{{ proto array split(string pattern, string string [, int limit])
- Split string into array by regular expression */
-PHP_FUNCTION(split)
+static void php_split(INTERNAL_FUNCTION_PARAMETERS, int icase)
{
pval **spliton, **str, **arg_count = NULL;
regex_t re;
regmatch_t subs[1];
char *strp, *endp;
- int err, size, count;
+ int err, size, count, copts = 0;
+
+ if (icase)
+ copts = REG_ICASE;
switch (ZEND_NUM_ARGS()) {
case 2:
@@ -526,7 +525,7 @@ PHP_FUNCTION(split)
strp = (*str)->value.str.val;
endp = (*str)->value.str.val + strlen((*str)->value.str.val);
- err = regcomp(&re, (*spliton)->value.str.val, REG_EXTENDED);
+ err = regcomp(&re, (*spliton)->value.str.val, REG_EXTENDED | copts);
if (err) {
php_error(E_WARNING, "unexpected regex error (%d)", err);
RETURN_FALSE;
@@ -586,11 +585,31 @@ PHP_FUNCTION(split)
add_next_index_stringl(return_value, strp, size, 1);
regfree(&re);
+}
+
+/* ("root", "passwd", "uid", "gid", "other:stuff:like:/bin/sh")
+ = split(":", $passwd_file, 5); */
+/* {{{ proto array split(string pattern, string string [, int limit])
+ Split string into array by regular expression */
+
+PHP_FUNCTION(split)
+{
+ php_split(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+}
- return;
+/* }}} */
+
+/* {{{ proto array spliti(string pattern, string string [, int limit])
+ Split string into array by regular expression case-insensitive */
+
+PHP_FUNCTION(spliti)
+{
+ php_split(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
+
/* }}} */
+
/* {{{ proto string sql_regcase(string string)
Make regular expression for case insensitive match */
PHPAPI PHP_FUNCTION(sql_regcase)
diff --git a/ext/standard/reg.h b/ext/standard/reg.h
index 0ffa7438bd..57c403eb09 100644
--- a/ext/standard/reg.h
+++ b/ext/standard/reg.h
@@ -40,6 +40,7 @@ PHP_FUNCTION(eregi);
PHP_FUNCTION(eregi_replace);
PHP_FUNCTION(ereg_replace);
PHP_FUNCTION(split);
+PHP_FUNCTION(spliti);
PHPAPI PHP_FUNCTION(sql_regcase);
typedef struct {