in reply to logic for smart quotes - what does this code mean?

The first will convert a double quote character into two single quotes only if $$quote is true. From that it appears that $$quote is a flag to mark if an opening quote has been found but its partner has not. I'll go further to assume that $text is a chunk at a time, and this takes care of quotes that span chunks.