Re: [PHP-DEV] Feature Request #5919 case-insensitive version ofstr_replace()

2003-01-29 Thread Derick Rethans
On Wed, 29 Jan 2003, Sara Golemon wrote:

  I've got an implementation put together, the patch for which can be
  viewed at:
 
  http://169.229.139.97/test/str_ireplace.diff.txt
 
 After some comments on IRC, here's an alternate version to the above
 patch.  This second approach avoids creating php_memnstri by simply
 searching through a copy of haystack which is strtolowered against a
 strtolowered version of needle (no need to copy that part).
 
 http://169.229.139.97/test/str_ireplace.diff-2.txt
 
 Should be quicker and cleaner at the cost of a small malloc in the
 estrndup call.

I still don;t see no real use for this function, you can easily do this 
with eregi_replace() or preg_replace().

Derick

-- 

-
 Derick Rethans http://derickrethans.nl/ 
 PHP Magazine - PHP Magazine for Professionals   http://php-mag.net/
-


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Feature Request #5919 case-insensitive version ofstr_replace()

2003-01-29 Thread Sascha Schumann
I suggest to check out

http://citeseer.nj.nec.com/navarro01fast.html

The presented BNDM algorithm is one of the fastest string
searching algorithm while being easy to implement.  Its main
loop is faster than the naive str_replace implementation(*).

Check out a C test implementation:

http://www.mail-archive.com/dev@httpd.apache.org/msg00939.html

The above paper also discusses extending the algorithm to
cover character classes (case insensitivity).

(*) I had incorporated it into PHP, if I had found a way to
nicely offset the compilation step.  This proved to be the
major obstacle for small sets.

- Sascha


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Feature Request #5919 case-insensitive version ofstr_replace()

2003-01-29 Thread Sascha Schumann
 On a related topic, the 'boyer' option of str_replace isn't even
 documented.  That alternate method of performing str_replaces look like
 it's a bit more efficient (no benchmarkes atm) but I'm wondering if
 there's a specific reasons why it wasn't documented yet.

The BM algorithm is outdated and can savely be dropped.

- Sascha


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Feature Request #5919 case-insensitive version ofstr_replace()

2003-01-29 Thread Dan Kalowsky
I'd tip my hat towards implementing it.  Pollita has a good point on
consistency and for those who don't know regex's.

On Wed, 29 Jan 2003, Sara Golemon wrote:

  I may be wrong since I haven't profiled this, but my understanding is
  that str_replace is much faster than doing either of the regex
  replacements.  For that reason alone, there is a use for it.
 
  Normally it would be quite faster, however once case sensitivity is
  added to  the mix I believe the speed difference would be minimal.
 
 I don't even see the speed difference as an issue as much as (A)
 simplicity for the user who hasn't figured out regex yet, (B) consistency
 (we have 'i' versions of most other string functions, why not this one?)

 The parameter accepting still needs to be fixed though, I copied most of
 the str_ireplace code from str_replace and forgot to clean that section up
 and make it nicer.  I'll save that for *if* a quorum can be reached to
 include it at all.

 On a related topic, the 'boyer' option of str_replace isn't even
 documented.  That alternate method of performing str_replaces look like
 it's a bit more efficient (no benchmarkes atm) but I'm wondering if
 there's a specific reasons why it wasn't documented yet.

 -Pollita






---
Dan KalowskyI'll walk a thousand miles just
http://www.deadmime.org/~dankto slip this skin.
[EMAIL PROTECTED]- Streets of Philadelphia,
[EMAIL PROTECTED]Bruce Springsteen

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Feature Request #5919 case-insensitive version ofstr_replace()

2003-01-29 Thread Sascha Schumann
 One last optimization to save memcpys when needle_len == str_len (thanks
 again ilia):

 Actual Patch:
 http://169.229.139.97/test/str_ireplace.diff-5.txt

 Resultant string.c for easy reading:
 http://169.229.139.97/test/string-5.c

 I've heard enough Ayes over Nays (here, in bugs.php.net, and in IRC) to
 say this should go in.

Well, actually, I would prefer to see a proper BNDM
implementation in the tree.

- character classes are handled for free
  (i.e. a case insensitive search does not take longer)

- combining shift-and and automata is much faster than our
  current naive algorithm (I may say so, I wrote it years ago)

- allows us to combine multiple patterns into one search (I
  have not studied that part of the paper yet). This would
  enable us to optimize the case where you pass arrays to
  str_replace.  Instead of scanning the haystack one time
  per replacement text, we would scan it only once.

- Sascha

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, visit: http://www.php.net/unsub.php