Page 2 of 3
Posted: Fri Aug 12, 2005 4:01 pm
by feyd
I've updated my previous post, not wanting to flood the page.
I made a couple of improvements in my code and added some profiling stuff. As the numbers show, Ambush's solution is faster every time, albeit wordier, but less confusing to most people here.

Posted: Fri Aug 12, 2005 4:34 pm
by Ambush Commander
It just got even wordier. Added comments. This sort of thing is meant to be edited.
Mine is faster. Heh. That's really cool.
::Scratch::
Now you've committed blasphemy there, Ambush Commander, for thinking you could be better than master Feyd. Now... feel his wrath!

Really, I guess, it's a matter of the old belief that regular expressions are expensive.
I found this input very interesting:
Code: Select all
bang th\\is \\"Fo \"o bar" \\\"B"ang Bling" foo "Boo" foo
Both algorithms performed almost the same for it... I wonder why...
Posted: Mon Aug 15, 2005 3:45 am
by Grim...
Dudes, you rock

Posted: Mon Aug 15, 2005 4:16 am
by Grim...
I've gone for the Ambush Commander's solution, mainly because Feyd's uses ctype_space, a function that my version of PHP doesn't support.
Thanks, guys!
Posted: Mon Aug 15, 2005 6:36 am
by feyd
you can create your own ctype_space():
Code: Select all
if(!function_exists('ctype_space'))
{
function ctype_space($input)
{
return (strlen(trim($input)) == 0);
}
}
Posted: Wed Aug 17, 2005 8:23 am
by Grim...
That's good, because Ambush Commanders kept timing out on the array merge line

Posted: Wed Aug 17, 2005 8:25 am
by Ambush Commander
Hmmm... how big are your strings?
Posted: Wed Aug 17, 2005 8:32 am
by Grim...
3 words, in this case
Any way it can be done without array_merge ?
Posted: Wed Aug 17, 2005 8:37 am
by Ambush Commander
Nope. Although I bet it's a bug in the code. Can you post the string?
Posted: Wed Aug 17, 2005 8:39 am
by Grim...
"crap car" yuck
Posted: Wed Aug 17, 2005 8:41 am
by Grim...
I don't think it is a bug in the code, my PHP has been behaving very oddly lately...
Posted: Wed Aug 17, 2005 8:45 am
by Ambush Commander
No, it's a bug. I see it. Unitialized string offset. Working on a fix.
Posted: Wed Aug 17, 2005 8:48 am
by Grim...
How come it worked for Feyd?
/confused
Posted: Wed Aug 17, 2005 8:50 am
by Ambush Commander
Updated first post with new code.
The problem with the code was it couldn't handle quotes that were at position 0. It would try to find a backslash that was before it (at position -1), which, of course, is unacceptable. With E_ALL on, you see the -1 offset and it's been fixed by adding in an extra conditional and then having the other sections make sure their section isn't empty.
It worked for Feyd because he didn't test any strings that started with a quote.

Posted: Wed Aug 17, 2005 8:52 am
by feyd
I don't test much of anything in my solution, no need!
