Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:2338 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14625 invoked from network); 14 Jun 2003 23:17:46 -0000 Received: from unknown (HELO joeysmith.com) (209.197.17.2) by pb1.pair.com with SMTP; 14 Jun 2003 23:17:46 -0000 Received: from joeysmith.com (joey@localhost [127.0.0.1]) by joeysmith.com (8.12.8/8.12.8/Debian-2) with ESMTP id h5ENHnmd032042 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=FAIL) for ; Sat, 14 Jun 2003 17:17:49 -0600 Received: (from joey@localhost) by joeysmith.com (8.12.8/8.12.8/Debian-2) id h5ENHnJK032041 for internals@lists.php.net; Sat, 14 Jun 2003 17:17:49 -0600 Date: Sat, 14 Jun 2003 17:17:49 -0600 To: internals@lists.php.net Message-ID: <20030614231746.GA32026@joeysmith.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ikeVEW9yuYc//A+q" Content-Disposition: inline User-Agent: Mutt/1.5.4i Subject: sixth mode for count_chars From: joey@joeysmith.com (Joey Smith) --ikeVEW9yuYc//A+q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The two attached files add a sixth mode to count chars, one that comes up now and again. This is the same as mode 1, but the resulting array has the actual char as the array index instead of the byte-value. This can be used in place of preg_split('//', $string) and such. I've also prepared patches for the documentation and for 4.3.2 to go along with this. You can also find the patches online: http://www.joeysmith.com/CVS_HEAD.patch http://www.joeysmith.com/PHP_4_3_2.patch http://www.joeysmith.com/phpdoc.patch --ikeVEW9yuYc//A+q Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="CVS_HEAD.patch" ? CVS_HEAD.patch Index: ext/standard/string.c =================================================================== RCS file: /repository/php4/ext/standard/string.c,v retrieving revision 1.390 diff -u -r1.390 string.c --- ext/standard/string.c 11 Jun 2003 02:16:19 -0000 1.390 +++ ext/standard/string.c 14 Jun 2003 21:44:19 -0000 @@ -4053,6 +4053,7 @@ int len, inx; char retstr[256]; int retlen=0; + char temp[2]; if (ac < 1 || ac > 2 || zend_get_parameters_ex(ac, &input, &mode) == FAILURE) { WRONG_PARAM_COUNT; @@ -4064,7 +4065,7 @@ convert_to_long_ex(mode); mymode = Z_LVAL_PP(mode); - if (mymode < 0 || mymode > 4) { + if (mymode < 0 || mymode > 5) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown mode."); RETURN_FALSE; } @@ -4080,7 +4081,7 @@ len--; } - if (mymode < 3) { + if ((mymode < 3) || (mymode == 5)) { array_init(return_value); } @@ -4107,6 +4108,13 @@ case 4: if (chars[inx] == 0) { retstr[retlen++] = inx; + } + break; + case 5: + if (chars[inx] > 0) { + temp[0] = inx; + temp[1] = 0; + add_assoc_long_ex(return_value, temp, sizeof(temp), chars[inx]); } break; } --ikeVEW9yuYc//A+q--