String Extension Proposal

From: Date: Fri, 01 Jul 2005 17:45:54 +0000
Subject: String Extension Proposal
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-2512@lists.php.net to get a copy of this message
Hello, I've started working on an extension which declares a String class for PHP. I already have several methods completed and will add more as I have time. The features of this String class are the following: Speed/Space Management ---------------------- Right now, when you perform an operation such as "$value = strtoupper($value)", a copy of the string is made, uppercased, and then returned. This copy is unnecessary, as the original string is going to be replaced. In this String class, all operations are done in the current buffer. Another example, a "trim" method call simply moves the non-whitespace characters to the beginning of the string and terminates (sets it to '\0') the string at the first whitespace chacter at the end of the string. If a copy of the string is truly needed, then the "makeCopy()" method is just for that. You can do "$myStr->trim()" to do in-line trimming or "$trimmedStr = $myStr->makeCopy()->trim()" to preserve the original value. The start size and prealloc sizes for string buffers will be configurable through INI options. A method "reserve()" exists to reserve a specific size for the string. If a string expects to have a lot of concatenations, reserve()'ing an appropriate size for the string will GREATLY increase performance and space utilization. Primitive String Compatibility ----------------------------- The following primitive string operations ALREADY work on the current class, compiled against PHP 5.0.4! <code> $myStr = new String( "Hello World!" ); // get single character echo $myStr{1}; // prints 'e' // interpolation! echo "The contents are: $myStr"; //prints "The contents are: Hello World!" // regular functions! echo strrev( $myStr ); // prints "!dlroW olleH" </code> If there are no objections, I would like to post my code to PECL. This extension only declares one class, "String", and is meant to only work in PHP 5 and above. Regards, Jessie Hernandez

« previous php.pecl.dev (#2512) next »