コード例 #1
0
ファイル: profile.py プロジェクト: bradfordelliott/shorte
    def format_comment(self, comment, strip_single_line_comments=True):

        #print "COMMENT_BEFORE\n[%s]" % comment

        comment = re.sub("/\*\*\<", "", comment)
        comment = re.sub("/\*", "", comment)
        comment = re.sub("\*/", "", comment)
        comment = re.sub("^\s*\*", "", comment, re.MULTILINE)

        #expr = re.compile("^\s*\*", re.MULTILINE)
        #comment = expr.sub("", comment)
        
        if(strip_single_line_comments):
            #comment = re.sub(" +", " ", comment)
            comment = re.sub("//", "", comment)
        
        #print "COMMENT_1\n[%s]" % comment
        comment = trim_leading_blank_lines(comment)
        #print "COMMENT_2\n[%s]" % comment
        comment = trim_leading_indent(comment)
        #print "COMMENT_3\n[%s]" % comment

        return comment
コード例 #2
0
ファイル: profile.py プロジェクト: bradfordelliott/shorte
    def format_comment1(self, comment, strip_single_line_comments=True):

        #print "COMMENT_BEFORE\n[%s]" % comment
        chars = list(comment)
        output = ''
        i = 0
        length = len(chars)
        while i < length:
            if(chars[i] == '\r'):
                i += 1
                continue

            if(chars[i] == '\n'):
                output += chars[i]
                i += 1

                # Search forward and see if the next
                # line starts with an asterisk that needs to
                # be stripped
                j = i
                while(j < length and (chars[j] == ' ')):
                    j += 1

                if(j < length and chars[j] == '*'):
                    if(j + 1 < length and chars[j+1] != '/'):
                        i = j + 1
                        continue

            elif(chars[i] == '/'):
                if(chars[i+1] == '*'):
                    i += 1
                    while(chars[i] == '*'):
                        i += 1
                else:
                    output += chars[i]
                    i += 1

            elif(chars[i] == '*'):
                if(chars[i+1] == '/'):
                    i += 2

                else:
                    output += chars[i]
                    i += 1

            else:
                output += chars[i]
                i += 1

        comment = output

        #comment = re.sub("/\*\*\<", "", comment)
        #comment = re.sub("/\*", "", comment)
        #comment = re.sub("\*/", "", comment)
        #comment = re.sub("^\s*\*", "", comment, re.MULTILINE)

        #expr = re.compile("^\s*\*", re.MULTILINE)
        #comment = expr.sub("", comment)
        #
        #if(strip_single_line_comments):
        #    #comment = re.sub(" +", " ", comment)
        #    comment = re.sub("//", "", comment)
        
        #print "COMMENT_1\n[%s]" % comment
        comment = trim_leading_blank_lines(comment)
        #print "COMMENT_2\n[%s]" % comment
        comment = trim_leading_indent(comment)
        #print "COMMENT_3\n[%s]" % comment

        return comment