mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Add strncasecmp function
@ Added strncasecmp function (Andi)
This commit is contained in:
parent
9bb4011d06
commit
1373a16280
3 changed files with 45 additions and 0 deletions
|
@ -33,6 +33,7 @@ static ZEND_FUNCTION(strlen);
|
||||||
static ZEND_FUNCTION(strcmp);
|
static ZEND_FUNCTION(strcmp);
|
||||||
static ZEND_FUNCTION(strncmp);
|
static ZEND_FUNCTION(strncmp);
|
||||||
static ZEND_FUNCTION(strcasecmp);
|
static ZEND_FUNCTION(strcasecmp);
|
||||||
|
static ZEND_FUNCTION(strncasecmp);
|
||||||
static ZEND_FUNCTION(each);
|
static ZEND_FUNCTION(each);
|
||||||
static ZEND_FUNCTION(error_reporting);
|
static ZEND_FUNCTION(error_reporting);
|
||||||
static ZEND_FUNCTION(define);
|
static ZEND_FUNCTION(define);
|
||||||
|
@ -76,6 +77,7 @@ static zend_function_entry builtin_functions[] = {
|
||||||
ZEND_FE(strcmp, NULL)
|
ZEND_FE(strcmp, NULL)
|
||||||
ZEND_FE(strncmp, NULL)
|
ZEND_FE(strncmp, NULL)
|
||||||
ZEND_FE(strcasecmp, NULL)
|
ZEND_FE(strcasecmp, NULL)
|
||||||
|
ZEND_FE(strncasecmp, NULL)
|
||||||
ZEND_FE(each, first_arg_force_ref)
|
ZEND_FE(each, first_arg_force_ref)
|
||||||
ZEND_FE(error_reporting, NULL)
|
ZEND_FE(error_reporting, NULL)
|
||||||
ZEND_FE(define, NULL)
|
ZEND_FE(define, NULL)
|
||||||
|
@ -274,6 +276,22 @@ ZEND_FUNCTION(strcasecmp)
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
/* {{{ proto int strncasecmp(string str1, string str2, int len)
|
||||||
|
Binary safe string comparison */
|
||||||
|
ZEND_FUNCTION(strncasecmp)
|
||||||
|
{
|
||||||
|
zval **s1, **s2, **s3;
|
||||||
|
|
||||||
|
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &s1, &s2, &s3) == FAILURE) {
|
||||||
|
ZEND_WRONG_PARAM_COUNT();
|
||||||
|
}
|
||||||
|
convert_to_string_ex(s1);
|
||||||
|
convert_to_string_ex(s2);
|
||||||
|
convert_to_long_ex(s3);
|
||||||
|
RETURN_LONG(zend_binary_zval_strncasecmp(*s1,*s2,*s3));
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
ZEND_FUNCTION(each)
|
ZEND_FUNCTION(each)
|
||||||
{
|
{
|
||||||
zval **array,*entry,**entry_ptr, *tmp;
|
zval **array,*entry,**entry_ptr, *tmp;
|
||||||
|
|
|
@ -1473,6 +1473,25 @@ ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ZEND_API int zend_binary_strncasecmp(char *s1, uint len1, char *s2, uint len2, uint length)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
int c1,c2;
|
||||||
|
|
||||||
|
len = MIN(length, MIN(len1, len2));
|
||||||
|
|
||||||
|
while (len--) {
|
||||||
|
c1 = tolower(*s1++);
|
||||||
|
c2 = tolower(*s2++);
|
||||||
|
if (c1 != c2) {
|
||||||
|
return c1 - c2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return len1 - len2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2)
|
ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2)
|
||||||
{
|
{
|
||||||
return zend_binary_strcmp(s1->value.str.val, s1->value.str.len, s2->value.str.val, s2->value.str.len);
|
return zend_binary_strcmp(s1->value.str.val, s1->value.str.len, s2->value.str.val, s2->value.str.len);
|
||||||
|
@ -1490,6 +1509,12 @@ ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ZEND_API int zend_binary_zval_strncasecmp(zval *s1, zval *s2, zval *s3)
|
||||||
|
{
|
||||||
|
return zend_binary_strncasecmp(s1->value.str.val, s1->value.str.len, s2->value.str.val, s2->value.str.len, s3->value.lval);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2)
|
ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2)
|
||||||
{
|
{
|
||||||
int ret1,ret2;
|
int ret1,ret2;
|
||||||
|
|
|
@ -148,9 +148,11 @@ ZEND_API void zend_str_tolower(char *str, unsigned int length);
|
||||||
ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2);
|
ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2);
|
||||||
ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3);
|
ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3);
|
||||||
ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2);
|
ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2);
|
||||||
|
ZEND_API int zend_binary_zval_strncasecmp(zval *s1, zval *s2, zval *s3);
|
||||||
ZEND_API int zend_binary_strcmp(char *s1, uint len1, char *s2, uint len2);
|
ZEND_API int zend_binary_strcmp(char *s1, uint len1, char *s2, uint len2);
|
||||||
ZEND_API int zend_binary_strncmp(char *s1, uint len1, char *s2, uint len2, uint length);
|
ZEND_API int zend_binary_strncmp(char *s1, uint len1, char *s2, uint len2, uint length);
|
||||||
ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2);
|
ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2);
|
||||||
|
ZEND_API int zend_binary_strncasecmp(char *s1, uint len1, char *s2, uint len2, uint length);
|
||||||
|
|
||||||
ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2);
|
ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2);
|
||||||
ZEND_API void zend_compare_symbol_tables(zval *result, HashTable *ht1, HashTable *ht2);
|
ZEND_API void zend_compare_symbol_tables(zval *result, HashTable *ht1, HashTable *ht2);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue