Skip to content

Commit c5cafe6

Browse files
committed
fix a bug in c multi comment in 0007
1 parent c52ac25 commit c5cafe6

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎burness/0007/1.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//123
2-
2+
/*
3+
123
4+
*/
35

46

57
132

‎burness/0007/Program_lines_stat.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
lan_postfix={'python':'.py','c':'.c'}
1313
lan_comment={'python':'#','c':'//'}
1414
# 解决多行注释 如python中的'''
15-
multi_comment={'python':'\'\'\'','c':'/*'}
15+
multi_comment_start={'python':'\'\'\'','c':'/*'}
16+
multi_comment_end={'python':'\'\'\'','c':'*/'}
1617

1718
def stat_lines(file_name,file_type):
1819
import re
@@ -24,10 +25,13 @@ def stat_lines(file_name,file_type):
2425
# pdb.set_trace()
2526
line_next=line.lstrip()
2627
# fuck a bug here in c multi comment
27-
if line_next.startswith(multi_comment[file_type]):
28-
is_comment= not is_comment
29-
if not is_comment:
30-
stat_result['comment']+=1
28+
if not is_comment and line_next.startswith(multi_comment_start[file_type]):
29+
is_comment= True
30+
stat_result['comment']+=1
31+
continue
32+
if line_next.startswith(multi_comment_end[file_type]):
33+
is_comment=False
34+
stat_result['comment']+=1
3135
# print(line)
3236
# print(line_next)
3337
if not line.split():

0 commit comments

Comments
 (0)