cvs: /php4/ext/standard basic_functions.c php_string.h string.c

From: Date: Tue, 14 Dec 1999 03:52:43 +0000
Subject: cvs: /php4/ext/standard basic_functions.c php_string.h string.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-7895@lists.php.net to get a copy of this message
thies Mon Dec 13 22:52:43 1999 EDT Modified files: /php4/ext/standard basic_functions.c php_string.h string.c Log: @- implemented count_chars(). (Thies) Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.134 php4/ext/standard/basic_functions.c:1.135 --- php4/ext/standard/basic_functions.c:1.134 Mon Dec 13 13:31:28 1999 +++ php4/ext/standard/basic_functions.c Mon Dec 13 22:52:12 1999 @@ -152,6 +152,7 @@ PHP_FE(chop, NULL) PHP_FE(str_replace, NULL) PHP_FE(str_repeat, NULL) + PHP_FE(count_chars, NULL) PHP_FE(chunk_split, NULL) PHP_FE(trim, NULL) PHP_FE(ltrim, NULL) Index: php4/ext/standard/php_string.h diff -u php4/ext/standard/php_string.h:1.4 php4/ext/standard/php_string.h:1.5 --- php4/ext/standard/php_string.h:1.4 Mon Dec 13 18:40:36 1999 +++ php4/ext/standard/php_string.h Mon Dec 13 22:52:12 1999 @@ -29,7 +29,7 @@ */ -/* $Id: php_string.h,v 1.4 1999/12/13 23:40:36 andrei Exp $ */ +/* $Id: php_string.h,v 1.5 1999/12/14 03:52:12 thies Exp $ */ /* Synced with php3 revision 1.43 1999-06-16 [ssb] */ @@ -46,6 +46,7 @@ PHP_FUNCTION(ltrim); PHP_FUNCTION(soundex); +PHP_FUNCTION(count_chars); PHP_FUNCTION(explode); PHP_FUNCTION(implode); PHP_FUNCTION(strtok); Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.73 php4/ext/standard/string.c:1.74 --- php4/ext/standard/string.c:1.73 Mon Dec 13 22:25:04 1999 +++ php4/ext/standard/string.c Mon Dec 13 22:52:12 1999 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.73 1999/12/14 03:25:04 andrei Exp $ */ +/* $Id: string.c,v 1.74 1999/12/14 03:52:12 thies Exp $ */ /* Synced with php3 revision 1.193 1999-06-16 [ssb] */ @@ -2352,9 +2352,79 @@ } /* }}} */ -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ +/* {{{ proto mixed count_chars(string input[, int mode]) + Returns info about what characters are used in input */ +PHP_FUNCTION(count_chars) +{ + zval **input, **mode; + int chars[256]; + int ac=ARG_COUNT(ht); + int mymode=0; + unsigned char *buf; + int len, inx; + char retstr[256]; + int retlen=0; + + if (ac < 1 || ac > 2 || getParametersEx(ac, &input, &mode) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_string_ex(input); + + if (ac == 2) { + convert_to_long_ex(mode); + mymode = (*mode)->value.lval; + + if (mymode < 0 || mymode > 4) { + php_error(E_WARNING, "unknown mode"); + RETURN_FALSE; + } + } + + len = (*input)->value.str.len; + buf = (unsigned char *) (*input)->value.str.val; + memset((void*) chars,0,sizeof(chars)); + + while (len > 0) { + chars[*buf]++; + buf++; + len--; + } + + if (mymode < 3) { + array_init(return_value); + } + + for (inx=0; inx < 255; inx++) { + switch (mymode) { + case 0: + add_index_long(return_value,inx,chars[inx]); + break; + case 1: + if (chars[inx] != 0) { + add_index_long(return_value,inx,chars[inx]); + } + break; + case 2: + if (chars[inx] == 0) { + add_index_long(return_value,inx,chars[inx]); + } + break; + case 3: + if (chars[inx] != 0) { + retstr[retlen++] = inx; + } + break; + case 4: + if (chars[inx] == 0) { + retstr[retlen++] = inx; + } + break; + } + } + + if (mymode >= 3 && mymode <= 4) { + RETURN_STRINGL(retstr,retlen,1); + } +} +/* }}} */

« previous php.version4 (#7895) next »