Tweaked webrtc_reformat.
Fixed variable names such as maskByte and stuff within brackets. Fixed bug where we would think that for instance foo_internal.h was the self include when the right answer was foo.h. Removed comment conversion: it was doing more damage than good. BUG= R=mflodman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/1442005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3983 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
315d39866e
commit
aeb7d8757d
@ -30,8 +30,19 @@ def LowerWord(obj):
|
||||
|
||||
|
||||
def DeCamelCase(text):
|
||||
"""De-camelize variable names."""
|
||||
pattern = re.compile(r'(?<=[ _*\(\&\!])([a-z]+)(?<!k)([A-Z]+)([a-z])?')
|
||||
"""De-camelize variable names.
|
||||
|
||||
This function will look at any stringLikeThis and format it in steps. The
|
||||
sequence will be stringLikeThis -> string_likeThis -> string_like_this.
|
||||
"""
|
||||
possible_tokens_before_vars = '[ _*\(\&\!\[]'
|
||||
pattern = re.compile(r'(?<=' + possible_tokens_before_vars + ')' +
|
||||
# Match some lower-case characters
|
||||
'([a-z]+)' +
|
||||
# Don't match kFoo, !kFoo, [kFoo], etc
|
||||
'(?<!' + possible_tokens_before_vars + 'k)' +
|
||||
# Match some upper-case characters
|
||||
'([A-Z]+)([a-z])?')
|
||||
while re.search(pattern, text):
|
||||
text = re.sub(pattern, LowerWord, text)
|
||||
return text
|
||||
@ -52,34 +63,6 @@ def PostfixToPrefixInForLoops(text):
|
||||
return re.sub(pattern, r'\1++\2)', text)
|
||||
|
||||
|
||||
def CPPComments(text):
|
||||
"""Remove all C-comments and replace with C++ comments."""
|
||||
|
||||
# Keep the copyright header style.
|
||||
line_list = text.splitlines(True)
|
||||
copyright_list = line_list[0:10]
|
||||
code_list = line_list[10:]
|
||||
copy_text = ''.join(copyright_list)
|
||||
code_text = ''.join(code_list)
|
||||
|
||||
# Remove */ for C-comments, don't care about trailing blanks.
|
||||
comment_end = re.compile(r'\n[ ]*\*/[ ]*')
|
||||
code_text = re.sub(comment_end, '', code_text)
|
||||
comment_end = re.compile(r'\*/')
|
||||
code_text = re.sub(comment_end, '', code_text)
|
||||
# Remove comment lines in the middle of comments, replace with C++ comments.
|
||||
comment_star = re.compile(r'(?<=\n)[ ]*(?!\*\w)\*[ ]*')
|
||||
code_text = re.sub(comment_star, r'// ', code_text)
|
||||
# Remove start of C comment and replace with C++ comment.
|
||||
comment_start = re.compile(r'/\*[ ]*\n')
|
||||
code_text = re.sub(comment_start, '', code_text)
|
||||
comment_start = re.compile(r'/\*[ ]*(.)')
|
||||
code_text = re.sub(comment_start, r'// \1', code_text)
|
||||
|
||||
# Add copyright info.
|
||||
return copy_text + code_text
|
||||
|
||||
|
||||
def SortIncludeHeaders(text, filename):
|
||||
"""Sorts all include headers in alphabetic order.
|
||||
|
||||
@ -106,7 +89,7 @@ def SortIncludeHeaders(text, filename):
|
||||
h_filename, _ = os.path.splitext(os.path.basename(filename))
|
||||
|
||||
for item in includes:
|
||||
if re.search(h_filename, item):
|
||||
if re.search(h_filename + '\.', item):
|
||||
self_include = item
|
||||
elif re.search(sys_pattern, item):
|
||||
sys_includes.append(item)
|
||||
@ -208,7 +191,6 @@ def main():
|
||||
text = DeCamelCase(text)
|
||||
text = MoveUnderScore(text)
|
||||
text = PostfixToPrefixInForLoops(text)
|
||||
text = CPPComments(text)
|
||||
text = AddHeaderPath(text)
|
||||
text = AddWebrtcPrefixToOldSrcRelativePaths(text)
|
||||
text = SortIncludeHeaders(text, filename)
|
||||
|
Loading…
Reference in New Issue
Block a user