| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 class Code(object): | 5 class Code(object): |
| 6 """A convenience object for constructing code. | 6 """A convenience object for constructing code. |
| 7 | 7 |
| 8 Logically each object should be a block of code. All methods except |Render| | 8 Logically each object should be a block of code. All methods except |Render| |
| 9 and |IsEmpty| return self. | 9 and |IsEmpty| return self. |
| 10 """ | 10 """ |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 if last_space != -1: | 125 if last_space != -1: |
| 126 line = comment[0:last_space] | 126 line = comment[0:last_space] |
| 127 comment = comment[last_space + 1:] | 127 comment = comment[last_space + 1:] |
| 128 else: | 128 else: |
| 129 line = comment[0:max_len] | 129 line = comment[0:max_len] |
| 130 comment = comment[max_len:] | 130 comment = comment[max_len:] |
| 131 return line, comment | 131 return line, comment |
| 132 | 132 |
| 133 # First line has the full maximum length. | 133 # First line has the full maximum length. |
| 134 if not new_line and self._code: | 134 if not new_line and self._code: |
| 135 max_len = self._comment_length - len(self._code[-1].value) - 1 | 135 max_len = self._comment_length - len(self._code[-1].value) |
| 136 else: | 136 else: |
| 137 max_len = (self._comment_length - len(''.join(self._line_prefixes)) - | 137 max_len = (self._comment_length - len(''.join(self._line_prefixes)) - |
| 138 len(comment_prefix)) | 138 len(comment_prefix)) |
| 139 line, comment = trim_comment(comment, max_len) | 139 line, comment = trim_comment(comment, max_len) |
| 140 self.Append(comment_prefix + line, substitute=False, new_line=new_line) | 140 self.Append(comment_prefix + line, substitute=False, new_line=new_line) |
| 141 | 141 |
| 142 # Any subsequent lines be subject to the wrap indent. | 142 # Any subsequent lines be subject to the wrap indent. |
| 143 max_len = (self._comment_length - len(''.join(self._line_prefixes)) - | 143 max_len = (self._comment_length - len(''.join(self._line_prefixes)) - |
| 144 len(comment_prefix) - wrap_indent) | 144 len(comment_prefix) - wrap_indent) |
| 145 while len(comment): | 145 while len(comment): |
| (...skipping 29 matching lines...) Expand all Loading... |
| 175 """ | 175 """ |
| 176 return '\n'.join([l.value for l in self._code]) | 176 return '\n'.join([l.value for l in self._code]) |
| 177 | 177 |
| 178 | 178 |
| 179 class Line(object): | 179 class Line(object): |
| 180 """A line of code. | 180 """A line of code. |
| 181 """ | 181 """ |
| 182 def __init__(self, value, substitute=True): | 182 def __init__(self, value, substitute=True): |
| 183 self.value = value | 183 self.value = value |
| 184 self.substitute = substitute | 184 self.substitute = substitute |
| OLD | NEW |