Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Unified Diff: tools/json_schema_compiler/code.py

Issue 1010603007: [Extension API Extern Generation] Fix comment indentation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: True 80 char limit Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/json_schema_compiler/code_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/code.py
diff --git a/tools/json_schema_compiler/code.py b/tools/json_schema_compiler/code.py
index 8ce6afab675e61620199e2328cdfe7338b9b1236..10a5d884ad737340115bf64cac6875fe6941f077 100644
--- a/tools/json_schema_compiler/code.py
+++ b/tools/json_schema_compiler/code.py
@@ -85,7 +85,7 @@ class Code(object):
self.Append(line)
return self
- def Comment(self, comment, comment_prefix='// '):
+ def Comment(self, comment, comment_prefix='// ', wrap_indent=0):
"""Adds the given string as a comment.
Will split the comment if it's too long. Use mainly for variable length
@@ -93,17 +93,31 @@ class Code(object):
Unaffected by code.Substitute().
"""
- max_len = self._comment_length - self._indent_level - len(comment_prefix)
- while len(comment) >= max_len:
- line = comment[0:max_len]
- last_space = line.rfind(' ')
+ # Helper function to trim a comment to the maximum length, and return one
+ # line and the remainder of the comment.
+ def trim_comment(comment, max_len):
+ if len(comment) <= max_len:
+ return comment, ''
+ last_space = comment.rfind(' ', 0, max_len + 1)
if last_space != -1:
- line = line[0:last_space]
+ line = comment[0:last_space]
comment = comment[last_space + 1:]
else:
+ line = comment[0:max_len]
comment = comment[max_len:]
- self.Append(comment_prefix + line, substitute=False)
- self.Append(comment_prefix + comment, substitute=False)
+ return line, comment
+
+ # First line has the full maximum length.
+ max_len = self._comment_length - self._indent_level - len(comment_prefix)
+ line, comment = trim_comment(comment, max_len)
+ self.Append(comment_prefix + line, substitute=False)
+
+ # Any subsequent lines be subject to the wrap indent.
+ max_len = max_len - wrap_indent
+ while len(comment):
+ line, comment = trim_comment(comment, max_len)
+ self.Append(comment_prefix + (' ' * wrap_indent) + line, substitute=False)
+
return self
def Substitute(self, d):
« no previous file with comments | « no previous file | tools/json_schema_compiler/code_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698