]> granicus.if.org Git - php/commitdiff
Added substr_compare().
authorIlia Alshanetsky <iliaa@php.net>
Thu, 30 Oct 2003 00:49:33 +0000 (00:49 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 30 Oct 2003 00:49:33 +0000 (00:49 +0000)
NEWS
ext/standard/basic_functions.c
ext/standard/php_string.h
ext/standard/string.c

diff --git a/NEWS b/NEWS
index 74f647fcfd41101f01750fcd8967b2e7865e5897..fb3bdeb15f4969d9dc332a13c3df064de63f5a5a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,7 @@ PHP                                                                        NEWS
   . array_diff_uassoc(). (Andrey)
   . convert_uuencode(). (Ilia)
   . convert_uudecode(). (Ilia)
+  . substr_compare(). (Ilia)
   . pcntl_wait(). (GeorgeS)
 - Added "resume_pos" context option to "ftp://" wrapper. (Sara)
 - Added optional parameter to OCIWriteTemporaryLob() to specify the type of LOB
index 14c51179a9e728795359e14428f117a79074cc0f..60f01bf7d9f9cf2224909f405f656a11c792bc57 100644 (file)
@@ -374,6 +374,7 @@ function_entry basic_functions[] = {
        PHP_FE(str_word_count,                                                                                                          NULL)
        PHP_FE(str_split,                                                                                                               NULL)
        PHP_FE(strpbrk,                                                                                                                 NULL)
+       PHP_FE(substr_compare,                                                                                                          NULL)
 
 #ifdef HAVE_STRCOLL
        PHP_FE(strcoll,                                                                                                                 NULL)
index be64af0d6c0ad2218840211442374081dad43be7..dac757b0501cd895ba58ef84a96d2a454b81d99b 100644 (file)
@@ -89,6 +89,7 @@ PHP_FUNCTION(str_shuffle);
 PHP_FUNCTION(str_word_count);
 PHP_FUNCTION(str_split);
 PHP_FUNCTION(strpbrk);
+PHP_FUNCTION(substr_compare);
 #ifdef HAVE_STRCOLL
 PHP_FUNCTION(strcoll);
 #endif
index fe7553f13cb99158c5274e23b1a77695b67b44ee..73775ad24414407100ea9769e016371865d6bf45 100644 (file)
@@ -4662,6 +4662,35 @@ PHP_FUNCTION(strpbrk)
 }
 /* }}} */
 
+/* {{{ proto int substr_compare(string main_str, string str, int offset [, int length [, bool case_sensitivity]])
+   Binary safe optionally case insensitive comparison of 2 strings from an offset, up to length characters */
+PHP_FUNCTION(substr_compare)
+{
+       char *s1, *s2;
+       int s1_len, s2_len;
+       long offset, len=0;
+       zend_bool cs=0;
+       uint cmp_len;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|lb", &s1, &s1_len, &s2, &s2_len, &offset, &len, &cs) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       if (len && offset >= s1_len) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "The start position cannot exceed initial string length.");
+               RETURN_FALSE;
+       }
+
+       cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset)));
+
+       if (!cs) {
+               RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
+       } else {
+               RETURN_LONG(zend_binary_strncasecmp(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
+       }
+}
+/* }}} */
+
 /*
  * Local variables:
  * tab-width: 4