how to remove c++ comments from a cpp file?

Gabriel Genellina gagsl-py at yahoo.com.ar
Fri Jan 26 13:56:17 EST 2007


"Peter Otten" <__peter__ at web.de> escribió en el mensaje 
news:epd751$518$03$1 at news.t-online.com...
> Laurent Rahuel wrote:
>
>> And using the codecs module
>
> Why would you de/encode at all?

I'd say the otherwise: why not? This is the recommended practice: decode 
inputs as soon as possible, work on Unicode, encode only when you write the 
output.
In this particular case, it's not necesary and you get the same results, 
only because these two conditions are met:

- the encoding used is utf-8
- we're looking for '//', and no unicode character contains '/' in its 
representation using that encoding apart from '/' itself

Looking for the byte sequence '//' into data encoded with a different 
encoding (like utf-16 or ucs-2) could give false positives. And looking for 
other things (like '¡¡') on utf-8 could give false positives too.
The same applies if one wants to skip string literals looking for '"' and 
'\\"'.
Anyway for a toy script like this, perhaps it does not make any sense at 
all - but one should be aware of the potential problems.

-- 
Gabriel Genellina 





More information about the Python-list mailing list