diff --git a/blame.py b/blame.py index 2f3556a..031dafd 100644 --- a/blame.py +++ b/blame.py @@ -48,13 +48,13 @@ class Blame: if self.blames.get(author, None) == None: self.blames[author] = BlameEntry() - if comment.is_comment_begining(FileDiff.get_extension(i), content): + if comment.has_comment_begining(FileDiff.get_extension(i), content): is_inside_comment = True if comment.is_comment(FileDiff.get_extension(i), content) or is_inside_comment: self.blames[author].comments += 1 - if comment.is_comment_end(FileDiff.get_extension(i), content): + if comment.has_comment_end(FileDiff.get_extension(i), content): is_inside_comment = False self.blames[author].rows += 1 diff --git a/comment.py b/comment.py index e81ff6f..009d3c1 100644 --- a/comment.py +++ b/comment.py @@ -26,20 +26,24 @@ __comment_end__ = {"java": "*/", "c": "*/", "cpp": "*/", "h": "*/", "hpp": "*/", __comment__ = {"java": "//", "c": "//", "cpp": "//", "h": "//", "hpp": "//", "py": "#", "glsl": "//", "rb": "#", "js": "//", "sql": "--"} -def is_comment_begining(extension, string): - if __comment_begining__.get(extension, None) != None: - return string.strip().startswith(__comment_begining__[extension]) - else: - return False - -def is_comment_end(extension, string): - if __comment_end__.get(extension, None) != None: - return string.strip().endswith(__comment_end__[extension]) - else: - return False - def is_comment(extension, string): - if __comment__.get(extension, None) != None: - return string.strip().startswith(__comment__[extension]) + if __comment_begining__.get(extension, None) != None and string.strip().startswith(__comment__[extension]): + return True + if __comment_end__.get(extension, None) != None and string.strip().endswith(__comment__[extension]): + return True + if __comment__.get(extension, None) != None and string.strip().startswith(__comment__[extension]): + return True + + return False + +def has_comment_begining(extension, string): + if __comment_begining__.get(extension, None) != None: + return string.find(__comment_begining__[extension]) != -1 + else: + return False + +def has_comment_end(extension, string): + if __comment_end__.get(extension, None) != None: + return string.find(__comment_end__[extension]) != -1 else: return False diff --git a/metrics.py b/metrics.py index 2cd6868..89b779b 100644 --- a/metrics.py +++ b/metrics.py @@ -46,13 +46,13 @@ class Metrics: eloc_counter = 0 for j in file_r.readlines(): - if comment.is_comment_begining(extension, j): + if comment.has_comment_begining(extension, j): is_inside_comment = True if not comment.is_comment(extension, j) and not is_inside_comment: eloc_counter += 1 - if comment.is_comment_end(extension, j): + if comment.has_comment_end(extension, j): is_inside_comment = False return eloc_counter