Lines Matching full:line
88 """Represents a position (line and column) in a text file."""
90 def __init__(self, line=-1, column=-1):
91 self.line = line
95 return self.line == rhs.line and self.column == rhs.column
101 return self.line < rhs.line or (
102 self.line == rhs.line and self.column < rhs.column)
117 return '%s(%s)' % (self.line + 1, self.column)
120 return Cursor(self.line, self.column + offset)
123 return Cursor(self.line, self.column - offset)
128 return Cursor(self.line, self.column)
166 return lines[pos.line][pos.column:].startswith(string)
169 def FindFirstInLine(line, token_table):
172 m = regex.search(line)
190 cur_line_number = cursor.line
191 for line in lines[start.line:]:
192 if cur_line_number == start.line:
193 line = line[start.column:]
194 m = FindFirstInLine(line, token_table)
196 # We found a regex in line.
198 if cur_line_number == start.line:
217 if start.line == end.line:
218 return lines[start.line][start.column:end.column]
220 result_lines = ([lines[start.line][start.column:]] +
221 lines[start.line + 1:end.line] +
222 [lines[end.line][:end.column]])
227 """Strip meta comments from each line in the given string."""
244 line = lines[pos.line][pos.column:]
245 m = regex.search(line)
262 line = lines[pos.line][pos.column:]
263 m = re.search(regex, line)
271 line = lines[pos.line][pos.column:]
272 m = re.search(regex, line)
276 print ('ERROR: %s expected on line %s after column %s.' %
277 (token_type, pos.line + 1, pos.column))
339 pos = Cursor(exp_token.end.line + 1, 0)
359 new_pos = Cursor(pos.line + 1, 0)
717 def WrapComment(line, output):
718 loc = line.find('//')
719 before_comment = line[:loc].rstrip()
727 comment = line[loc + 2:].strip()
741 def WrapCode(line, line_concat, output):
742 indent = len(line) - len(line.lstrip())
743 prefix = indent*' ' # Prefix of the current line
744 max_len = 80 - indent - len(line_concat) # Maximum length of the current line
745 new_prefix = prefix + 4*' ' # Prefix of a continuation line
746 new_max_len = max_len - 4 # Maximum length of a continuation line
747 # Prefers to wrap a line after a ',' or ';'.
748 segs = [seg for seg in re.split(r'([^,;]+[,;]?)', line.strip()) if seg != '']
749 cur_line = '' # The current line without leading spaces.
751 # If the line is still too long, wrap at a space.
771 def WrapPreprocessorDirective(line, output):
772 WrapCode(line, ' \\', output)
775 def WrapPlainCode(line, output):
776 WrapCode(line, '', output)
779 def IsMultiLineIWYUPragma(line):
780 return re.search(r'/\* IWYU pragma: ', line)
783 def IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
784 return (re.match(r'^#(ifndef|define|endif\s*//)\s*[\w_]+\s*$', line) or
785 re.match(r'^#include\s', line) or
787 re.search(r'// IWYU pragma: ', line))
790 def WrapLongLine(line, output):
791 line = line.rstrip()
792 if len(line) <= 80:
793 output.append(line)
794 elif IsSingleLineComment(line):
795 if IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
798 output.append(line)
800 WrapComment(line, output)
801 elif IsInPreprocessorDirective(output, line):
802 if IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
805 output.append(line)
807 WrapPreprocessorDirective(line, output)
808 elif IsMultiLineIWYUPragma(line):
809 output.append(line)
811 WrapPlainCode(line, output)
817 for line in lines:
818 WrapLongLine(line, output)
819 output2 = [line.rstrip() for line in output]