Chromium Code Reviews| 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..175aea17700849eff1b48fea56000d4a780f183b 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,8 +93,11 @@ class Code(object): |
| Unaffected by code.Substitute(). |
| """ |
| - max_len = self._comment_length - self._indent_level - len(comment_prefix) |
| - while len(comment) >= max_len: |
| + # 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, '' |
| line = comment[0:max_len] |
|
Devlin
2015/03/26 22:36:54
Technically, this means treats the max length as 1
Dan Beam
2015/03/26 22:41:48
i think 80 is fine...?
Devlin
2015/03/26 23:13:08
Thought so, but figured good to double check.
|
| last_space = line.rfind(' ') |
| if last_space != -1: |
| @@ -102,8 +105,19 @@ class Code(object): |
| comment = comment[last_space + 1:] |
| else: |
| 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): |