Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5654 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5442 invoked by uid 1010); 21 Nov 2003 22:14:01 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 5418 invoked from network); 21 Nov 2003 22:14:01 -0000 Received: from unknown (HELO mail-1.nethere.net) (66.63.128.70) by pb1.pair.com with SMTP; 21 Nov 2003 22:14:01 -0000 Received: (qmail 20242 invoked from network); 21 Nov 2003 22:13:59 -0000 Received: from ppp-207-167-100-199.sndg-pm4-2.dialup.nethere.net (localhost.localdomain [207.167.100.199]) by mail-1.nethere.net with SMTP; 21 Nov 2003 22:13:59 -0000 (envelope-sender ) Organization: The Coeus Group To: "Sara Golemon" , internals@lists.php.net Date: Fri, 21 Nov 2003 14:10:07 -0800 User-Agent: KMail/1.4.3 References: <200311210525.59473.evan@coeus-group.com> <004f01c3b074$c86d5850$0a00000a@alphaweb.net> In-Reply-To: <004f01c3b074$c86d5850$0a00000a@alphaweb.net> X-I-See: Faces X-Presso: Yes X-DeCSS-Usage: cat title-key scrambled.vob | decss > clear.vob X-DeCSS-Line-1: #define m(i)(x[i]^s[i+84])<< X-DeCSS-Line-2: unsigned char x[5],y,s[2048];main(n){for(read(0,x,5);read(0,s,n=2048);write(1,s,n))if(s[y=s[13]%8+20]/16%4==1){int i=m(1)17^256+m(0)8,k=m(2)0,j=m(4)17^m(3)9^k*2-k%8^8,a=0,c=26;for(s[y]-=16;--c;j*=2)a=a*2^i&1,i=i/2^j&1<<24;for(j=127;++jy)c+=y=i^i/8^i>>4^i>>12,i=i>>8^y<<17,a^=a>>14,y=a^a*8^a<<6,a=a>>8^y<<9,k=s[j],k="7Wo~'G_\216"[k&7]+2^"cr3sfw6v;*k+>/n."[k>>4]*2^k*257/8,s[j]=k^(k&k*2&34)*6^c+~y;}} MIME-Version: 1.0 Message-ID: <200311211408.03470.evan@coeus-group.com> Content-Type: Multipart/Mixed; boundary="------------Boundary-00=_VW2QKJOKCJDXG0I3P9SL" Subject: Re: [PATCH] proposal for new function (str_type) From: evan@coeus-group.com (Evan Nemerson) --------------Boundary-00=_VW2QKJOKCJDXG0I3P9SL Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit On Friday 21 November 2003 01:16 pm, you wrote: > > I've attached a patch which adds a function that basically wraps the > > ctype.h > > > functions. It pretty much just lets you check to see if a string contains > > only a certain set of characters. I think it would be very nice for input > > validation, particularly for those who fear regular expressions. Here's > > the > > > prototype: > > A couple things: > > #1 Have you looked at the ctype extension? > http://us4.php.net/manual/en/ref.ctype.php Yeah, but I like being able to use them all at once. > > #2 If a unified function is to be added (not against it per se) it should > probably be named ctype() (as the "top-level" of the ctype extension and be > placed in ext/ctype rather than in ext/standard/strings.[ch] Agreed. Here's a new patch that does that, and renames the calls the constants CTYPE_* > > -Sara -- Evan Nemerson evan@coeus-group.com --------------Boundary-00=_VW2QKJOKCJDXG0I3P9SL Content-Type: text/x-diff; charset="iso-8859-1"; name="php_str_type.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="php_str_type.diff" Index: ext/ctype/ctype.c =================================================================== RCS file: /repository/php-src/ext/ctype/ctype.c,v retrieving revision 1.28 diff -u -r1.28 ctype.c --- ext/ctype/ctype.c 3 Oct 2003 15:50:01 -0000 1.28 +++ ext/ctype/ctype.c 21 Nov 2003 22:10:36 -0000 @@ -55,17 +55,49 @@ PHP_FE(ctype_space, NULL) PHP_FE(ctype_upper, NULL) PHP_FE(ctype_xdigit, NULL) + PHP_FE(ctype, NULL) {NULL, NULL, NULL} /* Must be the last line in ctype_functions[] */ }; /* }}} */ +#define CTYPE_ALNUM 0x01 +#define CTYPE_ALPHA 0x02 +#define CTYPE_CNTRL 0x04 +#define CTYPE_DIGIT 0x08 +#define CTYPE_GRAPH 0x10 +#define CTYPE_LOWER 0x20 +#define CTYPE_PRINT 0x40 +#define CTYPE_PUNCT 0x80 +#define CTYPE_SPACE 0x100 +#define CTYPE_UPPER 0x200 +#define CTYPE_XDIGIT 0x400 + +/* {{{ PHP_MINIT_FUNCTION + */ +PHP_MINIT_FUNCTION(ctype) +{ + REGISTER_LONG_CONSTANT("CTYPE_ALNUM", CTYPE_ALNUM, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CTYPE_ALPHA", CTYPE_ALPHA, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CTYPE_CNTRL", CTYPE_CNTRL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CTYPE_DIGIT", CTYPE_DIGIT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CTYPE_GRAPH", CTYPE_GRAPH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CTYPE_LOWER", CTYPE_LOWER, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CTYPE_PRINT", CTYPE_PRINT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CTYPE_PUNCT", CTYPE_PUNCT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CTYPE_SPACE", CTYPE_SPACE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CTYPE_UPPER", CTYPE_UPPER, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("CTYPE_XDIGIT", CTYPE_XDIGIT, CONST_CS | CONST_PERSISTENT); + return SUCCESS; +} +/* }}} */ + /* {{{ ctype_module_entry */ zend_module_entry ctype_module_entry = { STANDARD_MODULE_HEADER, "ctype", ctype_functions, - NULL, + PHP_MINIT(ctype), NULL, NULL, NULL, @@ -204,6 +236,50 @@ } /* }}} */ +/* {{{ proto bool ctype(string str, int type) + Find out if a string is composed entirely of the specified type(s) of characters. */ +PHP_FUNCTION(ctype) +{ + char *str; + int str_l, types, count, res; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &str, &str_l, &types) == FAILURE) { + RETURN_FALSE; + } + + for ( count=0 ; count