feedback, comments on this php-delimiter scrubbing program?

Jeffrey Goldberg jeffrey at
Tue Jun 16 23:32:47 UTC 2009

On Jun 16, 2009, at 12:02 PM, Gary Kline wrote:

> 	this works, but still gives a warning.  it's sloppy coding, but
> 	as a second version...

You've got some superfluous tests for EOF in some places, and you may  
also be missing some.

Your approach has been to "look ahead" with an extra getc() when you  
come across an interesting character.  I recommended that instead of  
doing that you keep a variable "state" to keep track of where you are  
(and have very recently been) instead of looking ahead.

I haven't tried your code, but I suspect that it behaves incorrectly  
with input

   (1) that has a '<' as a final character
   (2) that includes things like "<<<<?"
   (3) that includes things like "??>"

There is a systematic (if a bit tedious) way to make sure that you  
check every condition.  When you've worked enough on this, you can  
peek at an answer which I've attached.

(For the rest of you, I know that it would be more efficient to make  
the big switch on state instead of on input character, but for  
pedagogical reasons I did it the other way around.  I deliberately  
avoided other available tunings).

The extensive comments in the code should make it clear what is going  
on.  Once you understand the concepts here it should be very easy to  
write code to do similar things in the future.


Jeffrey Goldberg              

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gkline.c
Type: application/octet-stream
Size: 3143 bytes
Desc: not available
Url :
-------------- next part --------------

More information about the freebsd-questions mailing list