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.
Splitting words by spaces except when they are in "quot
Moderator: General Moderators
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
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:
Both algorithms performed almost the same for it... I wonder why...
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!
I found this input very interesting:
Code: Select all
bang th\\is \\"Fo \"o bar" \\\"B"ang Bling" foo "Boo" foo- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you can create your own ctype_space():
Code: Select all
if(!function_exists('ctype_space'))
{
function ctype_space($input)
{
return (strlen(trim($input)) == 0);
}
}- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
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.
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.