All pastes #24834 Raw Edit

man_in_shack

public text v1 · immutable
#24834 ·published 2005-10-07 11:42 UTC
rendered paste body
def stripcom(s,delim="#"):
        c=0
        state=None
        lits=["'",'"']
        while c<len(s)-len(delim)+1:
                if s[c] in lits and (c>0 and s[c-1]!="\\"):
                        if state==None:
                                state=lits.index(s[c])
                        else:
                                if s[c]==lits[state]:
                                        state=None
                if state==None and s[c:c+len(delim)]==delim:
                        return s[:c]
                c=c+1
        return s